launchdarkly-js-sdk-common 3.2.7 → 3.2.10
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 +12 -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 -2
- package/typings.d.ts +6 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!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 G(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 P=t("LaunchDarklyUnexpectedResponseError"),X=t("LaunchDarklyInvalidEnvironmentIdError"),o=t("LaunchDarklyInvalidUserError"),W=t("LaunchDarklyInvalidEventKeyError"),d=t("LaunchDarklyInvalidArgumentError"),Q=t("LaunchDarklyFlagFetchError");function O(e){return!(400<=e&&e<500)||(400===e||408===e||429===e)}for(var r=Object.freeze({__proto__:null,LDUnexpectedResponseError:P,LDInvalidEnvironmentIdError:X,LDInvalidUserError:o,LDInvalidEventKeyError:W,LDInvalidArgumentError:d,LDFlagFetchError:Q,isHttpErrorRecoverable:O}),i=function(e){for(var n,t=e.length,r=t%3,i=[],o=0,a=t-r;o<a;o+=16383)i.push(f(e,o,a<o+16383?a:o+16383));1==r?(n=e[t-1],i.push(u[n>>2]+u[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],i.push(u[n>>10]+u[n>>4&63]+u[n<<2&63]+"="));return i.join("")},u=[],a=[],s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=0,l=s.length;c<l;++c)u[c]=s[c],a[s.charCodeAt(c)]=c;function f(e,n,t){for(var r,i,o=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(u[(i=r)>>18&63]+u[i>>12&63]+u[i>>6&63]+u[63&i]);return o.join("")}a["-".charCodeAt(0)]=62,a["_".charCodeAt(0)]=63;var g=Array.isArray,m=Object.keys,p=Object.prototype.hasOwnProperty,v=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,i,o,a=g(n),u=g(t);if(a&&u){if((i=n.length)!=t.length)return!1;for(r=i;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=m(n);if((i=v.length)!==m(t).length)return!1;for(r=i;0!=r--;)if(!p.call(t,v[r]))return!1;for(r=i;0!=r--;)if(!e(n[o=v[r]],t[o]))return!1;return!0}return n!=n&&t!=t},h=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function y(e){var n=unescape(encodeURIComponent(e));return i(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function S(e){return y(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Y(e){return JSON.parse(JSON.stringify(e))}function Z(e,n){return v(e,n)}function ee(e){setTimeout(e,0)}function ne(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function b(e){var n={};for(var t in e)ie(e,t)&&(n[t]={value:e[t],version:0});return n}function te(e){var n={};for(var t in e)ie(e,t)&&(n[t]=e[t].value);return n}function k(e,n){for(var t,r=n.slice(0),i=[],o=e;0<r.length;){for(t=[];0<o;){var a=r.shift();if(!a)break;(o-=S(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}o=e,i.push(t)}return i}function E(e){var n=e.version||"3.2.7";return e.userAgent+"/"+n}function U(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":E(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function re(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return G({},e,{},n)},{})}function ie(e,n){return Object.prototype.hasOwnProperty.call(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||G({},e))[r]=String(i))}return n||e}var w=Object.freeze({__proto__:null,btoa:y,base64URLEncode:S,clone:Y,deepEquals:Z,onNextTick:ee,wrapPromiseCallback:ne,transformValuesToVersionedValues:b,transformVersionedValuesToValues:te,chunkUserEventsForUrl:k,getLDUserAgentString:E,getLDHeaders:U,extend:re,objectHasOwnProperty:ie,sanitizeUser:oe});for(var D,I=(function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}(D={exports:{}},D.exports),D.exports),j=[],R=0;R<256;++R)j[R]=(R+256).toString(16).substr(1);var T,N,F=function(e,n){var t=n||0,r=j;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},C=0,L=0;var A=function(e,n,t){var r=n&&t||0,i=n||[],o=(e=e||{}).node||T,a=void 0!==e.clockseq?e.clockseq:N;if(null==o||null==a){var u=I();null==o&&(o=T=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=N=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:L+1,l=s-C+(c-L)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||C<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");C=s,N=a;var f=(1e4*(268435455&(s+=122192928e5))+(L=c))%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var v=s/4294967296*1e4&268435455;i[r++]=v>>>8&255,i[r++]=255&v,i[r++]=v>>>24&15|16,i[r++]=v>>>16&255,i[r++]=a>>>8|128,i[r++]=255&a;for(var d=0;d<6;++d)i[r+d]=o[d];return n||F(i)},x=2e3;function ae(u,e,n){var t="/a/"+e+".gif",s=re({"Content-Type":"application/json"},U(u,n)),c=u.httpFallbackPing,l={};return l.sendChunk=function(e,r,i,n){var o=JSON.stringify(e),a=i?null:A();return n?function n(t){var e=i?s:re({},s,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return u.httpRequest("POST",r,e,o).promise.then(function(e){if(e)return 400<=e.status&&O(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)}).catch(function(){return t?n(!1):Promise.reject()})}(!0).catch(function(){}):(c&&c(r+t+"?d="+S(o)),Promise.resolve())},l.sendEvents=function(e,n,t){if(!u.httpRequest)return Promise.resolve();var r,i=u.httpAllowsPost();r=i?[e]:k(x-n.length,e);for(var o=[],a=0;a<r.length;a++)o.push(l.sendChunk(r[a],n,t,i));return Promise.all(o)},l}function _(e){var n={},s=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(r,i){return Object.keys(r).reduce(function(e,n){var t=e;return i(n)&&(!function(e){return!l[e]&&(s||-1!==o.indexOf(e)||-1!==c.indexOf(e))}(n)?t[0][n]=r[n]:t[1][n]=!0),t},[{},{}])}var o=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],i=t[1];if(e.custom){var a=n(e.custom,function(){return!0});r.custom=a[0],i=re({},i,a[1])}var u=Object.keys(i);return u.length&&(u.sort(),r.privateAttrs=u),r},n}function V(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}function q(){return"LaunchDarkly client initialized"}function J(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"}function ue(e){return'Custom event "'+e+'" does not exist'}function se(){return"No environment/client-side ID was specified."+$}function ce(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+$}function z(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."}function M(){return"identify() has no effect here; it must be called on the main client instance"}function B(){return"received ping message from stream"}function K(){return"received streaming update for all flags"}function le(e){return'received streaming update for flag "'+e+'"'}function fe(e){return'received streaming update for flag "'+e+'" but ignored due to version check'}function ve(e){return'received streaming deletion for flag "'+e+'"'}function de(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'}function ge(e){return'enqueueing "'+e+'" event'}var $=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",me=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},pe=function(e){return'Expected application/json content type but got "'+e+'"'},he=function(){return"localStorage is unavailable"},ye=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},be=function(e){return"network error"+(e?" ("+e+")":"")},ke=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+$},Ee=function(e){return"Error fetching flag settings: "+V(e)},we=function(){return"No user specified."+$},De=function(){return"Invalid user specified."+$},Se=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},Pe=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(O(e)?t:"giving up permanently")},Oe=function(){return"Cannot make HTTP requests in this environment."+$},Ue=function(){return"Closing stream connection"},Ie=function(e){return"Opening stream connection to "+e},je=function(e,n){return"Error on stream connection: "+V(e)+", will continue retrying every "+n+" milliseconds."},Re=function(e){return'Ignoring unknown config option "'+e+'"'},Te=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},Ne=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},Fe=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Ce=function(e){return"polling for feature flags at "+e},Le=function(e){return"sending "+e+" events"},Ae=Object.freeze({__proto__:null,clientInitialized:q,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:me,eventWithoutUser:J,invalidContentType:pe,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:he,localStorageUnavailableForUserId:ye,networkError:be,unknownCustomEventKey:ue,environmentNotFound:ke,environmentNotSpecified:se,errorFetchingFlags:Ee,userNotSpecified:we,invalidUser:De,bootstrapOldFormat:ce,bootstrapInvalid:z,deprecated:Se,httpErrorMessage:Pe,httpUnavailable:Oe,identifyDisabled:M,streamClosing:Ue,streamConnecting:Ie,streamError:je,unknownOption:Re,wrongOptionType:Te,wrongOptionTypeBoolean:Ne,optionBelowMinimum:Fe,debugPolling:Ce,debugStreamPing:B,debugStreamPut:K,debugStreamPatch:le,debugStreamPatchIgnored:fe,debugStreamDelete:ve,debugStreamDeleteIgnored:de,debugEnqueueingEvent:ge,debugPostingEvents:Le,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"}});function xe(e,n,t,r,i,o){var a,u=3<arguments.length&&void 0!==r?r:null,s=4<arguments.length&&void 0!==i?i:null,c={},l=(5<arguments.length&&void 0!==o?o:null)||ae(e,t,n),f=n.eventsUrl+"/events/bulk/"+t,v=function(){var e={},a=0,u=0,s={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=s[n];t?t.count=t.count+1:s[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>u&&(u=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in s){var r=s[t],i=e[r.key];i||(i={default:r.default,counters:[]},e[r.key]=i);var o={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(o.variation=r.variation),r.version?o.version=r.version:o.unknown=!0,i.counters.push(o),n=!1}return n?null:{startDate:a,endDate:u,features:e}},e.clearSummary=function(){u=a=0,s={}},e}(),d=_(n),g=n.inlineUsersInEvents,m=n.samplingInterval,p=n.eventCapacity,h=n.flushInterval,y=n.logger,b=[],k=0,E=!1,w=!1;function D(){return 0===m||0===Math.floor(Math.random()*m)}function S(e){b.length<p?(b.push(e),w=!1):(w||(w=!0,y.warn(me())),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=re({},e);return g||"identify"===e.kind?n.user=d.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),t){var r=re({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,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(Le(e.length)),l.sendEvents(e,f).then(function(e){e&&(e.serverTime&&(k=e.serverTime),O(e.status)||(E=!0),400<=e.status&&ee(function(){s.maybeReportError(new P(Pe(e.status,"event posting","some events were dropped")))}))}))},c.start=function(){a=setTimeout(function e(){c.flush(),a=setTimeout(e,h)},h)},c.stop=function(){clearTimeout(a)},c}function _e(n){var e={},i={};return e.on=function(e,n,t){i[e]=i[e]||[],i[e]=i[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(i[e])for(var r=0;r<i[e].length;r++)i[e][r].handler===n&&i[e][r].context===t&&(i[e]=i[e].slice(0,r).concat(i[e].slice(r+1)))},e.emit=function(e){if(i[e])for(var n=i[e].slice(0),t=0;t<n.length;t++)n[t].handler.apply(n[t].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(i)},e.getEventListenerCount=function(e){return i[e]?i[e].length:0},e.maybeReportError=function(e){e&&(!function(e){return!!i[e]}("error")?(n||console).error(e.message):this.emit("error",e))},e}var Ve="ready",qe="initialized",Je="failed";var ze=function(r){var n=!1,t=!1,i=null,e=null,o=new Promise(function(n){r.on(Ve,function e(){r.off(Ve,e),n()})}).catch(function(){});return{getInitializationPromise:function(){return e||(n?Promise.resolve():t?Promise.reject(i):e=new Promise(function(n,t){r.on(qe,function e(){r.off(qe,e),n()}),r.on(Je,function e(n){r.off(Je,e),t(n)})}))},getReadyPromise:function(){return o},signalSuccess:function(){n||t||(n=!0,r.emit(qe),r.emit(Ve))},signalFailure:function(e){n||t||(t=!0,i=e,r.emit(Je,e),r.emit(Ve)),r.maybeReportError(e)}}};function Me(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(he()),Promise.reject(e)})},u.saveFlags=function(e){var n=re({},e,{$schema:1});return t.set(s(),JSON.stringify(n)).catch(function(e){return a.warn(he()),Promise.reject(e)})},u.clearFlags=function(){return t.clear(s()).catch(function(e){return a.warn(he()),Promise.reject(e)})},u}function Be(i,e,o,n){var a,u=e.streamUrl,s=e.logger,t={},c=u+"/eval/"+o,l=e.useReport,f=e.evaluationReasons,r=e.streamReconnectDelay,v=U(i,e),d=!1,g=null,m=null,p=null,h=null,y=null;function b(e){d||(s.warn(je(e,r)),d=!0),D(!1),w(),k(r)}function k(e){m||(e?m=setTimeout(E,e):E())}function E(){var e;m=null;var n="",t={headers:v};if(i.eventSourceFactory){for(var r in null!=h&&(n="h="+h),l?i.eventSourceAllowsReport?(e=c,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(p)):(e=u+"/ping/"+o,n=""):e=c+"/"+S(JSON.stringify(p)),f&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,w(),s.info(Ie(e)),a=(new Date).getTime(),g=i.eventSourceFactory(e,t),y)ie(y,r)&&g.addEventListener(r,y[r]);g.onerror=b}}function w(){g&&(s.info(Ue()),g.close(),g=null)}function D(e){a&&n&&n.recordStreamInit(a,!e,(new Date).getTime()-a),a=null}return t.connect=function(e,n,t){p=e,h=n,y={};function r(n){y[n]=function(e){D(!(d=!1)),t[n]&&t[n](e)}}for(var i in t||{})r(i);k()},t.disconnect=function(){clearTimeout(m),m=null,w()},t.isConnected=function(){return!!(g&&i.eventSourceIsActive&&i.eventSourceIsActive(g))},t}var Ke="application/json";function $e(u,s,a){var c=s.baseUrl,l=s.useReport,f=s.evaluationReasons,v=s.logger,e={},d={};function g(e,n){if(!u.httpRequest)return new Promise(function(e,n){n(new Q(Oe()))});var t=n?"REPORT":"GET",r=U(u,s);n&&(r["Content-Type"]=Ke);var i=d[e];i||(i=function(t){var r,i,o,a,e={addPromise:function(n,e){r=n,i&&i(),i=e,n.then(function(e){r===n&&(o(e),t&&t())},function(e){r===n&&(a(e),t&&t())})}};return e.resultPromise=new Promise(function(e,n){o=e,a=n}),e}(function(){delete d[e]}),d[e]=i);var o=u.httpRequest(t,e,r,n),a=o.promise.then(function(e){if(200!==e.status)return Promise.reject(function(e){return 404===e.status?new X(ke()):new Q(Ee(e.statusText||String(e.status)))}(e));if(e.header("content-type")&&e.header("content-type").startsWith(Ke))return JSON.parse(e.body);var n=pe(e.header("content-type")||"");return Promise.reject(new Q(n))},function(e){return Promise.reject(new Q(be(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(Ce(r)),g(r,i)},e}var He="ld:$anonUserId";function Ge(r,i){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new o(we()));var t=Y(e);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?(r?r.get(He).catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return t.key=e,t;var n=A();return function(e){return r?r.set(He,e).catch(function(){i.warn(ye())}):Promise.resolve()}(t.key=n).then(function(){return t})}):Promise.reject(new o(De()))},e}var Xe={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},inlineUsersInEvents:{default:!1},allowFrequentDuplicateEvents:{default:!1},sendEventsOnlyForVariation:{default:!1},useReport:{default:!1},evaluationReasons:{default:!1},eventCapacity:{default:100,minimum:1},flushInterval:{default:2e3,minimum:2e3},samplingInterval:{default:0,minimum:0},streamReconnectDelay:{default:1e3,minimum:0},allAttributesPrivate:{default:!1},privateAttributeNames:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"}};function We(e,n,t,r){var a=re({logger:{default:r}},Xe,t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){ee(function(){n&&n.maybeReportError(new d(e))})}var o,s,c,l,f=re({},e||{});function v(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=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(Se(e,n)),n&&(void 0===o[n]&&(o[n]=o[e]),delete o[e])}}),s=re({},f),Object.keys(a).forEach(function(e){void 0!==s[e]&&null!==s[e]||(s[e]=a[e]&&a[e].default)}),l=re({},c=f=s),Object.keys(c).forEach(function(e){var n=c[e];if(null!=n){var t=a[e];if(void 0===t)u(Re(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(Ne(e,o))):(u(Te(e,r,o)),l[e]=t.default):"number"===o&&void 0!==t.minimum&&n<t.minimum&&(u(Fe(e,n,t.minimum)),l[e]=t.minimum)}}}}),f=l}var Qe=Object.freeze({__proto__:null,baseOptionDefs:Xe,validate:We}).baseOptionDefs;var Ye=function(e){var n={diagnosticId:A()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n},Ze=function(e){var n,t,r,i;function o(e){n=e,r=t=0,i=[]}return o(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:i}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,i=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};i.push(r)},reset:o}},en=function(n,e,t,r,i,o){var a,u,s=!!n.diagnosticUseCombinedEvent,c="ld:"+r+":$diagnostics",l=i.eventsUrl+"/events/diagnostic/"+r,f=i.diagnosticRecordingInterval,v=e,d=!!i.streaming,g={};function m(){return{sdk:function(){var e=G({},n.diagnosticSdkData);i.wrapperName&&(e.wrapperName=i.wrapperName);i.wrapperVersion&&(e.wrapperVersion=i.wrapperVersion);return e}(),configuration:{customBaseURI:i.baseUrl!==Qe.baseUrl.default,customStreamURI:i.streamUrl!==Qe.streamUrl.default,customEventsURI:i.eventsUrl!==Qe.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!d,allAttributesPrivate:!!i.allAttributesPrivate,inlineUsersInEvents:!!i.inlineUsersInEvents,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,allowFrequentDuplicateEvents:!!i.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation},platform:n.diagnosticPlatformData}}function p(e){i.logger&&i.logger.debug(Ae.debugPostingDiagnosticEvent(e)),t.sendEvents(e,l,!0).then(function(){}).catch(function(){})}function h(){p(function(){var e=(new Date).getTime(),n=G({kind:s?"diagnostic-combined":"diagnostic",id:o,creationDate:e},v.getProps());return s&&(n=G({},n,{},m())),v.reset(e),n}()),u=setTimeout(h,f),a=(new Date).getTime(),s&&function(){if(n.localStorage){var e=G({},v.getProps());n.localStorage.set(c,JSON.stringify(e),function(){})}}()}return g.start=function(){s?function(t){if(!n.localStorage)return t(!1);n.localStorage.get(c).then(function(e){if(e)try{var n=JSON.parse(e);v.setProps(n),a=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(a||0)+f,t=(new Date).getTime();n<=t?h():u=setTimeout(h,n-t)}else 0===Math.floor(4*Math.random())?h():u=setTimeout(h,f)}):(p(G({kind:"diagnostic-init",id:o,creationDate:v.getProps().dataSinceDate},m())),u=setTimeout(h,f))},g.stop=function(){u&&clearTimeout(u)},g.setStreaming=function(e){d=e},g};function nn(e,n){var o,a=["debug","info","warn","error"];o=null!=n?""===n?"":n+" ":"LD: ";var u=0;e&&(u="none"===e?100:a.indexOf(e));var t={};function r(e,n,t){if(u<=e&&console){var r=console[n];if(r){var i=e<a.length?a[e]:"?";r.call(console,o+"["+i+"] "+t)}}}return t.debug=function(e){return r(0,"log",e)},t.info=function(e){return r(1,"info",e)},t.warn=function(e){return r(2,"warn",e)},t.error=function(e){return r(3,"error",e)},t}var tn="change",rn="internal-change";e.createConsoleLogger=nn,e.errors=r,e.initialize=function(e,n,t,i,r){var a,o,u,s,c=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||nn("warn")}(),l=_e(c),f=ze(l),v=We(t,l,r,c),d=v.sendEvents,g=e,m=v.hash,p=ae(i,g,v),h=v.sendEvents&&!v.diagnosticOptOut,y=h?Ye(g):null,b=h?Ze((new Date).getTime()):null,k=h?en(i,b,p,g,v,y):null,E=Be(i,v,g,b),w=v.eventProcessor||xe(i,v,g,b,l,p),D=$e(i,v,g),S={},P={},O=v.streaming,U=!1,I=!1,j=!0,R=v.stateProvider,T=function(e,n){var t,r={};return r.setUser=function(e){(t=oe(e))&&n&&n(Y(t))},r.getUser=function(){return t?Y(t):null},e&&r.setUser(e),r}(null,function(e){if(R)return;e&&F({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),N=Ge(i.localStorage,c);function F(e){g&&(R&&R.enqueueEvent&&R.enqueueEvent(e)||(e.user?(j=!1,!d||I||i.isDoNotTrack()||(c.debug(ge(e.kind)),w.enqueue(e))):j&&(c.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"),j=!1)))}function C(e,n,t,r){var i=T.getUser(),o=new Date,a=n?n.value:null;if(!v.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(i&&i.key?i.key:"")+e,s=S[u];if(s&&o-s<3e5)return;S[u]=o}var c={kind:"feature",key:e,user:i,value:a,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime()},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 L(e,n,t,r){var i;if(P&&ie(P,e)&&P[e]&&!P[e].deleted){var o=P[e];i=A(o),null!==o.value&&void 0!==o.value||(i.value=n)}else i={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&C(e,i,n,r),i}function A(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function x(){o=!0,T.getUser()&&E.connect(T.getUser(),m,{ping:function(){c.debug("received ping message from stream"),D.fetchFlagSettings(T.getUser(),m).then(function(e){return V(e||{})}).catch(function(e){l.maybeReportError(new Q(Ee(e)))})},put:function(e){var n=JSON.parse(e.data);c.debug("received streaming update for all flags"),V(n)},patch:function(e){var n=JSON.parse(e.data),t=P[n.key];if(!t||!t.version||!n.version||t.version<n.version){c.debug(le(n.key));var r={},i=re({},n);delete i.key;var o=A(P[n.key]=i);r[n.key]=t?{previous:t.value,current:o}:{current:o},q(r)}else c.debug(fe(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!P[n.key]||P[n.key].version<n.version){c.debug(ve(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},q(t)}else c.debug(de(n.key))}})}function _(){o&&(E.disconnect(),o=!1)}function V(e){var n={};if(!e)return Promise.resolve();for(var t in P)ie(P,t)&&P[t]&&(e[t]&&!Z(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)ie(e,r)&&e[r]&&(!P[r]||P[r].deleted)&&(n[r]={current:A(e[r])});return P=G({},e),q(n).catch(function(){})}function q(i){var e=Object.keys(i);if(0<e.length){var o={};e.forEach(function(e){var n=i[e].current,t=n?n.value:void 0,r=i[e].previous;l.emit(tn+":"+e,t,r),o[e]=n?{current:t,previous:r}:{previous:r}}),l.emit(tn,o),l.emit(rn,P),v.sendEventsOnlyForVariation||R||e.forEach(function(e){C(e,i[e].current)})}return a&&s?s.saveFlags(P).catch(function(){return null}):Promise.resolve()}function J(){var e=O||u&&void 0===O;e&&!o?x():!e&&o&&_(),k&&k.setStreaming(e)}function z(e){return e===tn||e.substr(0,tn.length+1)===tn+":"}if(i.localStorage&&(s=new Me(i.localStorage,g,m,T,c)),"string"==typeof v.bootstrap&&"LOCALSTORAGE"===v.bootstrap.toUpperCase()&&(s?a=!0:c.warn(he())),"object"===H(v.bootstrap)&&(P=function(t){var e=Object.keys(t),r="$flagsState",i=t[r];!i&&e.length&&c.warn(ce()),!1===t.$valid&&c.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var o={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var n={value:t[e]};i&&i[e]?n=re(n,i[e]):n.version=0,o[e]=n}}),o}(v.bootstrap)),R){var M=R.getInitialState();M?B(M):R.on("init",B),R.on("update",function(e){e.user&&T.setUser(e.user);e.flags&&V(e.flags)})}else(e?N.validateUser(n).then(function(e){return T.setUser(e),"object"===H(v.bootstrap)?K():a?s.loadFlags().catch(function(){return null}).then(function(e){return null==e?(P={},D.fetchFlagSettings(T.getUser(),m).then(function(e){return V(e||{})}).then(K).catch(function(e){$(new Q(Ee(e)))})):(P=e,ee(K),D.fetchFlagSettings(T.getUser(),m).then(function(e){return V(e)}).catch(function(e){return l.maybeReportError(e)}))}):D.fetchFlagSettings(T.getUser(),m).then(function(e){P=e||{},K()}).catch(function(e){P={},$(e)})}):Promise.reject(new X(se()))).catch($);function B(e){g=e.environment,T.setUser(e.user),P=G({},e.flags),ee(K)}function K(){c.info("LaunchDarkly client initialized"),U=!0,J(),f.signalSuccess()}function $(e){f.signalFailure(e)}return{client:{waitForInitialization:function(){return f.getInitializationPromise()},waitUntilReady:function(){return f.getReadyPromise()},identify:function(e,r,n){return I?ne(Promise.resolve({}),n):R?(c.warn("identify() has no effect here; it must be called on the main client instance"),ne(Promise.resolve(te(P)),n)):ne((a&&s?s.clearFlags():Promise.resolve()).then(function(){return N.validateUser(e)}).then(function(t){return D.fetchFlagSettings(t,r).then(function(e){var n=te(e);return T.setUser(t),m=r,e?V(e).then(function(){return n}):n})}).then(function(e){return o&&x(),e}).catch(function(e){return l.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return T.getUser()},variation:function(e,n){return L(e,n,!0,!1).value},variationDetail:function(e,n){return L(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&c.warn(ue(e));var r={kind:"custom",key:e,user:T.getUser(),url:i.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),F(r)}else l.maybeReportError(new W(ue(e)))},on:function(e,n,t){z(e)?(u=!0,U&&J(),l.on(e,n,t)):l.on.apply(l,arguments)},off:function(e){if(l.off.apply(l,arguments),z(e)){var n=!1;l.getEvents().forEach(function(e){z(e)&&0<l.getEventListenerCount(e)&&(n=!0)}),n||(u=!1,o&&void 0===O&&_())}},setStreaming:function(e){var n=null===e?void 0:e;n!==O&&(O=n,J())},flush:function(e){return ne(d?w.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!P)return e;for(var n in P)ie(P,n)&&(e[n]=L(n,null,!v.sendEventsOnlyForVariation).value);return e},close:function(e){if(I)return ne(Promise.resolve(),e);function n(){I=!0,P={}}return ne(Promise.resolve().then(function(){if(_(),k&&k.stop(),d)return w.stop(),w.flush()}).then(n).catch(n),e)}},options:v,emitter:l,ident:T,logger:c,requestor:D,start:function(){d&&(k&&k.start(),w.start())},enqueueEvent:F,getFlagsInternal:function(){return P},getEnvironmentId:function(){return g},internalChangeEventName:rn}},e.messages=Ae,e.utils=w,e.version="3.2.7",Object.defineProperty(e,"__esModule",{value:!0})});
|
|
1
|
+
!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 G(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 P=t("LaunchDarklyUnexpectedResponseError"),X=t("LaunchDarklyInvalidEnvironmentIdError"),o=t("LaunchDarklyInvalidUserError"),W=t("LaunchDarklyInvalidEventKeyError"),d=t("LaunchDarklyInvalidArgumentError"),Q=t("LaunchDarklyFlagFetchError");function O(e){return!(400<=e&&e<500)||(400===e||408===e||429===e)}for(var r=Object.freeze({__proto__:null,LDUnexpectedResponseError:P,LDInvalidEnvironmentIdError:X,LDInvalidUserError:o,LDInvalidEventKeyError:W,LDInvalidArgumentError:d,LDFlagFetchError:Q,isHttpErrorRecoverable:O}),i=function(e){for(var n,t=e.length,r=t%3,i=[],o=0,a=t-r;o<a;o+=16383)i.push(f(e,o,a<o+16383?a:o+16383));1==r?(n=e[t-1],i.push(u[n>>2]+u[n<<4&63]+"==")):2==r&&(n=(e[t-2]<<8)+e[t-1],i.push(u[n>>10]+u[n>>4&63]+u[n<<2&63]+"="));return i.join("")},u=[],a=[],s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=0,l=s.length;c<l;++c)u[c]=s[c],a[s.charCodeAt(c)]=c;function f(e,n,t){for(var r,i,o=[],a=n;a<t;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),o.push(u[(i=r)>>18&63]+u[i>>12&63]+u[i>>6&63]+u[63&i]);return o.join("")}a["-".charCodeAt(0)]=62,a["_".charCodeAt(0)]=63;var g=Array.isArray,m=Object.keys,p=Object.prototype.hasOwnProperty,v=function e(n,t){if(n===t)return!0;if(n&&t&&"object"==typeof n&&"object"==typeof t){var r,i,o,a=g(n),u=g(t);if(a&&u){if((i=n.length)!=t.length)return!1;for(r=i;0!=r--;)if(!e(n[r],t[r]))return!1;return!0}if(a!=u)return!1;var s=n instanceof Date,c=t instanceof Date;if(s!=c)return!1;if(s&&c)return n.getTime()==t.getTime();var l=n instanceof RegExp,f=t instanceof RegExp;if(l!=f)return!1;if(l&&f)return n.toString()==t.toString();var v=m(n);if((i=v.length)!==m(t).length)return!1;for(r=i;0!=r--;)if(!p.call(t,v[r]))return!1;for(r=i;0!=r--;)if(!e(n[o=v[r]],t[o]))return!1;return!0}return n!=n&&t!=t},h=["key","secondary","ip","country","email","firstName","lastName","avatar","name"];function y(e){var n=unescape(encodeURIComponent(e));return i(function(e){for(var n=[],t=0;t<e.length;t++)n.push(e.charCodeAt(t));return n}(n))}function S(e){return y(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function Y(e){return JSON.parse(JSON.stringify(e))}function Z(e,n){return v(e,n)}function ee(e){setTimeout(e,0)}function ne(e,n){var t=e.then(function(e){return n&&setTimeout(function(){n(null,e)},0),e},function(e){if(!n)return Promise.reject(e);setTimeout(function(){n(e,null)},0)});return n?void 0:t}function b(e){var n={};for(var t in e)ie(e,t)&&(n[t]={value:e[t],version:0});return n}function te(e){var n={};for(var t in e)ie(e,t)&&(n[t]=e[t].value);return n}function k(e,n){for(var t,r=n.slice(0),i=[],o=e;0<r.length;){for(t=[];0<o;){var a=r.shift();if(!a)break;(o-=S(JSON.stringify(a)).length)<0&&0<t.length?r.unshift(a):t.push(a)}o=e,i.push(t)}return i}function E(e){var n=e.version||"3.2.10";return e.userAgent+"/"+n}function U(e,n){if(n&&!n.sendLDHeaders)return{};var t={"X-LaunchDarkly-User-Agent":E(e)};return n&&n.wrapperName&&(t["X-LaunchDarkly-Wrapper"]=n.wrapperVersion?n.wrapperName+"/"+n.wrapperVersion:n.wrapperName),t}function re(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce(function(e,n){return G({},e,{},n)},{})}function ie(e,n){return Object.prototype.hasOwnProperty.call(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||G({},e))[r]=String(i))}return n||e}var w=Object.freeze({__proto__:null,btoa:y,base64URLEncode:S,clone:Y,deepEquals:Z,onNextTick:ee,wrapPromiseCallback:ne,transformValuesToVersionedValues:b,transformVersionedValuesToValues:te,chunkUserEventsForUrl:k,getLDUserAgentString:E,getLDHeaders:U,extend:re,objectHasOwnProperty:ie,sanitizeUser:oe});for(var D,I=(function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=new Array(16);e.exports=function(){for(var e,n=0;n<16;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}(D={exports:{}},D.exports),D.exports),j=[],R=0;R<256;++R)j[R]=(R+256).toString(16).substr(1);var T,N,F=function(e,n){var t=n||0,r=j;return[r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],"-",r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]],r[e[t++]]].join("")},C=0,L=0;var A=function(e,n,t){var r=n&&t||0,i=n||[],o=(e=e||{}).node||T,a=void 0!==e.clockseq?e.clockseq:N;if(null==o||null==a){var u=I();null==o&&(o=T=[1|u[0],u[1],u[2],u[3],u[4],u[5]]),null==a&&(a=N=16383&(u[6]<<8|u[7]))}var s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:L+1,l=s-C+(c-L)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||C<s)&&void 0===e.nsecs&&(c=0),1e4<=c)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");C=s,N=a;var f=(1e4*(268435455&(s+=122192928e5))+(L=c))%4294967296;i[r++]=f>>>24&255,i[r++]=f>>>16&255,i[r++]=f>>>8&255,i[r++]=255&f;var v=s/4294967296*1e4&268435455;i[r++]=v>>>8&255,i[r++]=255&v,i[r++]=v>>>24&15|16,i[r++]=v>>>16&255,i[r++]=a>>>8|128,i[r++]=255&a;for(var d=0;d<6;++d)i[r+d]=o[d];return n||F(i)},x=2e3;function ae(u,e,n){var t="/a/"+e+".gif",s=re({"Content-Type":"application/json"},U(u,n)),c=u.httpFallbackPing,l={};return l.sendChunk=function(e,r,i,n){var o=JSON.stringify(e),a=i?null:A();return n?function n(t){var e=i?s:re({},s,{"X-LaunchDarkly-Event-Schema":"3","X-LaunchDarkly-Payload-ID":a});return u.httpRequest("POST",r,e,o).promise.then(function(e){if(e)return 400<=e.status&&O(e.status)&&t?n(!1):function(e){var n={status:e.status},t=e.header("date");if(t){var r=Date.parse(t);r&&(n.serverTime=r)}return n}(e)}).catch(function(){return t?n(!1):Promise.reject()})}(!0).catch(function(){}):(c&&c(r+t+"?d="+S(o)),Promise.resolve())},l.sendEvents=function(e,n,t){if(!u.httpRequest)return Promise.resolve();var r,i=u.httpAllowsPost();r=i?[e]:k(x-n.length,e);for(var o=[],a=0;a<r.length;a++)o.push(l.sendChunk(r[a],n,t,i));return Promise.all(o)},l}function _(e){var n={},s=e.allAttributesPrivate,c=e.privateAttributeNames||[],l={key:!0,custom:!0,anonymous:!0},f={key:!0,secondary:!0,ip:!0,country:!0,email:!0,firstName:!0,lastName:!0,avatar:!0,name:!0,anonymous:!0,custom:!0};return n.filterUser=function(e){if(!e)return null;function n(r,i){return Object.keys(r).reduce(function(e,n){var t=e;return i(n)&&(!function(e){return!l[e]&&(s||-1!==o.indexOf(e)||-1!==c.indexOf(e))}(n)?t[0][n]=r[n]:t[1][n]=!0),t},[{},{}])}var o=e.privateAttributeNames||[],t=n(e,function(e){return f[e]}),r=t[0],i=t[1];if(e.custom){var a=n(e.custom,function(){return!0});r.custom=a[0],i=re({},i,a[1])}var u=Object.keys(i);return u.length&&(u.sort(),r.privateAttrs=u),r},n}function V(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}function q(){return"LaunchDarkly client initialized"}function J(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"}function ue(e){return'Custom event "'+e+'" does not exist'}function se(){return"No environment/client-side ID was specified."+$}function ce(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+$}function z(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."}function M(){return"identify() has no effect here; it must be called on the main client instance"}function B(){return"received ping message from stream"}function K(){return"received streaming update for all flags"}function le(e){return'received streaming update for flag "'+e+'"'}function fe(e){return'received streaming update for flag "'+e+'" but ignored due to version check'}function ve(e){return'received streaming deletion for flag "'+e+'"'}function de(e){return'received streaming deletion for flag "'+e+'" but ignored due to version check'}function ge(e){return'enqueueing "'+e+'" event'}var $=" Please see https://docs.launchdarkly.com/docs/js-sdk-reference#section-initializing-the-client for instructions on SDK initialization.",me=function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},pe=function(e){return'Expected application/json content type but got "'+e+'"'},he=function(){return"localStorage is unavailable"},ye=function(){return"localStorage is unavailable, so anonymous user ID cannot be cached"},be=function(e){return"network error"+(e?" ("+e+")":"")},ke=function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+$},Ee=function(e){return"Error fetching flag settings: "+V(e)},we=function(){return"No user specified."+$},De=function(){return"Invalid user specified."+$},Se=function(e,n){return n?'"'+e+'" is deprecated, please use "'+n+'"':'"'+e+'" is deprecated'},Pe=function(e,n,t){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+n+" - "+(O(e)?t:"giving up permanently")},Oe=function(){return"Cannot make HTTP requests in this environment."+$},Ue=function(){return"Closing stream connection"},Ie=function(e){return"Opening stream connection to "+e},je=function(e,n){return"Error on stream connection: "+V(e)+", will continue retrying every "+n+" milliseconds."},Re=function(e){return'Ignoring unknown config option "'+e+'"'},Te=function(e,n,t){return'Config option "'+e+'" should be of type '+n+", got "+t+", using default value"},Ne=function(e,n){return'Config option "'+e+'" should be a boolean, got '+n+", converting to boolean"},Fe=function(e,n,t){return'Config option "'+e+'" was set to '+n+", changing to minimum value of "+t},Ce=function(e){return"polling for feature flags at "+e},Le=function(e){return"sending "+e+" events"},Ae=Object.freeze({__proto__:null,clientInitialized:q,clientNotReady:function(){return"LaunchDarkly client is not ready"},eventCapacityExceeded:me,eventWithoutUser:J,invalidContentType:pe,invalidKey:function(){return"Event key must be a string"},localStorageUnavailable:he,localStorageUnavailableForUserId:ye,networkError:be,unknownCustomEventKey:ue,environmentNotFound:ke,environmentNotSpecified:se,errorFetchingFlags:Ee,userNotSpecified:we,invalidUser:De,bootstrapOldFormat:ce,bootstrapInvalid:z,deprecated:Se,httpErrorMessage:Pe,httpUnavailable:Oe,identifyDisabled:M,streamClosing:Ue,streamConnecting:Ie,streamError:je,unknownOption:Re,wrongOptionType:Te,wrongOptionTypeBoolean:Ne,optionBelowMinimum:Fe,debugPolling:Ce,debugStreamPing:B,debugStreamPut:K,debugStreamPatch:le,debugStreamPatchIgnored:fe,debugStreamDelete:ve,debugStreamDeleteIgnored:de,debugEnqueueingEvent:ge,debugPostingEvents:Le,debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"}});function xe(e,n,t,r,i,o){var a,u=3<arguments.length&&void 0!==r?r:null,s=4<arguments.length&&void 0!==i?i:null,c={},l=(5<arguments.length&&void 0!==o?o:null)||ae(e,t,n),f=n.eventsUrl+"/events/bulk/"+t,v=function(){var e={},a=0,u=0,s={};return e.summarizeEvent=function(e){if("feature"===e.kind){var n=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),t=s[n];t?t.count=t.count+1:s[n]={count:1,key:e.key,variation:e.variation,version:e.version,value:e.value,default:e.default},(0===a||e.creationDate<a)&&(a=e.creationDate),e.creationDate>u&&(u=e.creationDate)}},e.getSummary=function(){var e={},n=!0;for(var t in s){var r=s[t],i=e[r.key];i||(i={default:r.default,counters:[]},e[r.key]=i);var o={value:r.value,count:r.count};void 0!==r.variation&&null!==r.variation&&(o.variation=r.variation),r.version?o.version=r.version:o.unknown=!0,i.counters.push(o),n=!1}return n?null:{startDate:a,endDate:u,features:e}},e.clearSummary=function(){u=a=0,s={}},e}(),d=_(n),g=n.inlineUsersInEvents,m=n.samplingInterval,p=n.eventCapacity,h=n.flushInterval,y=n.logger,b=[],k=0,E=!1,w=!1;function D(){return 0===m||0===Math.floor(Math.random()*m)}function S(e){b.length<p?(b.push(e),w=!1):(w||(w=!0,y.warn(me())),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=re({},e);return g||"identify"===e.kind?n.user=d.filterUser(e.user):(n.userKey=e.user.key,delete n.user),"feature"===e.kind&&(delete n.trackEvents,delete n.debugEventsUntilDate),n}(e)),t){var r=re({},e,{kind:"debug"});delete r.trackEvents,delete r.debugEventsUntilDate,delete r.variation,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(Le(e.length)),l.sendEvents(e,f).then(function(e){e&&(e.serverTime&&(k=e.serverTime),O(e.status)||(E=!0),400<=e.status&&ee(function(){s.maybeReportError(new P(Pe(e.status,"event posting","some events were dropped")))}))}))},c.start=function(){a=setTimeout(function e(){c.flush(),a=setTimeout(e,h)},h)},c.stop=function(){clearTimeout(a)},c}function _e(n){var e={},i={};return e.on=function(e,n,t){i[e]=i[e]||[],i[e]=i[e].concat({handler:n,context:t})},e.off=function(e,n,t){if(i[e])for(var r=0;r<i[e].length;r++)i[e][r].handler===n&&i[e][r].context===t&&(i[e]=i[e].slice(0,r).concat(i[e].slice(r+1)))},e.emit=function(e){if(i[e])for(var n=i[e].slice(0),t=0;t<n.length;t++)n[t].handler.apply(n[t].context,Array.prototype.slice.call(arguments,1))},e.getEvents=function(){return Object.keys(i)},e.getEventListenerCount=function(e){return i[e]?i[e].length:0},e.maybeReportError=function(e){e&&(!function(e){return!!i[e]}("error")?(n||console).error(e.message):this.emit("error",e))},e}var Ve="ready",qe="initialized",Je="failed";var ze=function(r){var n=!1,t=!1,i=null,e=null,o=new Promise(function(n){r.on(Ve,function e(){r.off(Ve,e),n()})}).catch(function(){});return{getInitializationPromise:function(){return e||(n?Promise.resolve():t?Promise.reject(i):e=new Promise(function(n,t){r.on(qe,function e(){r.off(qe,e),n()}),r.on(Je,function e(n){r.off(Je,e),t(n)})}))},getReadyPromise:function(){return o},signalSuccess:function(){n||t||(n=!0,r.emit(qe),r.emit(Ve))},signalFailure:function(e){n||t||(t=!0,i=e,r.emit(Je,e),r.emit(Ve)),r.maybeReportError(e)}}};function Me(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(he()),Promise.reject(e)})},u.saveFlags=function(e){var n=re({},e,{$schema:1});return t.set(s(),JSON.stringify(n)).catch(function(e){return a.warn(he()),Promise.reject(e)})},u.clearFlags=function(){return t.clear(s()).catch(function(e){return a.warn(he()),Promise.reject(e)})},u}function Be(i,e,o,n){var a,u=e.streamUrl,s=e.logger,t={},c=u+"/eval/"+o,l=e.useReport,f=e.evaluationReasons,r=e.streamReconnectDelay,v=U(i,e),d=!1,g=null,m=null,p=null,h=null,y=null;function b(e){d||(s.warn(je(e,r)),d=!0),D(!1),w(),k(r)}function k(e){m||(e?m=setTimeout(E,e):E())}function E(){var e;m=null;var n="",t={headers:v};if(i.eventSourceFactory){for(var r in null!=h&&(n="h="+h),l?i.eventSourceAllowsReport?(e=c,t.method="REPORT",t.headers["Content-Type"]="application/json",t.body=JSON.stringify(p)):(e=u+"/ping/"+o,n=""):e=c+"/"+S(JSON.stringify(p)),f&&(n=n+(n?"&":"")+"withReasons=true"),e=e+(n?"?":"")+n,w(),s.info(Ie(e)),a=(new Date).getTime(),g=i.eventSourceFactory(e,t),y)ie(y,r)&&g.addEventListener(r,y[r]);g.onerror=b}}function w(){g&&(s.info(Ue()),g.close(),g=null)}function D(e){a&&n&&n.recordStreamInit(a,!e,(new Date).getTime()-a),a=null}return t.connect=function(e,n,t){p=e,h=n,y={};function r(n){y[n]=function(e){D(!(d=!1)),t[n]&&t[n](e)}}for(var i in t||{})r(i);k()},t.disconnect=function(){clearTimeout(m),m=null,w()},t.isConnected=function(){return!!(g&&i.eventSourceIsActive&&i.eventSourceIsActive(g))},t}var Ke="application/json";function $e(u,s,a){var c=s.baseUrl,l=s.useReport,f=s.evaluationReasons,v=s.logger,e={},d={};function g(e,n){if(!u.httpRequest)return new Promise(function(e,n){n(new Q(Oe()))});var t=n?"REPORT":"GET",r=U(u,s);n&&(r["Content-Type"]=Ke);var i=d[e];i||(i=function(t){var r,i,o,a,e={addPromise:function(n,e){r=n,i&&i(),i=e,n.then(function(e){r===n&&(o(e),t&&t())},function(e){r===n&&(a(e),t&&t())})}};return e.resultPromise=new Promise(function(e,n){o=e,a=n}),e}(function(){delete d[e]}),d[e]=i);var o=u.httpRequest(t,e,r,n),a=o.promise.then(function(e){if(200!==e.status)return Promise.reject(function(e){return 404===e.status?new X(ke()):new Q(Ee(e.statusText||String(e.status)))}(e));if(e.header("content-type")&&e.header("content-type").substring(0,Ke.length)===Ke)return JSON.parse(e.body);var n=pe(e.header("content-type")||"");return Promise.reject(new Q(n))},function(e){return Promise.reject(new Q(be(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(Ce(r)),g(r,i)},e}var He="ld:$anonUserId";function Ge(r,i){var e={};return e.validateUser=function(e){if(!e)return Promise.reject(new o(we()));var t=Y(e);return null!==t.key&&void 0!==t.key?(t.key=t.key.toString(),Promise.resolve(t)):t.anonymous?(r?r.get(He).catch(function(){return null}):Promise.resolve(null)).then(function(e){if(e)return t.key=e,t;var n=A();return function(e){return r?r.set(He,e).catch(function(){i.warn(ye())}):Promise.resolve()}(t.key=n).then(function(){return t})}):Promise.reject(new o(De()))},e}var Xe={baseUrl:{default:"https://app.launchdarkly.com"},streamUrl:{default:"https://clientstream.launchdarkly.com"},eventsUrl:{default:"https://events.launchdarkly.com"},sendEvents:{default:!0},streaming:{type:"boolean"},sendLDHeaders:{default:!0},inlineUsersInEvents:{default:!1},allowFrequentDuplicateEvents:{default:!1},sendEventsOnlyForVariation:{default:!1},useReport:{default:!1},evaluationReasons:{default:!1},eventCapacity:{default:100,minimum:1},flushInterval:{default:2e3,minimum:2e3},samplingInterval:{default:0,minimum:0},streamReconnectDelay:{default:1e3,minimum:0},allAttributesPrivate:{default:!1},privateAttributeNames:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"}};function We(e,n,t,r){var a=re({logger:{default:r}},Xe,t),i={all_attributes_private:"allAttributesPrivate",private_attribute_names:"privateAttributeNames",samplingInterval:null};function u(e){ee(function(){n&&n.maybeReportError(new d(e))})}var o,s,c,l,f=re({},e||{});function v(e){if(null===e)return"any";if(void 0!==e){if(Array.isArray(e))return"array";var n=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(Se(e,n)),n&&(void 0===o[n]&&(o[n]=o[e]),delete o[e])}}),s=re({},f),Object.keys(a).forEach(function(e){void 0!==s[e]&&null!==s[e]||(s[e]=a[e]&&a[e].default)}),l=re({},c=f=s),Object.keys(c).forEach(function(e){var n=c[e];if(null!=n){var t=a[e];if(void 0===t)u(Re(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(Ne(e,o))):(u(Te(e,r,o)),l[e]=t.default):"number"===o&&void 0!==t.minimum&&n<t.minimum&&(u(Fe(e,n,t.minimum)),l[e]=t.minimum)}}}}),f=l}var Qe=Object.freeze({__proto__:null,baseOptionDefs:Xe,validate:We}).baseOptionDefs;var Ye=function(e){var n={diagnosticId:A()};return e&&(n.sdkKeySuffix=6<e.length?e.substring(e.length-6):e),n},Ze=function(e){var n,t,r,i;function o(e){n=e,r=t=0,i=[]}return o(e),{getProps:function(){return{dataSinceDate:n,droppedEvents:t,eventsInLastBatch:r,streamInits:i}},setProps:function(e){n=e.dataSinceDate,t=e.droppedEvents||0,r=e.eventsInLastBatch||0,i=e.streamInits||[]},incrementDroppedEvents:function(){t++},setEventsInLastBatch:function(e){r=e},recordStreamInit:function(e,n,t){var r={timestamp:e,failed:n,durationMillis:t};i.push(r)},reset:o}},en=function(n,e,t,r,i,o){var a,u,s=!!n.diagnosticUseCombinedEvent,c="ld:"+r+":$diagnostics",l=i.eventsUrl+"/events/diagnostic/"+r,f=i.diagnosticRecordingInterval,v=e,d=!!i.streaming,g={};function m(){return{sdk:function(){var e=G({},n.diagnosticSdkData);i.wrapperName&&(e.wrapperName=i.wrapperName);i.wrapperVersion&&(e.wrapperVersion=i.wrapperVersion);return e}(),configuration:{customBaseURI:i.baseUrl!==Qe.baseUrl.default,customStreamURI:i.streamUrl!==Qe.streamUrl.default,customEventsURI:i.eventsUrl!==Qe.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!d,allAttributesPrivate:!!i.allAttributesPrivate,inlineUsersInEvents:!!i.inlineUsersInEvents,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,allowFrequentDuplicateEvents:!!i.allowFrequentDuplicateEvents,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation},platform:n.diagnosticPlatformData}}function p(e){i.logger&&i.logger.debug(Ae.debugPostingDiagnosticEvent(e)),t.sendEvents(e,l,!0).then(function(){}).catch(function(){})}function h(){p(function(){var e=(new Date).getTime(),n=G({kind:s?"diagnostic-combined":"diagnostic",id:o,creationDate:e},v.getProps());return s&&(n=G({},n,{},m())),v.reset(e),n}()),u=setTimeout(h,f),a=(new Date).getTime(),s&&function(){if(n.localStorage){var e=G({},v.getProps());n.localStorage.set(c,JSON.stringify(e),function(){})}}()}return g.start=function(){s?function(t){if(!n.localStorage)return t(!1);n.localStorage.get(c).then(function(e){if(e)try{var n=JSON.parse(e);v.setProps(n),a=n.dataSinceDate}catch(e){}t(!0)}).catch(function(){t(!1)})}(function(e){if(e){var n=(a||0)+f,t=(new Date).getTime();n<=t?h():u=setTimeout(h,n-t)}else 0===Math.floor(4*Math.random())?h():u=setTimeout(h,f)}):(p(G({kind:"diagnostic-init",id:o,creationDate:v.getProps().dataSinceDate},m())),u=setTimeout(h,f))},g.stop=function(){u&&clearTimeout(u)},g.setStreaming=function(e){d=e},g};function nn(e,n){var o,a=["debug","info","warn","error"];o=null!=n?""===n?"":n+" ":"LD: ";var u=0;e&&(u="none"===e?100:a.indexOf(e));var t={};function r(e,n,t){if(u<=e&&console){var r=console[n];if(r){var i=e<a.length?a[e]:"?";r.call(console,o+"["+i+"] "+t)}}}return t.debug=function(e){return r(0,"log",e)},t.info=function(e){return r(1,"info",e)},t.warn=function(e){return r(2,"warn",e)},t.error=function(e){return r(3,"error",e)},t}var tn="change",rn="internal-change";e.createConsoleLogger=nn,e.errors=r,e.initialize=function(e,n,t,i,r){var a,o,u,s,c=function(){if(t&&t.logger)return t.logger;return r&&r.logger&&r.logger.default||nn("warn")}(),l=_e(c),f=ze(l),v=We(t,l,r,c),d=v.sendEvents,g=e,m=v.hash,p=ae(i,g,v),h=v.sendEvents&&!v.diagnosticOptOut,y=h?Ye(g):null,b=h?Ze((new Date).getTime()):null,k=h?en(i,b,p,g,v,y):null,E=Be(i,v,g,b),w=v.eventProcessor||xe(i,v,g,b,l,p),D=$e(i,v,g),S={},P={},O=v.streaming,U=!1,I=!1,j=!0,R=v.stateProvider,T=function(e,n){var t,r={};return r.setUser=function(e){(t=oe(e))&&n&&n(Y(t))},r.getUser=function(){return t?Y(t):null},e&&r.setUser(e),r}(null,function(e){if(R)return;e&&F({kind:"identify",key:e.key,user:e,creationDate:(new Date).getTime()})}),N=Ge(i.localStorage,c);function F(e){g&&(R&&R.enqueueEvent&&R.enqueueEvent(e)||(e.user?(j=!1,!d||I||i.isDoNotTrack()||(c.debug(ge(e.kind)),w.enqueue(e))):j&&(c.warn("Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/docs/js-sdk-reference#section-analytics-events"),j=!1)))}function C(e,n,t,r){var i=T.getUser(),o=new Date,a=n?n.value:null;if(!v.allowFrequentDuplicateEvents){var u=JSON.stringify(a)+(i&&i.key?i.key:"")+e,s=S[u];if(s&&o-s<3e5)return;S[u]=o}var c={kind:"feature",key:e,user:i,value:a,variation:n?n.variationIndex:null,default:t,creationDate:o.getTime()},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 L(e,n,t,r){var i;if(P&&ie(P,e)&&P[e]&&!P[e].deleted){var o=P[e];i=A(o),null!==o.value&&void 0!==o.value||(i.value=n)}else i={value:n,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}};return t&&C(e,i,n,r),i}function A(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function x(){o=!0,T.getUser()&&E.connect(T.getUser(),m,{ping:function(){c.debug("received ping message from stream");var n=T.getUser();D.fetchFlagSettings(n,m).then(function(e){Z(n,T.getUser())&&V(e||{})}).catch(function(e){l.maybeReportError(new Q(Ee(e)))})},put:function(e){var n=JSON.parse(e.data);c.debug("received streaming update for all flags"),V(n)},patch:function(e){var n=JSON.parse(e.data),t=P[n.key];if(!t||!t.version||!n.version||t.version<n.version){c.debug(le(n.key));var r={},i=re({},n);delete i.key;var o=A(P[n.key]=i);r[n.key]=t?{previous:t.value,current:o}:{current:o},q(r)}else c.debug(fe(n.key))},delete:function(e){var n=JSON.parse(e.data);if(!P[n.key]||P[n.key].version<n.version){c.debug(ve(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},q(t)}else c.debug(de(n.key))}})}function _(){o&&(E.disconnect(),o=!1)}function V(e){var n={};if(!e)return Promise.resolve();for(var t in P)ie(P,t)&&P[t]&&(e[t]&&!Z(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)ie(e,r)&&e[r]&&(!P[r]||P[r].deleted)&&(n[r]={current:A(e[r])});return P=G({},e),q(n).catch(function(){})}function q(i){var e=Object.keys(i);if(0<e.length){var o={};e.forEach(function(e){var n=i[e].current,t=n?n.value:void 0,r=i[e].previous;l.emit(tn+":"+e,t,r),o[e]=n?{current:t,previous:r}:{previous:r}}),l.emit(tn,o),l.emit(rn,P),v.sendEventsOnlyForVariation||R||e.forEach(function(e){C(e,i[e].current)})}return a&&s?s.saveFlags(P).catch(function(){return null}):Promise.resolve()}function J(){var e=O||u&&void 0===O;e&&!o?x():!e&&o&&_(),k&&k.setStreaming(e)}function z(e){return e===tn||e.substr(0,tn.length+1)===tn+":"}if(i.localStorage&&(s=new Me(i.localStorage,g,m,T,c)),"string"==typeof v.bootstrap&&"LOCALSTORAGE"===v.bootstrap.toUpperCase()&&(s?a=!0:c.warn(he())),"object"===H(v.bootstrap)&&(P=function(t){var e=Object.keys(t),r="$flagsState",i=t[r];!i&&e.length&&c.warn(ce()),!1===t.$valid&&c.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");var o={};return e.forEach(function(e){if(e!==r&&"$valid"!==e){var n={value:t[e]};i&&i[e]?n=re(n,i[e]):n.version=0,o[e]=n}}),o}(v.bootstrap)),R){var M=R.getInitialState();M?B(M):R.on("init",B),R.on("update",function(e){e.user&&T.setUser(e.user);e.flags&&V(e.flags)})}else(e?N.validateUser(n).then(function(e){return T.setUser(e),"object"===H(v.bootstrap)?K():a?s.loadFlags().catch(function(){return null}).then(function(e){return null==e?(P={},D.fetchFlagSettings(T.getUser(),m).then(function(e){return V(e||{})}).then(K).catch(function(e){$(new Q(Ee(e)))})):(P=e,ee(K),D.fetchFlagSettings(T.getUser(),m).then(function(e){return V(e)}).catch(function(e){return l.maybeReportError(e)}))}):D.fetchFlagSettings(T.getUser(),m).then(function(e){P=e||{},K()}).catch(function(e){P={},$(e)})}):Promise.reject(new X(se()))).catch($);function B(e){g=e.environment,T.setUser(e.user),P=G({},e.flags),ee(K)}function K(){c.info("LaunchDarkly client initialized"),U=!0,J(),f.signalSuccess()}function $(e){f.signalFailure(e)}return{client:{waitForInitialization:function(){return f.getInitializationPromise()},waitUntilReady:function(){return f.getReadyPromise()},identify:function(e,r,n){return I?ne(Promise.resolve({}),n):R?(c.warn("identify() has no effect here; it must be called on the main client instance"),ne(Promise.resolve(te(P)),n)):ne((a&&s?s.clearFlags():Promise.resolve()).then(function(){return N.validateUser(e)}).then(function(t){return D.fetchFlagSettings(t,r).then(function(e){var n=te(e);return T.setUser(t),m=r,e?V(e).then(function(){return n}):n})}).then(function(e){return o&&x(),e}).catch(function(e){return l.maybeReportError(e),Promise.reject(e)}),n)},getUser:function(){return T.getUser()},variation:function(e,n){return L(e,n,!0,!1).value},variationDetail:function(e,n){return L(e,n,!0,!0)},track:function(e,n,t){if("string"==typeof e){i.customEventFilter&&!i.customEventFilter(e)&&c.warn(ue(e));var r={kind:"custom",key:e,user:T.getUser(),url:i.getCurrentUrl(),creationDate:(new Date).getTime()};null!=n&&(r.data=n),null!=t&&(r.metricValue=t),F(r)}else l.maybeReportError(new W(ue(e)))},on:function(e,n,t){z(e)?(u=!0,U&&J(),l.on(e,n,t)):l.on.apply(l,arguments)},off:function(e){if(l.off.apply(l,arguments),z(e)){var n=!1;l.getEvents().forEach(function(e){z(e)&&0<l.getEventListenerCount(e)&&(n=!0)}),n||(u=!1,o&&void 0===O&&_())}},setStreaming:function(e){var n=null===e?void 0:e;n!==O&&(O=n,J())},flush:function(e){return ne(d?w.flush():Promise.resolve(),e)},allFlags:function(){var e={};if(!P)return e;for(var n in P)ie(P,n)&&(e[n]=L(n,null,!v.sendEventsOnlyForVariation).value);return e},close:function(e){if(I)return ne(Promise.resolve(),e);function n(){I=!0,P={}}return ne(Promise.resolve().then(function(){if(_(),k&&k.stop(),d)return w.stop(),w.flush()}).then(n).catch(n),e)}},options:v,emitter:l,ident:T,logger:c,requestor:D,start:function(){d&&(k&&k.start(),w.start())},enqueueEvent:F,getFlagsInternal:function(){return P},getEnvironmentId:function(){return g},internalChangeEventName:rn}},e.messages=Ae,e.utils=w,e.version="3.2.10",Object.defineProperty(e,"__esModule",{value:!0})});
|
|
2
2
|
//# sourceMappingURL=ldclient-common.min.js.map
|