launchdarkly-js-sdk-common 3.5.1 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/ldclient-common.cjs.js +1 -1
- package/dist/ldclient-common.cjs.js.map +1 -1
- package/dist/ldclient-common.es.js +1 -1
- package/dist/ldclient-common.es.js.map +1 -1
- package/dist/ldclient-common.min.js +1 -1
- package/dist/ldclient-common.min.js.map +1 -1
- package/package.json +1 -1
- package/typings.d.ts +39 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to the `launchdarkly-js-sdk-common` package will be documented in this file. Changes that affect the dependent SDKs such as `launchdarkly-js-client-sdk` should also be logged in those projects, in the next release that uses the updated version of this package. This project adheres to [Semantic Versioning](http://semver.org).
|
|
4
4
|
|
|
5
|
+
## [3.7.0] - 2022-10-03
|
|
6
|
+
### Removed:
|
|
7
|
+
- Removed `seenRequests` cache. This cache was used to de-duplicate events, but it has been supplanted with summary events.
|
|
8
|
+
|
|
9
|
+
### Deprecated:
|
|
10
|
+
- The `allowFrequentDuplicateEvents` configuration has been deprecated because it controlled the behavior of the `seenRequests` cache.
|
|
11
|
+
|
|
12
|
+
## [3.6.0] - 2022-04-21
|
|
13
|
+
### Added:
|
|
14
|
+
- `LDOptionsBase.application`, for configuration of application metadata that may be used in LaunchDarkly analytics or other product features. This does not affect feature flag evaluations.
|
|
15
|
+
|
|
16
|
+
### Fixed:
|
|
17
|
+
- The `baseUrl`, `streamUrl`, and `eventsUrl` properties now work properly regardless of whether the URL string has a trailing slash. Previously, a trailing slash would cause request URL paths to have double slashes.
|
|
18
|
+
|
|
5
19
|
## [3.5.1] - 2022-02-17
|
|
6
20
|
### Fixed:
|
|
7
21
|
- If the SDK receives invalid JSON data from a streaming connection (possibly as a result of the connection being cut off), it now uses its regular error-handling logic: the error is emitted as an `error` event or, if there are no `error` event listeners, it is logged. Previously, it would be thrown as an unhandled exception.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _defineProperty(e,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 _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var n=0,t=new Array(e.length);n<e.length;n++)t[n]=e[n];return t}}function _iterableToArray(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}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"),LDInvalidDataError=createCustomError("LaunchDarklyInvalidDataError");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,LDInvalidDataError:LDInvalidDataError,isHttpErrorRecoverable:isHttpErrorRecoverable}),fromByteArray_1=fromByteArray,lookup=[],revLookup=[],code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,n,t){for(var r,o=[],i=n;i<t;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var n,t=e.length,r=t%3,o=[],i=16383,a=0,s=t-r;a<s;a+=i)o.push(encodeChunk(e,a,s<a+i?s:a+i));return 1==r?(n=e[t-1],o.push(lookup[n>>2]+lookup[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],o.push(lookup[n>>10]+lookup[n>>4&63]+lookup[n<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,o,i,a=isArray(n),s=isArray(t);if(a&&s){if((o=n.length)!=t.length)return!1;for(r=o;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=s)return!1;var u=n instanceof Date,c=t instanceof Date;if(u!=c)return!1;if(u&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var d=keyList(n);if((o=d.length)!==keyList(t).length)return!1;for(r=o;0!=r--;)if(!hasProp.call(t,d[r]))return!1;for(r=o;0!=r--;)if(!e(n[i=d[r]],t[i]))return!1;return!0}return n!=n&&t!=t},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function btoa(e){var n=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(n))}function stringToBytes(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,n){return fastDeepEqual(e,n)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function transformValuesToVersionedValues(e){var n={};for(var t in e)objectHasOwnProperty(e,t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var n={};for(var t in e)objectHasOwnProperty(e,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.5.1";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 transformHeaders(e,n){return n&&n.requestHeaderTransform?n.requestHeaderTransform(_objectSpread2({},e)):e}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 objectHasOwnProperty(e,n){return Object.prototype.hasOwnProperty.call(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,transformHeaders:transformHeaders,extend:extend,objectHasOwnProperty:objectHasOwnProperty,sanitizeUser:sanitizeUser});function createCommonjsModule(e,n){return e(n={exports:{}},n.exports),n.exports}for(var rngBrowser=createCommonjsModule(function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,n){var t=n||0,r=byteToHex;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")}var _nodeId,_clockseq,bytesToUuid_1=bytesToUuid,_lastMSecs=0,_lastNSecs=0;function v1(e,n,t){var r=n&&t||0,o=n||[],i=(e=e||{}).node||_nodeId,a=void 0!==e.clockseq?e.clockseq:_clockseq;if(null==i||null==a){var s=rngBrowser();null==i&&(i=_nodeId=[1|s[0],s[1],s[2],s[3],s[4],s[5]]),null==a&&(a=_clockseq=16383&(s[6]<<8|s[7]))}var u=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,l=u-_lastMSecs+(c-_lastNSecs)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||_lastMSecs<u)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=u,_clockseq=a;var f=(1e4*(268435455&(u+=122192928e5))+(_lastNSecs=c))%4294967296;o[r++]=f>>>24&255,o[r++]=f>>>16&255,o[r++]=f>>>8&255,o[r++]=255&f;var d=u/4294967296*1e4&268435455;o[r++]=d>>>8&255,o[r++]=255&d,o[r++]=d>>>24&15|16,o[r++]=d>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var v=0;v<6;++v)o[r+v]=i[v];return n||bytesToUuid_1(o)}var v1_1=v1,MAX_URL_LENGTH=2e3;function EventSender(s,e,u){var t="/a/"+e+".gif",c=extend({"Content-Type":"application/json"},getLDHeaders(s,u)),l=s.httpFallbackPing,f={};return f.sendChunk=function(e,r,o,n){var i=JSON.stringify(e),a=o?null:v1_1();return n?function n(t){var e=o?c:extend({},c,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return s.httpRequest("POST",r,transformHeaders(e,u),i).promise.then(function(e){if(e)return 400<=e.status&&isHttpErrorRecoverable(e.status)&&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(){}):(l&&l(r+t+"?d="+base64URLEncode(i)),Promise.resolve())},f.sendEvents=function(e,n,t){if(!s.httpRequest)return Promise.resolve();var r,o=s.httpAllowsPost();r=o?[e]:chunkUserEventsForUrl(MAX_URL_LENGTH-n.length,e);for(var i=[],a=0;a<r.length;a++)i.push(f.sendChunk(r[a],n,t,o));return Promise.all(i)},f}function EventSummarizer(){var e={},a=0,s=0,u={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=u[n];t?t.count=t.count+1:u[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>s&&(s=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in u){var r=u[t],o=e[r.key];o||(o={default:r.default,counters:[]},e[r.key]=o);var i={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:s,features:e}},e.clearSummary=function(){s=a=0,u={}},e}function UserFilter(e){var n={},u=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(r,o){return Object.keys(r).reduce(function(e,n){var t=e;return o(n)&&(!function(e){return!l[e]&&(u||-1!==i.indexOf(e)||-1!==c.indexOf(e))}(n)?t[0][n]=r[n]:t[1][n]=!0),t},[{},{}])}var i=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],o=t[1];if(e.custom){var a=n(e.custom,function(){return!0});r.custom=a[0],o=extend({},o,a[1])}var s=Object.keys(o);return s.length&&(s.sort(),r.privateAttrs=s),r},n}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},eventWithoutUser=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(e){return"local storage is unavailable: "+errorString(e)},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},invalidData=function(){return"Invalid data received from LaunchDarkly; connection may have been interrupted"},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},httpErrorMessage=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(isHttpErrorRecoverable(e)?t:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e,n){return"Error on stream connection: "+errorString(e)+", will continue retrying every "+n+" milliseconds."},unknownOption=function(e){return'Ignoring unknown config option "'+e+'"'},wrongOptionType=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},wrongOptionTypeBoolean=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},optionBelowMinimum=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},debugPolling=function(e){return"polling for feature flags at "+e},debugStreamPing=function(){return"received ping message from stream"},debugStreamPut=function(){return"received streaming update for all flags"},debugStreamPatch=function(e){return'received streaming update for flag "'+e+'"'},debugStreamPatchIgnored=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},debugStreamDelete=function(e){return'received streaming deletion for flag "'+e+'"'},debugStreamDeleteIgnored=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},debugEnqueueingEvent=function(e){return'enqueueing "'+e+'" event'},debugPostingEvents=function(e){return"sending "+e+" events"},debugPostingDiagnosticEvent=function(e){return"sending diagnostic event ("+e.kind+")"},messages=Object.freeze({__proto__:null,clientInitialized:clientInitialized,clientNotReady:clientNotReady,eventCapacityExceeded:eventCapacityExceeded,eventWithoutUser:eventWithoutUser,invalidContentType:invalidContentType,invalidKey:invalidKey,localStorageUnavailable:localStorageUnavailable,networkError:networkError,unknownCustomEventKey:unknownCustomEventKey,environmentNotFound:environmentNotFound,environmentNotSpecified:environmentNotSpecified,errorFetchingFlags:errorFetchingFlags,userNotSpecified:userNotSpecified,invalidUser:invalidUser,invalidData:invalidData,bootstrapOldFormat:bootstrapOldFormat,bootstrapInvalid:bootstrapInvalid,deprecated:deprecated,httpErrorMessage:httpErrorMessage,httpUnavailable:httpUnavailable,identifyDisabled:identifyDisabled,streamClosing:streamClosing,streamConnecting:streamConnecting,streamError:streamError,unknownOption:unknownOption,wrongOptionType:wrongOptionType,wrongOptionTypeBoolean:wrongOptionTypeBoolean,optionBelowMinimum:optionBelowMinimum,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents,debugPostingDiagnosticEvent:debugPostingDiagnosticEvent});function EventProcessor(e,n,t){var r,o=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null,i=4<arguments.length&&void 0!==arguments[4]?arguments[4]:null,a={},s=(5<arguments.length&&void 0!==arguments[5]?arguments[5]:null)||EventSender(e,t,n),u=n.eventsUrl+"/events/bulk/"+t,c=EventSummarizer(),l=UserFilter(n),f=n.inlineUsersInEvents,d=n.samplingInterval,v=n.eventCapacity,g=n.flushInterval,p=n.logger,m=[],y=0,h=!1,b=!1;function E(){return 0===d||0===Math.floor(Math.random()*d)}function k(e){m.length<v?(m.push(e),b=!1):(b||(b=!0,p.warn(eventCapacityExceeded())),o&&o.incrementDroppedEvents())}return a.enqueue=function(e){if(!h){var n=!1,t=!1;if(c.summarizeEvent(e),"feature"===e.kind?E()&&(n=!!e.trackEvents,t=function(e){return!!e.debugEventsUntilDate&&(e.debugEventsUntilDate>y&&e.debugEventsUntilDate>(new Date).getTime())}(e)):n=E(),n&&k(function(e){var n=extend({},e);return"alias"===e.kind||(f||"identify"===e.kind?n.user=l.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate)),n}(e)),t){var r=extend({},e,{kind:"debug"});r.user=l.filterUser(r.user),delete r.trackEvents,delete r.debugEventsUntilDate,k(r)}}},a.flush=function(){if(h)return Promise.resolve();var e=m,n=c.getSummary();return c.clearSummary(),n&&(n.kind="summary",e.push(n)),o&&o.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(m=[],p.debug(debugPostingEvents(e.length)),s.sendEvents(e,u).then(function(e){e&&(e.serverTime&&(y=e.serverTime),isHttpErrorRecoverable(e.status)||(h=!0),400<=e.status&&onNextTick(function(){i.maybeReportError(new LDUnexpectedResponseError(httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},a.start=function(){r=setTimeout(function e(){a.flush(),r=setTimeout(e,g)},g)},a.stop=function(){clearTimeout(r)},a}function EventEmitter(n){var e={},o={};return e.on=function(e,n,t){o[e]=o[e]||[],o[e]=o[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(o[e])for(var r=0;r<o[e].length;r++)o[e][r].handler===n&&o[e][r].context===t&&(o[e]=o[e].slice(0,r).concat(o[e].slice(r+1)))},e.emit=function(e){if(o[e])for(var n=o[e].slice(0),t=0;t<n.length;t++)n[t].handler.apply(n[t].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(o)},e.getEventListenerCount=function(e){return o[e]?o[e].length:0},e.maybeReportError=function(e){e&&(!function(e){return!!o[e]}("error")?(n||console).error(e.message):this.emit("error",e))},e}var readyEvent="ready",successEvent="initialized",failureEvent="failed";function InitializationStateTracker(r){var n=!1,t=!1,o=null,e=null,i=new Promise(function(n){r.on(readyEvent,function e(){r.off(readyEvent,e),n()})}).catch(function(){});return{getInitializationPromise:function(){return e||(n?Promise.resolve():t?Promise.reject(o):e=new Promise(function(n,t){r.on(successEvent,function e(){r.off(successEvent,e),n()}),r.on(failureEvent,function e(n){r.off(failureEvent,e),t(n)})}))},getReadyPromise:function(){return i},signalSuccess:function(){n||t||(n=!0,r.emit(successEvent),r.emit(readyEvent))},signalFailure:function(e){n||t||(t=!0,o=e,r.emit(failureEvent,e),r.emit(readyEvent)),r.maybeReportError(e)}}}var InitializationState=InitializationStateTracker;function PersistentFlagStore(t,r,o,i){var a={};function s(){var e="",n=i.getUser();return n&&(e=o||btoa(JSON.stringify(n))),"ld:"+r+":"+e}return a.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 a.clearFlags().then(function(){return null})}})},a.saveFlags=function(e){var n=extend({},e,{$schema:1});return t.set(s(),JSON.stringify(n))},a.clearFlags=function(){return t.clear(s())},a}function PersistentStorage(r,n){function o(e){t||(t=!0,n.warn(localStorageUnavailable(e)))}var e={},t=!1;return e.isEnabled=function(){return!!r},e.get=function(e){return new Promise(function(n){r?r.get(e).then(n).catch(function(e){o(e),n(void 0)}):n(void 0)})},e.set=function(e,t){return new Promise(function(n){r?r.set(e,t).then(function(){return n(!0)}).catch(function(e){o(e),n(!1)}):n(!1)})},e.clear=function(e){return new Promise(function(n){r?r.clear(e).then(function(){return n(!0)}).catch(function(e){o(e),n(!1)}):n(!1)})},e}var streamReadTimeoutMillis=3e5;function Stream(o,i,a,n){var s,u=i.streamUrl,c=i.logger,e={},l=u+"/eval/"+a,f=i.useReport,d=i.evaluationReasons,t=i.streamReconnectDelay,v=getLDHeaders(o,i),g=!1,p=null,m=null,y=null,h=null,b=null;function E(e){g||(c.warn(streamError(e,t)),g=!0),S(!1),D(),k(t)}function k(e){m||(e?m=setTimeout(r,e):r())}function r(){var e;m=null;var n="",t={headers:v,readTimeoutMillis:streamReadTimeoutMillis};if(o.eventSourceFactory){for(var r in null!=h&&(n="h="+h),f?o.eventSourceAllowsReport?(e=l,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(y)):(e=u+"/ping/"+a,n=""):e=l+"/"+base64URLEncode(JSON.stringify(y)),t.headers=transformHeaders(t.headers,i),d&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,D(),c.info(streamConnecting(e)),s=(new Date).getTime(),p=o.eventSourceFactory(e,t),b)objectHasOwnProperty(b,r)&&p.addEventListener(r,b[r]);p.onerror=E}}function D(){p&&(c.info(streamClosing()),p.close(),p=null)}function S(e){s&&n&&n.recordStreamInit(s,!e,(new Date).getTime()-s),s=null}return e.connect=function(e,n,t){y=e,h=n,b={};function r(n){b[n]=function(e){S(!(g=!1)),t[n]&&t[n](e)}}for(var o in t||{})r(o);k()},e.disconnect=function(){clearTimeout(m),m=null,D()},e.isConnected=function(){return!!(p&&o.eventSourceIsActive&&o.eventSourceIsActive(p))},e}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 jsonContentType="application/json";function getResponseError(e){return 404===e.status?new LDInvalidEnvironmentIdError(environmentNotFound()):new LDFlagFetchError(errorFetchingFlags(e.statusText||String(e.status)))}function Requestor(s,u,a){var c=u.baseUrl,l=u.useReport,f=u.evaluationReasons,d=u.logger,e={},v={};function g(e,n){if(!s.httpRequest)return new Promise(function(e,n){n(new LDFlagFetchError(httpUnavailable()))});var t=n?"REPORT":"GET",r=getLDHeaders(s,u);n&&(r["Content-Type"]=jsonContentType);var o=v[e];o||(o=promiseCoalescer(function(){delete v[e]}),v[e]=o);var i=s.httpRequest(t,e,transformHeaders(r,u),n),a=i.promise.then(function(e){if(200!==e.status)return Promise.reject(getResponseError(e));if(e.header("content-type")&&e.header("content-type").substring(0,jsonContentType.length)===jsonContentType)return JSON.parse(e.body);var n=invalidContentType(e.header("content-type")||"");return Promise.reject(new LDFlagFetchError(n))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))});return o.addPromise(a,function(){i.cancel&&i.cancel()}),o.resultPromise}return e.fetchJSON=function(e){return g(c+e,null)},e.fetchFlagSettings=function(e,n){var t,r,o,i="";return l?(r=[c,"/sdk/evalx/",a,"/user"].join(""),o=JSON.stringify(e)):(t=base64URLEncode(JSON.stringify(e)),r=[c,"/sdk/evalx/",a,"/users/",t].join("")),n&&(i="h="+n),f&&(i=i+(i?"&":"")+"withReasons=true"),r=r+(i?"?":"")+i,d.debug(debugPolling(r)),g(r,o)},e}function Identity(e,t){var r,n={};return n.setUser=function(e){var n=r&&clone(r);(r=sanitizeUser(e))&&t&&t(clone(r),n)},n.getUser=function(){return r?clone(r):null},e&&n.setUser(e),n}var ldUserIdKey="ld:$anonUserId";function UserValidator(r){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.get(ldUserIdKey).then(function(e){if(e)return t.key=e,t;var n=v1_1();return function(e){return r.set(ldUserIdKey,e)}(t.key=n).then(function(){return t})}):Promise.reject(new LDInvalidUserError(invalidUser()))},e}var logLevels=["debug","info","warn","error","none"];function commonBasicLogger(e,a){if(e&&e.destination&&"function"!=typeof e.destination)throw new Error("destination for basicLogger was set to a non-function");function n(n){return function(e){console&&console[n]&&console[n].call(console,e)}}var s=e&&e.destination?[e.destination,e.destination,e.destination,e.destination]:[n("log"),n("info"),n("warn"),n("error")],u=!(!e||!e.destination),c=e&&void 0!==e.prefix&&null!==e.prefix?e.prefix:"[LaunchDarkly] ",r=1;if(e&&e.level)for(var t=0;t<logLevels.length;t++)logLevels[t]===e.level&&(r=t);for(var o={},i=function(e){var n=logLevels[e];if("none"!==n)if(e<r)o[n]=function(){};else{var t=e;o[n]=function(){!function(e,n,t){if(!(t.length<1)){var r,o=u?n+": "+c:c;if(1!==t.length&&a){var i=_toConsumableArray(t);i[0]=o+i[0],r=a.apply(void 0,_toConsumableArray(i))}else r=o+t[0];try{s[e](r)}catch(e){console&&console.log&&console.log("[LaunchDarkly] Configured logger's "+n+" method threw an exception: "+e)}}}(t,n,arguments)}}},l=0;l<logLevels.length;l++)i(l);return o}function validateLogger(n){logLevels.forEach(function(e){if("none"!==e&&(!n[e]||"function"!=typeof n[e]))throw new Error("Provided logger instance must support logger."+e+"(...) method")})}function createConsoleLogger(e,n){return commonBasicLogger({level:e,prefix:n})}var baseOptionDefs={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},requestHeaderTransform:{type:"function"},inlineUsersInEvents:{default:!1},allowFrequentDuplicateEvents:{default:!1},sendEventsOnlyForVariation:{default:!1},useReport:{default:!1},evaluationReasons:{default:!1},eventCapacity:{default:100,minimum:1},flushInterval:{default:2e3,minimum:2e3},samplingInterval:{default:0,minimum:0},streamReconnectDelay:{default:1e3,minimum:0},allAttributesPrivate:{default:!1},privateAttributeNames:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"},autoAliasingOptOut:{default:!1}};function validate(e,n,t,r){var a=extend({logger:{default:r}},baseOptionDefs,t),o={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function s(e){onNextTick(function(){n&&n.maybeReportError(new LDInvalidArgumentError(e))})}var i,u,c,l,f=extend({},e||{});function d(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=_typeof(e);return"boolean"===n||"string"===n||"number"===n||"function"===n?n:"object"}}return i=f,Object.keys(o).forEach(function(e){if(void 0!==i[e]){var n=o[e];r&&r.warn(deprecated(e,n)),n&&(void 0===i[n]&&(i[n]=i[e]),delete i[e])}}),u=extend({},f),Object.keys(a).forEach(function(e){void 0!==u[e]&&null!==u[e]||(u[e]=a[e]&&a[e].default)}),l=extend({},c=f=u),Object.keys(c).forEach(function(e){var n=c[e];if(null!=n){var t=a[e];if(void 0===t)s(unknownOption(e));else{var r=t.type||d(t.default);if("any"!==r){var o=r.split("|"),i=d(n);o.indexOf(i)<0?"boolean"===r?(l[e]=!!n,s(wrongOptionTypeBoolean(e,i))):(s(wrongOptionType(e,r,i)),l[e]=t.default):"number"===i&&void 0!==t.minimum&&n<t.minimum&&(s(optionBelowMinimum(e,n,t.minimum)),l[e]=t.minimum)}}}}),validateLogger((f=l).logger),f}var configuration=Object.freeze({__proto__:null,baseOptionDefs:baseOptionDefs,validate:validate}),baseOptionDefs$1=configuration.baseOptionDefs;function DiagnosticId(e){var n={diagnosticId:v1_1()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n}function DiagnosticsAccumulator(e){var n,t,r,o;function i(e){n=e,r=t=0,o=[]}return i(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:o}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};o.push(r)},reset:i}}function DiagnosticsManager(n,r,e,t,o,i,a){var s,u,c=!!n.diagnosticUseCombinedEvent,l="ld:"+o+":$diagnostics",f=i.eventsUrl+"/events/diagnostic/"+o,d=i.diagnosticRecordingInterval,v=e,g=!!i.streaming,p={};function m(){return{sdk:function(){var e=_objectSpread2({},n.diagnosticSdkData);i.wrapperName&&(e.wrapperName=i.wrapperName);i.wrapperVersion&&(e.wrapperVersion=i.wrapperVersion);return e}(),configuration:{customBaseURI:i.baseUrl!==baseOptionDefs$1.baseUrl.default,customStreamURI:i.streamUrl!==baseOptionDefs$1.streamUrl.default,customEventsURI:i.eventsUrl!==baseOptionDefs$1.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!g,allAttributesPrivate:!!i.allAttributesPrivate,inlineUsersInEvents:!!i.inlineUsersInEvents,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,allowFrequentDuplicateEvents:!!i.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation,autoAliasingOptOut:!!i.autoAliasingOptOut},platform:n.diagnosticPlatformData}}function y(e){i.logger&&i.logger.debug(messages.debugPostingDiagnosticEvent(e)),t.sendEvents(e,f,!0).then(function(){}).catch(function(){})}function h(){y(function(){var e=(new Date).getTime(),n=_objectSpread2({kind:c?"diagnostic-combined":"diagnostic",id:a,creationDate:e},v.getProps());return c&&(n=_objectSpread2({},n,{},m())),v.reset(e),n}()),u=setTimeout(h,d),s=(new Date).getTime(),c&&function(){if(r.isEnabled()){var e=_objectSpread2({},v.getProps());r.set(l,JSON.stringify(e))}}()}return p.start=function(){c?function(t){if(!r.isEnabled())return t(!1);r.get(l).then(function(e){if(e)try{var n=JSON.parse(e);v.setProps(n),s=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(s||0)+d,t=(new Date).getTime();n<=t?h():u=setTimeout(h,n-t)}else 0===Math.floor(4*Math.random())?h():u=setTimeout(h,d)}):(y(_objectSpread2({kind:"diagnostic-init",id:a,creationDate:v.getProps().dataSinceDate},m())),u=setTimeout(h,d))},p.stop=function(){u&&clearTimeout(u)},p.setStreaming=function(e){g=e},p}var diagnosticEvents={DiagnosticId:DiagnosticId,DiagnosticsAccumulator:DiagnosticsAccumulator,DiagnosticsManager:DiagnosticsManager},diagnosticEvents_1=diagnosticEvents.DiagnosticId,diagnosticEvents_2=diagnosticEvents.DiagnosticsAccumulator,diagnosticEvents_3=diagnosticEvents.DiagnosticsManager,changeEvent="change",internalChangeEvent="internal-change";function initialize(e,n,t,i,r){var a,o,s,u=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||createConsoleLogger("warn")}(),c=EventEmitter(u),l=InitializationState(c),f=validate(t,c,r,u),d=f.sendEvents,v=e,g=f.hash,p=PersistentStorage(i.localStorage,u),m=EventSender(i,v,f),y=f.sendEvents&&!f.diagnosticOptOut,h=y?diagnosticEvents_1(v):null,b=y?diagnosticEvents_2((new Date).getTime()):null,E=y?diagnosticEvents_3(i,p,b,m,v,f,h):null,k=Stream(i,f,v,b),D=f.eventProcessor||EventProcessor(i,f,v,b,c,m),S=Requestor(i,f,v),w={},P={},U=f.streaming,L=!1,O=!1,I=!0,T=f.stateProvider,C=Identity(null,function(e,n){(function(e){if(T)return;e&&F({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})(e),!f.autoAliasingOptOut&&n&&n.anonymous&&e&&!e.anonymous&&V(e,n)}),_=UserValidator(p),j=p.isEnabled()?new PersistentFlagStore(p,v,g,C,u):null;function F(e){if(v&&!(T&&T.enqueueEvent&&T.enqueueEvent(e))){if("alias"!==e.kind){if(!e.user)return void(I&&(u.warn(eventWithoutUser()),I=!1));I=!1}!d||O||i.isDoNotTrack()||(u.debug(debugEnqueueingEvent(e.kind)),D.enqueue(e))}}function R(e,n,t,r){var o=C.getUser(),i=new Date,a=n?n.value:null;if(!f.allowFrequentDuplicateEvents){var s=JSON.stringify(a)+(o&&o.key?o.key:"")+e,u=w[s];if(u&&i-u<3e5)return;w[s]=i}var c={kind:"feature",key:e,user:o,value:a,variation:n?n.variationIndex:null,default:t,creationDate:i.getTime()};o&&o.anonymous&&(c.contextKind=N(o));var l=P[e];l&&(c.version=l.flagVersion?l.flagVersion:l.version,c.trackEvents=l.trackEvents,c.debugEventsUntilDate=l.debugEventsUntilDate),(r||l&&l.trackReason)&&n&&(c.reason=n.reason),F(c)}function x(e,n,t,r){var o;if(P&&objectHasOwnProperty(P,e)&&P[e]&&!P[e].deleted){var i=P[e];o=A(i),null!==i.value&&void 0!==i.value||(o.value=n)}else o={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&R(e,o,n,r),o}function A(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function N(e){return e.anonymous?"anonymousUser":"user"}function V(e,n){T||e&&n&&F({kind:"alias",key:e.key,contextKind:N(e),previousKey:n.key,previousContextKind:N(n),creationDate:(new Date).getTime()})}function H(){if(o=!0,C.getUser()){var a=function(e){try{return JSON.parse(e)}catch(e){return void c.maybeReportError(new LDInvalidDataError(invalidData()))}};k.connect(C.getUser(),g,{ping:function(){u.debug(debugStreamPing());var n=C.getUser();S.fetchFlagSettings(n,g).then(function(e){deepEquals(n,C.getUser())&&M(e||{})}).catch(function(e){c.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){var n=a(e.data);n&&(u.debug(debugStreamPut()),M(n))},patch:function(e){var n=a(e.data);if(n){var t=P[n.key];if(!t||!t.version||!n.version||t.version<n.version){u.debug(debugStreamPatch(n.key));var r={},o=extend({},n);delete o.key;var i=A(P[n.key]=o);r[n.key]=t?{previous:t.value,current:i}:{current:i},z(r)}else u.debug(debugStreamPatchIgnored(n.key))}},delete:function(e){var n=a(e.data);if(n)if(!P[n.key]||P[n.key].version<n.version){u.debug(debugStreamDelete(n.key));var t={};P[n.key]&&!P[n.key].deleted&&(t[n.key]={previous:P[n.key].value}),P[n.key]={version:n.version,deleted:!0},z(t)}else u.debug(debugStreamDeleteIgnored(n.key))}})}}function q(){o&&(k.disconnect(),o=!1)}function M(e){var n={};if(!e)return Promise.resolve();for(var t in P)objectHasOwnProperty(P,t)&&P[t]&&(e[t]&&!deepEquals(e[t].value,P[t].value)?n[t]={previous:P[t].value,current:A(e[t])}:e[t]&&!e[t].deleted||(n[t]={previous:P[t].value}));for(var r in e)objectHasOwnProperty(e,r)&&e[r]&&(!P[r]||P[r].deleted)&&(n[r]={current:A(e[r])});return P=_objectSpread2({},e),z(n).catch(function(){})}function z(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;c.emit(changeEvent+":"+e,t,r),i[e]=n?{current:t,previous:r}:{previous:r}}),c.emit(changeEvent,i),c.emit(internalChangeEvent,P),f.sendEventsOnlyForVariation||T||e.forEach(function(e){R(e,o[e].current)})}return a&&j?j.saveFlags(P):Promise.resolve()}function K(){var e=U||s&&void 0===U;e&&!o?H():!e&&o&&q(),E&&E.setStreaming(e)}function B(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}if("string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(j?a=!0:u.warn(localStorageUnavailable())),"object"===_typeof(f.bootstrap)&&(P=function(t){var e=Object.keys(t),r="$flagsState",o=t[r];!o&&e.length&&u.warn(bootstrapOldFormat()),!1===t.$valid&&u.warn(bootstrapInvalid());var i={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var n={value:t[e]};o&&o[e]?n=extend(n,o[e]):n.version=0,i[e]=n}}),i}(f.bootstrap)),T){var J=T.getInitialState();J?$(J):T.on("init",$),T.on("update",function(e){e.user&&C.setUser(e.user);e.flags&&M(e.flags)})}else(e?_.validateUser(n).then(function(e){return C.setUser(e),"object"===_typeof(f.bootstrap)?G():a?j.loadFlags().then(function(e){return null==e?(P={},S.fetchFlagSettings(C.getUser(),g).then(function(e){return M(e||{})}).then(G).catch(function(e){W(new LDFlagFetchError(errorFetchingFlags(e)))})):(P=e,onNextTick(G),S.fetchFlagSettings(C.getUser(),g).then(function(e){return M(e)}).catch(function(e){return c.maybeReportError(e)}))}):S.fetchFlagSettings(C.getUser(),g).then(function(e){P=e||{},G()}).catch(function(e){P={},W(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(W);function $(e){v=e.environment,C.setUser(e.user),P=_objectSpread2({},e.flags),onNextTick(G)}function G(){u.info(clientInitialized()),L=!0,K(),l.signalSuccess()}function W(e){l.signalFailure(e)}return{client:{waitForInitialization:function(){return l.getInitializationPromise()},waitUntilReady:function(){return l.getReadyPromise()},identify:function(e,r,n){return O?wrapPromiseCallback(Promise.resolve({}),n):T?(u.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(P)),n)):wrapPromiseCallback((a&&j?j.clearFlags():Promise.resolve()).then(function(){return _.validateUser(e)}).then(function(t){return S.fetchFlagSettings(t,r).then(function(e){var n=transformVersionedValuesToValues(e);return C.setUser(t),g=r,e?M(e).then(function(){return n}):n})}).then(function(e){return o&&H(),e}).catch(function(e){return c.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return C.getUser()},variation:function(e,n){return x(e,n,!0,!1).value},variationDetail:function(e,n){return x(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&u.warn(unknownCustomEventKey(e));var r=C.getUser(),o={kind:"custom",key:e,user:r,url:i.getCurrentUrl(),creationDate:(new Date).getTime()};r&&r.anonymous&&(o.contextKind=N(r)),null!=n&&(o.data=n),null!=t&&(o.metricValue=t),F(o)}else c.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e)))},alias:V,on:function(e,n,t){B(e)?(s=!0,L&&K(),c.on(e,n,t)):c.on.apply(c,arguments)},off:function(e){if(c.off.apply(c,arguments),B(e)){var n=!1;c.getEvents().forEach(function(e){B(e)&&0<c.getEventListenerCount(e)&&(n=!0)}),n||(s=!1,o&&void 0===U&&q())}},setStreaming:function(e){var n=null===e?void 0:e;n!==U&&(U=n,K())},flush:function(e){return wrapPromiseCallback(d?D.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!P)return e;for(var n in P)objectHasOwnProperty(P,n)&&(e[n]=x(n,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){if(O)return wrapPromiseCallback(Promise.resolve(),e);function n(){O=!0,P={}}return wrapPromiseCallback(Promise.resolve().then(function(){if(q(),E&&E.stop(),d)return D.stop(),D.flush()}).then(n).catch(n),e)}},options:f,emitter:c,ident:C,logger:u,requestor:S,start:function(){d&&(E&&E.start(),D.start())},enqueueEvent:F,getFlagsInternal:function(){return P},getEnvironmentId:function(){return v},internalChangeEventName:internalChangeEvent}}var version="3.5.1";exports.commonBasicLogger=commonBasicLogger,exports.createConsoleLogger=createConsoleLogger,exports.errors=errors,exports.initialize=initialize,exports.messages=messages,exports.utils=utils,exports.version=version;
|
|
1
|
+
"use strict";function ownKeys(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function _objectSpread2(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(n),!0).forEach(function(e){_defineProperty(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n=Object.prototype.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function createCustomError(e){function t(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=t}return(t.prototype=new Error).name=e,t.prototype.constructor=t}Object.defineProperty(exports,"__esModule",{value:!0});var LDUnexpectedResponseError=createCustomError("LaunchDarklyUnexpectedResponseError"),LDInvalidEnvironmentIdError=createCustomError("LaunchDarklyInvalidEnvironmentIdError"),LDInvalidUserError=createCustomError("LaunchDarklyInvalidUserError"),LDInvalidEventKeyError=createCustomError("LaunchDarklyInvalidEventKeyError"),LDInvalidArgumentError=createCustomError("LaunchDarklyInvalidArgumentError"),LDFlagFetchError=createCustomError("LaunchDarklyFlagFetchError"),LDInvalidDataError=createCustomError("LaunchDarklyInvalidDataError");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,LDInvalidDataError:LDInvalidDataError,isHttpErrorRecoverable:isHttpErrorRecoverable}),fromByteArray_1=fromByteArray,lookup=[],revLookup=[],code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,t,n){for(var r,o=[],i=t;i<n;i+=3)r=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]),o.push(tripletToBase64(r));return o.join("")}function fromByteArray(e){for(var t,n=e.length,r=n%3,o=[],i=16383,a=0,s=n-r;a<s;a+=i)o.push(encodeChunk(e,a,s<a+i?s:a+i));return 1==r?(t=e[n-1],o.push(lookup[t>>2]+lookup[t<<4&63]+"==")):2==r&&(t=(e[n-2]<<8)+e[n-1],o.push(lookup[t>>10]+lookup[t>>4&63]+lookup[t<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var isArray=Array.isArray,keyList=Object.keys,hasProp=Object.prototype.hasOwnProperty,fastDeepEqual=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){var r,o,i=isArray(t),a=isArray(n);if(i&&a){if((s=t.length)!=n.length)return!1;for(r=s;0!=r--;)if(!e(t[r],n[r]))return!1}else{if(i!=a)return!1;i=t instanceof Date,a=n instanceof Date;if(i!=a)return!1;if(i&&a)return t.getTime()==n.getTime();i=t instanceof RegExp,a=n instanceof RegExp;if(i!=a)return!1;if(i&&a)return t.toString()==n.toString();var s,u=keyList(t);if((s=u.length)!==keyList(n).length)return!1;for(r=s;0!=r--;)if(!hasProp.call(n,u[r]))return!1;for(r=s;0!=r--;)if(!e(t[o=u[r]],n[o]))return!1}return!0}return t!=t&&n!=n},userAttrsToStringify=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function appendUrlPath(e,t){return(e.endsWith("/")?e.substring(0,e.length-1):e)+(t.startsWith("/")?"":"/")+t}function btoa(e){e=unescape(encodeURIComponent(e));return fromByteArray_1(stringToBytes(e))}function stringToBytes(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}function base64URLEncode(e){return btoa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function clone(e){return JSON.parse(JSON.stringify(e))}function deepEquals(e,t){return fastDeepEqual(e,t)}function onNextTick(e){setTimeout(e,0)}function wrapPromiseCallback(e,t){e=e.then(function(e){return t&&setTimeout(function(){t(null,e)},0),e},function(e){if(!t)return Promise.reject(e);setTimeout(function(){t(e,null)},0)});return t?void 0:e}function transformValuesToVersionedValues(e){var t,n={};for(t in e)objectHasOwnProperty(e,t)&&(n[t]={value:e[t],version:0});return n}function transformVersionedValuesToValues(e){var t,n={};for(t in e)objectHasOwnProperty(e,t)&&(n[t]=e[t].value);return n}function chunkUserEventsForUrl(e,t){for(var n,r=t.slice(0),o=[],i=e;0<r.length;){for(n=[];0<i;){var a=r.shift();if(!a)break;(i-=base64URLEncode(JSON.stringify(a)).length)<0&&0<n.length?r.unshift(a):n.push(a)}i=e,o.push(n)}return o}function getLDUserAgentString(e){var t=e.version||"3.7.0";return e.userAgent+"/"+t}function extend(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.reduce(function(e,t){return _objectSpread2(_objectSpread2({},e),t)},{})}function objectHasOwnProperty(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function sanitizeUser(e){if(!e)return e;var t,n;for(n in userAttrsToStringify){var r=userAttrsToStringify[n],o=e[r];void 0!==o&&"string"!=typeof o&&((t=t||_objectSpread2({},e))[r]=String(o))}return t||e}var utils=Object.freeze({__proto__:null,appendUrlPath:appendUrlPath,btoa:btoa,base64URLEncode:base64URLEncode,clone:clone,deepEquals:deepEquals,onNextTick:onNextTick,wrapPromiseCallback:wrapPromiseCallback,transformValuesToVersionedValues:transformValuesToVersionedValues,transformVersionedValuesToValues:transformVersionedValuesToValues,chunkUserEventsForUrl:chunkUserEventsForUrl,getLDUserAgentString:getLDUserAgentString,extend:extend,objectHasOwnProperty:objectHasOwnProperty,sanitizeUser:sanitizeUser});function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}for(var rngBrowser=createCommonjsModule(function(e){var t,n,r="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);r?(t=new Uint8Array(16),e.exports=function(){return r(t),t}):(n=new Array(16),e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),n[t]=e>>>((3&t)<<3)&255;return n})}),byteToHex=[],i$1=0;i$1<256;++i$1)byteToHex[i$1]=(i$1+256).toString(16).substr(1);function bytesToUuid(e,t){var t=t||0,n=byteToHex;return[n[e[t++]],n[e[t++]],n[e[t++]],n[e[t++]],"-",n[e[t++]],n[e[t++]],"-",n[e[t++]],n[e[t++]],"-",n[e[t++]],n[e[t++]],"-",n[e[t++]],n[e[t++]],n[e[t++]],n[e[t++]],n[e[t++]],n[e[+t]]].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,n=void 0!==e.clockseq?e.clockseq:_clockseq,a=(null!=i&&null!=n||(a=rngBrowser(),null==i&&(i=_nodeId=[1|a[0],a[1],a[2],a[3],a[4],a[5]]),null==n&&(n=_clockseq=16383&(a[6]<<8|a[7]))),void 0!==e.msecs?e.msecs:(new Date).getTime()),s=void 0!==e.nsecs?e.nsecs:_lastNSecs+1,u=a-_lastMSecs+(s-_lastNSecs)/1e4;if(u<0&&void 0===e.clockseq&&(n=n+1&16383),1e4<=(s=(u<0||_lastMSecs<a)&&void 0===e.nsecs?0:s))throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");_lastMSecs=a,_clockseq=n;u=(1e4*(268435455&(a+=122192928e5))+(_lastNSecs=s))%4294967296,o[r++]=u>>>24&255,o[r++]=u>>>16&255,o[r++]=u>>>8&255,o[r++]=255&u,e=a/4294967296*1e4&268435455;o[r++]=e>>>8&255,o[r++]=255&e,o[r++]=e>>>24&15|16,o[r++]=e>>>16&255,o[r++]=n>>>8|128,o[r++]=255&n;for(var c=0;c<6;++c)o[r+c]=i[c];return t||bytesToUuid_1(o)}var v1_1=v1,logLevels=["debug","info","warn","error","none"];function commonBasicLogger(e,s){if(e&&e.destination&&"function"!=typeof e.destination)throw new Error("destination for basicLogger was set to a non-function");function t(t){return function(e){console&&console[t]&&console[t].call(console,e)}}var u=e&&e.destination?[e.destination,e.destination,e.destination,e.destination]:[t("log"),t("info"),t("warn"),t("error")],c=!(!e||!e.destination),l=e&&void 0!==e.prefix&&null!==e.prefix?e.prefix:"[LaunchDarkly] ",n=1;if(e&&e.level)for(var r=0;r<logLevels.length;r++)logLevels[r]===e.level&&(n=r);for(var o={},i=function(e){var i,a=logLevels[e];"none"!==a&&(e<n?o[a]=function(){}:(i=e,o[a]=function(){var e=i,t=a,n=arguments;if(!(n.length<1)){var r=c?t+": "+l:l,o=1!==n.length&&s?((o=_toConsumableArray(n))[0]=r+o[0],s.apply(void 0,_toConsumableArray(o))):r+n[0];try{u[e](o)}catch(e){console&&console.log&&console.log("[LaunchDarkly] Configured logger's "+t+" method threw an exception: "+e)}}}))},a=0;a<logLevels.length;a++)i(a);return o}function validateLogger(t){logLevels.forEach(function(e){if("none"!==e&&(!t[e]||"function"!=typeof t[e]))throw new Error("Provided logger instance must support logger."+e+"(...) method")})}function createConsoleLogger(e,t){return commonBasicLogger({level:e,prefix:t})}function errorString(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}var clientInitialized=function(){return"LaunchDarkly client initialized"},docLink=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initializing-the-client for instructions on SDK initialization.",clientNotReady=function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},eventWithoutUser=function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},invalidContentType=function(e){return'Expected application/json content type but got "'+e+'"'},invalidKey=function(){return"Event key must be a string"},localStorageUnavailable=function(e){return"local storage is unavailable: "+errorString(e)},networkError=function(e){return"network error"+(e?" ("+e+")":"")},unknownCustomEventKey=function(e){return'Custom event "'+e+'" does not exist'},environmentNotFound=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+docLink},environmentNotSpecified=function(){return"No environment/client-side ID was specified."+docLink},errorFetchingFlags=function(e){return"Error fetching flag settings: "+errorString(e)},userNotSpecified=function(){return"No user specified."+docLink},invalidUser=function(){return"Invalid user specified."+docLink},invalidData=function(){return"Invalid data received from LaunchDarkly; connection may have been interrupted"},bootstrapOldFormat=function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+docLink},bootstrapInvalid=function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},deprecated=function(e,t){return t?'"'+e+'" is deprecated, please use "'+t+'"':'"'+e+'" is deprecated'},httpErrorMessage=function(e,t,n){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+t+" - "+(isHttpErrorRecoverable(e)?n:"giving up permanently")},httpUnavailable=function(){return"Cannot make HTTP requests in this environment."+docLink},identifyDisabled=function(){return"identify() has no effect here; it must be called on the main client instance"},streamClosing=function(){return"Closing stream connection"},streamConnecting=function(e){return"Opening stream connection to "+e},streamError=function(e,t){return"Error on stream connection: "+errorString(e)+", will continue retrying every "+t+" milliseconds."},unknownOption=function(e){return'Ignoring unknown config option "'+e+'"'},wrongOptionType=function(e,t,n){return'Config option "'+e+'" should be of type '+t+", got "+n+", using default value"},wrongOptionTypeBoolean=function(e,t){return'Config option "'+e+'" should be a boolean, got '+t+", converting to boolean"},optionBelowMinimum=function(e,t,n){return'Config option "'+e+'" was set to '+t+", changing to minimum value of "+n},debugPolling=function(e){return"polling for feature flags at "+e},debugStreamPing=function(){return"received ping message from stream"},debugStreamPut=function(){return"received streaming update for all flags"},debugStreamPatch=function(e){return'received streaming update for flag "'+e+'"'},debugStreamPatchIgnored=function(e){return'received streaming update for flag "'+e+'" but ignored due to version check'},debugStreamDelete=function(e){return'received streaming deletion for flag "'+e+'"'},debugStreamDeleteIgnored=function(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'},debugEnqueueingEvent=function(e){return'enqueueing "'+e+'" event'},debugPostingEvents=function(e){return"sending "+e+" events"},debugPostingDiagnosticEvent=function(e){return"sending diagnostic event ("+e.kind+")"},invalidTagValue=function(e){return'Config option "'.concat(e,'" must only contain letters, numbers, ., _ or -.')},messages=Object.freeze({__proto__:null,clientInitialized:clientInitialized,clientNotReady:clientNotReady,eventCapacityExceeded:eventCapacityExceeded,eventWithoutUser:eventWithoutUser,invalidContentType:invalidContentType,invalidKey:invalidKey,localStorageUnavailable:localStorageUnavailable,networkError:networkError,unknownCustomEventKey:unknownCustomEventKey,environmentNotFound:environmentNotFound,environmentNotSpecified:environmentNotSpecified,errorFetchingFlags:errorFetchingFlags,userNotSpecified:userNotSpecified,invalidUser:invalidUser,invalidData:invalidData,bootstrapOldFormat:bootstrapOldFormat,bootstrapInvalid:bootstrapInvalid,deprecated:deprecated,httpErrorMessage:httpErrorMessage,httpUnavailable:httpUnavailable,identifyDisabled:identifyDisabled,streamClosing:streamClosing,streamConnecting:streamConnecting,streamError:streamError,unknownOption:unknownOption,wrongOptionType:wrongOptionType,wrongOptionTypeBoolean:wrongOptionTypeBoolean,optionBelowMinimum:optionBelowMinimum,debugPolling:debugPolling,debugStreamPing:debugStreamPing,debugStreamPut:debugStreamPut,debugStreamPatch:debugStreamPatch,debugStreamPatchIgnored:debugStreamPatchIgnored,debugStreamDelete:debugStreamDelete,debugStreamDeleteIgnored:debugStreamDeleteIgnored,debugEnqueueingEvent:debugEnqueueingEvent,debugPostingEvents:debugPostingEvents,debugPostingDiagnosticEvent:debugPostingDiagnosticEvent,invalidTagValue:invalidTagValue}),baseOptionDefs={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},requestHeaderTransform:{type:"function"},inlineUsersInEvents:{default:!1},allowFrequentDuplicateEvents:{default:!1},sendEventsOnlyForVariation:{default:!1},useReport:{default:!1},evaluationReasons:{default:!1},eventCapacity:{default:100,minimum:1},flushInterval:{default:2e3,minimum:2e3},samplingInterval:{default:0,minimum:0},streamReconnectDelay:{default:1e3,minimum:0},allAttributesPrivate:{default:!1},privateAttributeNames:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"},autoAliasingOptOut:{default:!1},application:{validator:applicationConfigValidator}},allowedTagCharacters=/^(\w|\.|-)+$/;function validateTagValue(e,t,n,r){if("string"==typeof n&&n.match(allowedTagCharacters))return n;r.warn(invalidTagValue(e))}function applicationConfigValidator(e,t,n,r){var o={};return n.id&&(o.id=validateTagValue("".concat(e,".id"),t,n.id,r)),n.version&&(o.version=validateTagValue("".concat(e,".version"),t,n.version,r)),o}function validate(e,t,n,a){var s=extend({logger:{default:a}},baseOptionDefs,n),r={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null,allowFrequentDuplicateEvents:void 0};function u(e){onNextTick(function(){t&&t.maybeReportError(new LDInvalidArgumentError(e))})}var o,i,c,l,n=extend({},e||{});function d(e){return null===e?"any":void 0!==e?Array.isArray(e)?"array":"boolean"===(e=_typeof(e))||"string"===e||"number"===e||"function"===e?e:"object":void 0}return o=n,Object.keys(r).forEach(function(e){var t;void 0!==o[e]&&(t=r[e],a&&a.warn(deprecated(e,t)),t&&(void 0===o[t]&&(o[t]=o[e]),delete o[e]))}),i=extend({},n),Object.keys(s).forEach(function(e){void 0!==i[e]&&null!==i[e]||(i[e]=s[e]&&s[e].default)}),l=extend({},c=n=i),Object.keys(c).forEach(function(e){var t,n,r,o,i=c[e];null!=i&&(void 0===(t=s[e])?u(unknownOption(e)):(n=t.type||d(t.default),(r=t.validator)?void 0!==(r=r(e,c,c[e],a))?l[e]=r:delete l[e]:"any"!==n&&(r=n.split("|"),o=d(i),r.indexOf(o)<0?"boolean"===n?(l[e]=!!i,u(wrongOptionTypeBoolean(e,o))):(u(wrongOptionType(e,n,o)),l[e]=t.default):"number"===o&&void 0!==t.minimum&&i<t.minimum&&(u(optionBelowMinimum(e,i,t.minimum)),l[e]=t.minimum))))}),validateLogger((n=l).logger),n}function getTags(e){var t={};return e&&(e.application&&void 0!==e.application.id&&null!==e.application.id&&(t["application-id"]=[e.application.id]),e.application&&void 0!==e.application.version&&null!==e.application.id&&(t["application-version"]=[e.application.version])),t}var configuration=Object.freeze({__proto__:null,baseOptionDefs:baseOptionDefs,validate:validate,getTags:getTags});function getLDHeaders(e,t){var n;return t&&!t.sendLDHeaders?{}:(e={"X-LaunchDarkly-User-Agent":getLDUserAgentString(e)},t&&t.wrapperName&&(e["X-LaunchDarkly-Wrapper"]=t.wrapperVersion?t.wrapperName+"/"+t.wrapperVersion:t.wrapperName),n=getTags(t),(t=Object.keys(n)).length&&(e["x-launchdarkly-tags"]=t.sort().flatMap(function(t){return Array.isArray(n[t])?n[t].sort().map(function(e){return"".concat(t,"/").concat(e)}):["".concat(t,"/").concat(n[t])]}).join(" ")),e)}function transformHeaders(e,t){return t&&t.requestHeaderTransform?t.requestHeaderTransform(_objectSpread2({},e)):e}var MAX_URL_LENGTH=2e3;function EventSender(s,e,u){var c="/a/"+e+".gif",l=extend({"Content-Type":"application/json"},getLDHeaders(s,u)),d=s.httpFallbackPing,f={};return f.sendChunk=function(e,t,r,n){var o=JSON.stringify(e),i=r?null:v1_1();function a(n){var e=r?l:extend({},l,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":i});return s.httpRequest("POST",t,transformHeaders(e,u),o).promise.then(function(e){var t;if(e)return 400<=e.status&&isHttpErrorRecoverable(e.status)&&n?a(!1):(t={status:(e=e).status},(e=e.header("date"))&&(e=Date.parse(e))&&(t.serverTime=e),t)}).catch(function(){return n?a(!1):Promise.reject()})}return n?a(!0).catch(function(){}):(d&&d(t+c+"?d="+base64URLEncode(o)),Promise.resolve())},f.sendEvents=function(e,t,n){if(!s.httpRequest)return Promise.resolve();for(var r=s.httpAllowsPost(),o=r?[e]:chunkUserEventsForUrl(MAX_URL_LENGTH-t.length,e),i=[],a=0;a<o.length;a++)i.push(f.sendChunk(o[a],t,n,r));return Promise.all(i)},f}function EventSummarizer(){var e={},a=0,s=0,u={};return e.summarizeEvent=function(e){var t,n;"feature"===e.kind&&(t=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),(n=u[t])?n.count=n.count+1:u[t]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>s&&(s=e.creationDate))},e.getSummary=function(){var e,t={},n=!0;for(e in u){var r=u[e],o=t[r.key],i=(o||(o={default:r.default,counters:[]},t[r.key]=o),{value:r.value,count:r.count});void 0!==r.variation&&null!==r.variation&&(i.variation=r.variation),r.version?i.version=r.version:i.unknown=!0,o.counters.push(i),n=!1}return n?null:{startDate:a,endDate:s,features:t}},e.clearSummary=function(){s=a=0,u={}},e}function UserFilter(e){var t={},a=e.allAttributesPrivate,s=e.privateAttributeNames||[],u={key:!0,custom:!0,anonymous:!0},c={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return t.filterUser=function(e){var t,o,n,r,i;return e?(t=e.privateAttributeNames||[],o=function(e){return!u[e]&&(a||-1!==t.indexOf(e)||-1!==s.indexOf(e))},n=(r=(i=function(n,r){return Object.keys(n).reduce(function(e,t){return r(t)&&(o(t)?e[1][t]=!0:e[0][t]=n[t]),e},[{},{}])})(e,function(e){return c[e]}))[0],r=r[1],e.custom&&(i=i(e.custom,function(){return 1}),n.custom=i[0],r=extend({},r,i[1])),(e=Object.keys(r)).length&&(e.sort(),n.privateAttrs=e),n):null},t}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=appendUrlPath(t.eventsUrl,"/events/bulk/"+n),c=EventSummarizer(),l=UserFilter(t),d=t.inlineUsersInEvents,f=t.samplingInterval,v=t.eventCapacity,g=t.flushInterval,p=t.logger,m=[],y=0,h=!1,b=!1;function E(){return 0===f||0===Math.floor(Math.random()*f)}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){var t,n,r;h||(t=r=!1,c.summarizeEvent(e),"feature"===e.kind?E()&&(r=!!e.trackEvents,t=!!(n=e).debugEventsUntilDate&&(n.debugEventsUntilDate>y&&n.debugEventsUntilDate>(new Date).getTime())):r=E(),r&&k((r=extend({},n=e),"alias"!==n.kind&&(d||"identify"===n.kind?r.user=l.filterUser(n.user):(r.userKey=n.user.key,delete r.user),"feature"===n.kind&&(delete r.trackEvents,delete r.debugEventsUntilDate)),r)),t&&((r=extend({},e,{kind:"debug"})).user=l.filterUser(r.user),delete r.trackEvents,delete r.debugEventsUntilDate,k(r)))},a.flush=function(){var e,t;return h||(e=m,t=c.getSummary(),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=o[e].slice(0),n=0;n<t.length;n++)t[n].handler.apply(t[n].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(o)},e.getEventListenerCount=function(e){return o[e]?o[e].length:0},e.maybeReportError=function(e){e&&(o["error"]?this.emit("error",e):(t||console).error(e.message))},e}var readyEvent="ready",successEvent="initialized",failureEvent="failed";function InitializationStateTracker(o){var t=!1,n=!1,r=null,e=null,i=new Promise(function(t){o.on(readyEvent,function e(){o.off(readyEvent,e),t()})}).catch(function(){});return{getInitializationPromise:function(){if(!e){if(t)return Promise.resolve();if(n)return Promise.reject(r);e=new Promise(function(t,n){function r(e){o.off(failureEvent,r),n(e)}o.on(successEvent,function e(){o.off(successEvent,e),t()}),o.on(failureEvent,r)})}return e},getReadyPromise:function(){return i},signalSuccess:function(){t||n||(t=!0,o.emit(successEvent),o.emit(readyEvent))},signalFailure:function(e){t||n||(n=!0,r=e,o.emit(failureEvent,e),o.emit(readyEvent)),o.maybeReportError(e)}}}var InitializationState=InitializationStateTracker;function PersistentFlagStore(t,n,r,o){var i={};function a(){var e="",t=o.getUser();return t&&(e=r||btoa(JSON.stringify(t))),"ld:"+n+":"+e}return i.loadFlags=function(){return t.get(a()).then(function(e){if(null==e)return null;try{var t,n=JSON.parse(e);return n&&(void 0===(t=n.$schema)||t<1?n=transformValuesToVersionedValues(n):delete n.$schema),n}catch(e){return i.clearFlags().then(function(){return null})}})},i.saveFlags=function(e){e=extend({},e,{$schema:1});return t.set(a(),JSON.stringify(e))},i.clearFlags=function(){return t.clear(a())},i}function PersistentStorage(r,t){function o(e){n||(n=!0,t.warn(localStorageUnavailable(e)))}var e={},n=!1;return e.isEnabled=function(){return!!r},e.get=function(e){return new Promise(function(t){r?r.get(e).then(t).catch(function(e){o(e),t(void 0)}):t(void 0)})},e.set=function(e,n){return new Promise(function(t){r?r.set(e,n).then(function(){return t(!0)}).catch(function(e){o(e),t(!1)}):t(!1)})},e.clear=function(e){return new Promise(function(t){r?r.clear(e).then(function(){return t(!0)}).catch(function(e){o(e),t(!1)}):t(!1)})},e}var streamReadTimeoutMillis=3e5;function Stream(o,i,a,t){var s,u=i.streamUrl,c=i.logger,e={},l=appendUrlPath(u,"/eval/"+a),d=i.useReport,f=i.evaluationReasons,n=i.streamReconnectDelay,v=getLDHeaders(o,i),g=!1,p=null,m=null,y=null,h=null,b=null;function E(e){g||(c.warn(streamError(e,n)),g=!0),S(!1),D(),k(n)}function k(e){m||(e?m=setTimeout(r,e):r())}function r(){m=null;var e,t="",n={headers:v,readTimeoutMillis:streamReadTimeoutMillis};if(o.eventSourceFactory){for(var r in null!=h&&(t="h="+h),d?o.eventSourceAllowsReport?(e=l,n.method="REPORT",n.headers["Content-Type"]="application/json",n.body=JSON.stringify(y)):(e=appendUrlPath(u,"/ping/"+a),t=""):e=l+"/"+base64URLEncode(JSON.stringify(y)),n.headers=transformHeaders(n.headers,i),e=e+((t=f?t+(t?"&":"")+"withReasons=true":t)?"?":"")+t,D(),c.info(streamConnecting(e)),s=(new Date).getTime(),p=o.eventSourceFactory(e,n),b)objectHasOwnProperty(b,r)&&p.addEventListener(r,b[r]);p.onerror=E}}function D(){p&&(c.info(streamClosing()),p.close(),p=null)}function S(e){s&&t&&t.recordStreamInit(s,!e,(new Date).getTime()-s),s=null}return e.connect=function(e,t,n){y=e,h=t,b={};for(var r in n||{})!function(t){b[t]=function(e){S(!(g=!1)),n[t]&&n[t](e)}}(r);k()},e.disconnect=function(){clearTimeout(m),m=null,D()},e.isConnected=function(){return!!(p&&o.eventSourceIsActive&&o.eventSourceIsActive(p))},e}function promiseCoalescer(n){var r,o,i,a,e={addPromise:function(t,e){r=t,o&&o(),o=e,t.then(function(e){r===t&&(i(e),n&&n())},function(e){r===t&&(a(e),n&&n())})}};return e.resultPromise=new Promise(function(e,t){i=e,a=t}),e}var jsonContentType="application/json";function getResponseError(e){return 404===e.status?new LDInvalidEnvironmentIdError(environmentNotFound()):new LDFlagFetchError(errorFetchingFlags(e.statusText||String(e.status)))}function Requestor(a,s,i){var u=s.baseUrl,c=s.useReport,l=s.evaluationReasons,d=s.logger,e={},f={};function v(e,t){var n,r,o,i;return a.httpRequest?(i=t?"REPORT":"GET",n=getLDHeaders(a,s),t&&(n["Content-Type"]=jsonContentType),(r=f[e])||(r=promiseCoalescer(function(){delete f[e]}),f[e]=r),i=(o=a.httpRequest(i,e,transformHeaders(n,s),t)).promise.then(function(e){var t;return 200===e.status?e.header("content-type")&&e.header("content-type").substring(0,jsonContentType.length)===jsonContentType?JSON.parse(e.body):(t=invalidContentType(e.header("content-type")||""),Promise.reject(new LDFlagFetchError(t))):Promise.reject(getResponseError(e))},function(e){return Promise.reject(new LDFlagFetchError(networkError(e)))}),r.addPromise(i,function(){o.cancel&&o.cancel()}),r.resultPromise):new Promise(function(e,t){t(new LDFlagFetchError(httpUnavailable()))})}return e.fetchJSON=function(e){return v(appendUrlPath(u,e),null)},e.fetchFlagSettings=function(e,t){var n,r,o="";return c?(n=[u,"/sdk/evalx/",i,"/user"].join(""),r=JSON.stringify(e)):(e=base64URLEncode(JSON.stringify(e)),n=[u,"/sdk/evalx/",i,"/users/",e].join("")),t&&(o="h="+t),d.debug(debugPolling(n=n+((o=l?o+(o?"&":"")+"withReasons=true":o)?"?":"")+o)),v(n,r)},e}function Identity(e,n){var r,t={setUser:function(e){var t=r&&clone(r);(r=sanitizeUser(e))&&n&&n(clone(r),t)},getUser:function(){return r?clone(r):null}};return e&&t.setUser(e),t}var ldUserIdKey="ld:$anonUserId";function UserValidator(n){var e={};return e.validateUser=function(e){var t;return e?null!==(t=clone(e)).key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?n.get(ldUserIdKey).then(function(e){return e?(t.key=e,t):(e=v1_1(),t.key=e,n.set(ldUserIdKey,e).then(function(){return t}))}):Promise.reject(new LDInvalidUserError(invalidUser())):Promise.reject(new LDInvalidUserError(userNotSpecified()))},e}var baseOptionDefs$1=configuration.baseOptionDefs,appendUrlPath$1=utils.appendUrlPath;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){o.push({timestamp:e,failed:t,durationMillis:n})},reset:i}}function DiagnosticsManager(t,r,e,n,o,i,a){var s,u,c=!!t.diagnosticUseCombinedEvent,l="ld:"+o+":$diagnostics",d=appendUrlPath$1(i.eventsUrl,"/events/diagnostic/"+o),f=i.diagnosticRecordingInterval,v=e,g=!!i.streaming,o={};function p(){return{sdk:function(){var e=_objectSpread2({},t.diagnosticSdkData);i.wrapperName&&(e.wrapperName=i.wrapperName);i.wrapperVersion&&(e.wrapperVersion=i.wrapperVersion);return e}(),configuration:{customBaseURI:i.baseUrl!==baseOptionDefs$1.baseUrl.default,customStreamURI:i.streamUrl!==baseOptionDefs$1.streamUrl.default,customEventsURI:i.eventsUrl!==baseOptionDefs$1.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!g,allAttributesPrivate:!!i.allAttributesPrivate,inlineUsersInEvents:!!i.inlineUsersInEvents,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation,autoAliasingOptOut:!!i.autoAliasingOptOut},platform:t.diagnosticPlatformData}}function m(e){i.logger&&i.logger.debug(messages.debugPostingDiagnosticEvent(e)),n.sendEvents(e,d,!0).then(function(){}).catch(function(){})}function y(){var e,t;m((t=(new Date).getTime(),e=_objectSpread2({kind:c?"diagnostic-combined":"diagnostic",id:a,creationDate:t},v.getProps()),c&&(e=_objectSpread2(_objectSpread2({},e),p())),v.reset(t),e)),u=setTimeout(y,f),s=(new Date).getTime(),c&&r.isEnabled()&&(t=_objectSpread2({},v.getProps()),r.set(l,JSON.stringify(t)))}return o.start=function(){var n;c?(n=function(e){var t;e?(e=(s||0)+f)<=(t=(new Date).getTime())?y():u=setTimeout(y,e-t):0===Math.floor(4*Math.random())?y():u=setTimeout(y,f)},r.isEnabled()?r.get(l).then(function(e){if(e)try{var t=JSON.parse(e);v.setProps(t),s=t.dataSinceDate}catch(e){}n(!0)}).catch(function(){n(!1)}):n(!1)):(m(_objectSpread2({kind:"diagnostic-init",id:a,creationDate:v.getProps().dataSinceDate},p())),u=setTimeout(y,f))},o.stop=function(){u&&clearTimeout(u)},o.setStreaming=function(e){g=e},o}var diagnosticEvents={DiagnosticId:DiagnosticId,DiagnosticsAccumulator:DiagnosticsAccumulator,DiagnosticsManager:DiagnosticsManager},diagnosticEvents_1=diagnosticEvents.DiagnosticId,diagnosticEvents_2=diagnosticEvents.DiagnosticsAccumulator,diagnosticEvents_3=diagnosticEvents.DiagnosticsManager,changeEvent="change",internalChangeEvent="internal-change";function initialize(A,x,e,o,t){var n,i,r,a,N,s,u,c=function(){if(e&&e.logger)return e.logger;return t&&t.logger&&t.logger.default||createConsoleLogger("warn")}(),l=EventEmitter(c),d=InitializationState(l),f=validate(e,l,t,c),v=f.sendEvents,g=A,p=f.hash,m=PersistentStorage(o.localStorage,c),V=EventSender(o,g,f),y=f.sendEvents&&!f.diagnosticOptOut,h=y?diagnosticEvents_1(g):null,b=y?diagnosticEvents_2((new Date).getTime()):null,E=y?diagnosticEvents_3(o,m,b,V,g,f,h):null,q=Stream(o,f,g,b),k=f.eventProcessor||EventProcessor(o,f,g,b,l,V),D=Requestor(o,f,g),S={},w=f.streaming,M=!1,P=!1,U=!0,T=f.stateProvider,L=Identity(null,function(e,t){(function(e){T||e&&I({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})})(e),!f.autoAliasingOptOut&&t&&t.anonymous&&e&&!e.anonymous&&K(e,t)}),H=UserValidator(m),O=m.isEnabled()?new PersistentFlagStore(m,g,p,L,c):null;function I(e){if(g&&!(T&&T.enqueueEvent&&T.enqueueEvent(e))){if("alias"!==e.kind){if(!e.user)return void(U&&(c.warn(eventWithoutUser()),U=!1));U=!1}!v||P||o.isDoNotTrack()||(c.debug(debugEnqueueingEvent(e.kind)),k.enqueue(e))}}function z(e,t,n,r){var o=L.getUser(),i=new Date,n={kind:"feature",key:e,user:o,value:t?t.value:null,variation:t?t.variationIndex:null,default:n,creationDate:i.getTime()},i=(o&&o.anonymous&&(n.contextKind=j(o)),S[e]);i&&(n.version=i.flagVersion||i.version,n.trackEvents=i.trackEvents,n.debugEventsUntilDate=i.debugEventsUntilDate),(r||i&&i.trackReason)&&t&&(n.reason=t.reason),I(n)}function C(e,t,n,r){var o,i;return S&&objectHasOwnProperty(S,e)&&S[e]&&!S[e].deleted?(i=_(o=S[e]),null!==o.value&&void 0!==o.value||(i.value=t)):i={value:t,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}},n&&z(e,i,t,r),i}function _(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function j(e){return e.anonymous?"anonymousUser":"user"}function K(e,t){T||e&&t&&I({kind:"alias",key:e.key,contextKind:j(e),previousKey:t.key,previousContextKind:j(t),creationDate:(new Date).getTime()})}function B(){var o;i=!0,L.getUser()&&(o=function(e){try{return JSON.parse(e)}catch(e){l.maybeReportError(new LDInvalidDataError(invalidData()))}},q.connect(L.getUser(),p,{ping:function(){c.debug(debugStreamPing());var t=L.getUser();D.fetchFlagSettings(t,p).then(function(e){deepEquals(t,L.getUser())&&F(e||{})}).catch(function(e){l.maybeReportError(new LDFlagFetchError(errorFetchingFlags(e)))})},put:function(e){e=o(e.data);e&&(c.debug(debugStreamPut()),F(e))},patch:function(e){var t,n,r,e=o(e.data);e&&(!(t=S[e.key])||!t.version||!e.version||t.version<e.version?(c.debug(debugStreamPatch(e.key)),n={},delete(r=extend({},e)).key,r=_(S[e.key]=r),n[e.key]=t?{previous:t.value,current:r}:{current:r},J(n)):c.debug(debugStreamPatchIgnored(e.key)))},delete:function(e){var t,e=o(e.data);e&&(!S[e.key]||S[e.key].version<e.version?(c.debug(debugStreamDelete(e.key)),t={},S[e.key]&&!S[e.key].deleted&&(t[e.key]={previous:S[e.key].value}),S[e.key]={version:e.version,deleted:!0},J(t)):c.debug(debugStreamDeleteIgnored(e.key)))}}))}function $(){i&&(q.disconnect(),i=!1)}function F(e){var t,n,r={};if(!e)return Promise.resolve();for(t in S)objectHasOwnProperty(S,t)&&S[t]&&(e[t]&&!deepEquals(e[t].value,S[t].value)?r[t]={previous:S[t].value,current:_(e[t])}:e[t]&&!e[t].deleted||(r[t]={previous:S[t].value}));for(n in e)objectHasOwnProperty(e,n)&&e[n]&&(!S[n]||S[n].deleted)&&(r[n]={current:_(e[n])});return S=_objectSpread2({},e),J(r).catch(function(){})}function J(o){var i,e=Object.keys(o);return 0<e.length&&(i={},e.forEach(function(e){var t=o[e].current,n=t?t.value:void 0,r=o[e].previous;l.emit(changeEvent+":"+e,n,r),i[e]=t?{current:n,previous:r}:{previous:r}}),l.emit(changeEvent,i),l.emit(internalChangeEvent,S),f.sendEventsOnlyForVariation||T||e.forEach(function(e){z(e,o[e].current)})),n&&O?O.saveFlags(S):Promise.resolve()}function W(){var e=w||r&&void 0===w;e&&!i?B():!e&&i&&$(),E&&E.setStreaming(e)}function G(e){return e===changeEvent||e.substr(0,changeEvent.length+1)===changeEvent+":"}function X(e){g=e.environment,L.setUser(e.user),S=_objectSpread2({},e.flags),onNextTick(R)}function R(){c.info(clientInitialized()),M=!0,W(),d.signalSuccess()}function Q(e){d.signalFailure(e)}return"string"==typeof f.bootstrap&&"LOCALSTORAGE"===f.bootstrap.toUpperCase()&&(O?n=!0:c.warn(localStorageUnavailable())),"object"===_typeof(f.bootstrap)&&(a=f.bootstrap,y=Object.keys(a),!(s=a[N="$flagsState"])&&y.length&&c.warn(bootstrapOldFormat()),!1===a.$valid&&c.warn(bootstrapInvalid()),u={},y.forEach(function(e){var t;e!==N&&"$valid"!==e&&(t={value:a[e]},s&&s[e]?t=extend(t,s[e]):t.version=0,u[e]=t)}),S=u),T?((h=T.getInitialState())?X(h):T.on("init",X),T.on("update",function(e){e.user&&L.setUser(e.user);e.flags&&F(e.flags)})):(A?H.validateUser(x).then(function(e){return L.setUser(e),"object"===_typeof(f.bootstrap)?R():n?O.loadFlags().then(function(e){return null==e?(S={},D.fetchFlagSettings(L.getUser(),p).then(function(e){return F(e||{})}).then(R).catch(function(e){Q(new LDFlagFetchError(errorFetchingFlags(e)))})):(S=e,onNextTick(R),D.fetchFlagSettings(L.getUser(),p).then(F).catch(function(e){return l.maybeReportError(e)}))}):D.fetchFlagSettings(L.getUser(),p).then(function(e){S=e||{},R()}).catch(function(e){S={},Q(e)})}):Promise.reject(new LDInvalidEnvironmentIdError(environmentNotSpecified()))).catch(Q),{client:{waitForInitialization:function(){return d.getInitializationPromise()},waitUntilReady:function(){return d.getReadyPromise()},identify:function(e,r,t){return P?wrapPromiseCallback(Promise.resolve({}),t):T?(c.warn(identifyDisabled()),wrapPromiseCallback(Promise.resolve(transformVersionedValuesToValues(S)),t)):wrapPromiseCallback((n&&O?O.clearFlags():Promise.resolve()).then(function(){return H.validateUser(e)}).then(function(n){return D.fetchFlagSettings(n,r).then(function(e){var t=transformVersionedValuesToValues(e);return L.setUser(n),p=r,e?F(e).then(function(){return t}):t})}).then(function(e){return i&&B(),e}).catch(function(e){return l.maybeReportError(e),Promise.reject(e)}),t)},getUser:function(){return L.getUser()},variation:function(e,t){return C(e,t,!0,!1).value},variationDetail:function(e,t){return C(e,t,!0,!0)},track:function(e,t,n){var r;"string"!=typeof e?l.maybeReportError(new LDInvalidEventKeyError(unknownCustomEventKey(e))):(o.customEventFilter&&!o.customEventFilter(e)&&c.warn(unknownCustomEventKey(e)),r={kind:"custom",key:e,user:e=L.getUser(),url:o.getCurrentUrl(),creationDate:(new Date).getTime()},e&&e.anonymous&&(r.contextKind=j(e)),null!=t&&(r.data=t),null!=n&&(r.metricValue=n),I(r))},alias:K,on:function(e,t,n){G(e)?(r=!0,M&&W(),l.on(e,t,n)):l.on.apply(l,arguments)},off:function(e){var t;l.off.apply(l,arguments),G(e)&&(t=!1,l.getEvents().forEach(function(e){G(e)&&0<l.getEventListenerCount(e)&&(t=!0)}),t||(r=!1,i&&void 0===w&&$()))},setStreaming:function(e){(e=null===e?void 0:e)!==w&&(w=e,W())},flush:function(e){return wrapPromiseCallback(v?k.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(S)for(var t in S)objectHasOwnProperty(S,t)&&!S[t].deleted&&(e[t]=C(t,null,!f.sendEventsOnlyForVariation).value);return e},close:function(e){var t;return P?wrapPromiseCallback(Promise.resolve(),e):(t=function(){P=!0,S={}},wrapPromiseCallback(Promise.resolve().then(function(){if($(),E&&E.stop(),v)return k.stop(),k.flush()}).then(t).catch(t),e))}},options:f,emitter:l,ident:L,logger:c,requestor:D,start:function(){v&&(E&&E.start(),k.start())},enqueueEvent:I,getFlagsInternal:function(){return S},getEnvironmentId:function(){return g},internalChangeEventName:internalChangeEvent}}var version="3.7.0";exports.commonBasicLogger=commonBasicLogger,exports.createConsoleLogger=createConsoleLogger,exports.errors=errors,exports.initialize=initialize,exports.messages=messages,exports.utils=utils,exports.version=version;
|
|
2
2
|
//# sourceMappingURL=ldclient-common.cjs.js.map
|