UNPKG

launchdarkly-js-client-sdk

Version:
1 lines 60.6 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LDClient={})}(this,function(e){"use strict";function t(e){function t(e,t){Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),this.message=e,this.code=t}return t.prototype=new Error,t.prototype.name=e,t.prototype.constructor=t,t}const n=t("LaunchDarklyUnexpectedResponseError"),r=t("LaunchDarklyInvalidEnvironmentIdError"),o=t("LaunchDarklyInvalidUserError"),i=t("LaunchDarklyInvalidEventKeyError"),a=t("LaunchDarklyInvalidArgumentError"),s=t("LaunchDarklyFlagFetchError");for(var c={LDUnexpectedResponseError:n,LDInvalidEnvironmentIdError:r,LDInvalidUserError:o,LDInvalidEventKeyError:i,LDInvalidArgumentError:a,LDInvalidDataError:t("LaunchDarklyInvalidDataError"),LDFlagFetchError:s,LDTimeoutError:t("LaunchDarklyTimeoutError"),isHttpErrorRecoverable:function(e){return!(e>=400&&e<500)||(400===e||408===e||429===e)}},u=function(e){var t=h(e),n=t[0],r=t[1];return 3*(n+r)/4-r},l=function(e){var t,n,r=h(e),o=r[0],i=r[1],a=new v(function(e,t,n){return 3*(t+n)/4-n}(0,o,i)),s=0,c=i>0?o-4:o;for(n=0;n<c;n+=4)t=g[e.charCodeAt(n)]<<18|g[e.charCodeAt(n+1)]<<12|g[e.charCodeAt(n+2)]<<6|g[e.charCodeAt(n+3)],a[s++]=t>>16&255,a[s++]=t>>8&255,a[s++]=255&t;2===i&&(t=g[e.charCodeAt(n)]<<2|g[e.charCodeAt(n+1)]>>4,a[s++]=255&t);1===i&&(t=g[e.charCodeAt(n)]<<10|g[e.charCodeAt(n+1)]<<4|g[e.charCodeAt(n+2)]>>2,a[s++]=t>>8&255,a[s++]=255&t);return a},d=function(e){for(var t,n=e.length,r=n%3,o=[],i=16383,a=0,s=n-r;a<s;a+=i)o.push(w(e,a,a+i>s?s:a+i));1===r?(t=e[n-1],o.push(f[t>>2]+f[t<<4&63]+"==")):2===r&&(t=(e[n-2]<<8)+e[n-1],o.push(f[t>>10]+f[t>>4&63]+f[t<<2&63]+"="));return o.join("")},f=[],g=[],v="undefined"!=typeof Uint8Array?Uint8Array:Array,p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",m=0;m<64;++m)f[m]=p[m],g[p.charCodeAt(m)]=m;function h(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function y(e){return f[e>>18&63]+f[e>>12&63]+f[e>>6&63]+f[63&e]}function w(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(y(r));return o.join("")}g["-".charCodeAt(0)]=62,g["_".charCodeAt(0)]=63;var b={byteLength:u,toByteArray:l,fromByteArray:d},k=Array.isArray,E=Object.keys,D=Object.prototype.hasOwnProperty,x=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){var r,o,i,a=k(t),s=k(n);if(a&&s){if((o=t.length)!=n.length)return!1;for(r=o;0!==r--;)if(!e(t[r],n[r]))return!1;return!0}if(a!=s)return!1;var c=t instanceof Date,u=n instanceof Date;if(c!=u)return!1;if(c&&u)return t.getTime()==n.getTime();var l=t instanceof RegExp,d=n instanceof RegExp;if(l!=d)return!1;if(l&&d)return t.toString()==n.toString();var f=E(t);if((o=f.length)!==E(n).length)return!1;for(r=o;0!==r--;)if(!D.call(n,f[r]))return!1;for(r=o;0!==r--;)if(!e(t[i=f[r]],n[i]))return!1;return!0}return t!=t&&n!=n};const O=["key","ip","country","email","firstName","lastName","avatar","name"];function C(e){const t=unescape(encodeURIComponent(e));return b.fromByteArray(function(e){const t=[];for(let n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}(t))}function P(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var S,I={appendUrlPath:function(e,t){return(e.endsWith("/")?e.substring(0,e.length-1):e)+(t.startsWith("/")?"":"/")+t},base64URLEncode:function(e){return C(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")},btoa:C,clone:function(e){return JSON.parse(JSON.stringify(e))},deepEquals:function(e,t){return x(e,t)},extend:function(...e){return e.reduce((e,t)=>({...e,...t}),{})},getLDUserAgentString:function(e){const t=e.version||"?";return e.userAgent+"/"+t},objectHasOwnProperty:P,onNextTick:function(e){setTimeout(e,0)},sanitizeContext:function(e){if(!e)return e;let t;return null!==e.kind&&void 0!==e.kind||O.forEach(n=>{const r=e[n];void 0!==r&&"string"!=typeof r&&(t=t||{...e},t[n]=String(r))}),t||e},transformValuesToVersionedValues:function(e){const t={};for(const n in e)P(e,n)&&(t[n]={value:e[n],version:0});return t},transformVersionedValuesToValues:function(e){const t={};for(const n in e)P(e,n)&&(t[n]=e[n].value);return t},wrapPromiseCallback:function(e,t){const n=e.then(e=>(t&&setTimeout(()=>{t(null,e)},0),e),e=>{if(!t)return Promise.reject(e);setTimeout(()=>{t(e,null)},0)});return t?void 0:n},once:function(e){let t,n=!1;return function(...r){return n||(n=!0,t=e.apply(this,r)),t}}},T=new Uint8Array(16);function F(){if(!S&&!(S="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return S(T)}var L=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function U(e){return"string"==typeof e&&L.test(e)}for(var j,A,R=[],N=0;N<256;++N)R.push((N+256).toString(16).substr(1));function $(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(R[e[t+0]]+R[e[t+1]]+R[e[t+2]]+R[e[t+3]]+"-"+R[e[t+4]]+R[e[t+5]]+"-"+R[e[t+6]]+R[e[t+7]]+"-"+R[e[t+8]]+R[e[t+9]]+"-"+R[e[t+10]]+R[e[t+11]]+R[e[t+12]]+R[e[t+13]]+R[e[t+14]]+R[e[t+15]]).toLowerCase();if(!U(n))throw TypeError("Stringified UUID is invalid");return n}var V=0,H=0;function M(e){if(!U(e))throw TypeError("Invalid UUID");var t,n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}function q(e,t,n){function r(e,r,o,i){if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));for(var t=[],n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof r&&(r=M(r)),16!==r.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var a=new Uint8Array(16+e.length);if(a.set(r),a.set(e,r.length),(a=n(a))[6]=15&a[6]|t,a[8]=63&a[8]|128,o){i=i||0;for(var s=0;s<16;++s)o[i+s]=a[s];return o}return $(a)}try{r.name=e}catch(e){}return r.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",r.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",r}function z(e){return 14+(e+64>>>9<<4)+1}function K(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function _(e,t,n,r,o,i){return K((a=K(K(t,e),K(r,i)))<<(s=o)|a>>>32-s,n);var a,s}function J(e,t,n,r,o,i,a){return _(t&n|~t&r,e,t,o,i,a)}function B(e,t,n,r,o,i,a){return _(t&r|n&~r,e,t,o,i,a)}function W(e,t,n,r,o,i,a){return _(t^n^r,e,t,o,i,a)}function G(e,t,n,r,o,i,a){return _(n^(t|~r),e,t,o,i,a)}var X=q("v3",48,function(e){if("string"==typeof e){var t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(var n=0;n<t.length;++n)e[n]=t.charCodeAt(n)}return function(e){for(var t=[],n=32*e.length,r="0123456789abcdef",o=0;o<n;o+=8){var i=e[o>>5]>>>o%32&255,a=parseInt(r.charAt(i>>>4&15)+r.charAt(15&i),16);t.push(a)}return t}(function(e,t){e[t>>5]|=128<<t%32,e[z(t)-1]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,a=0;a<e.length;a+=16){var s=n,c=r,u=o,l=i;n=J(n,r,o,i,e[a],7,-680876936),i=J(i,n,r,o,e[a+1],12,-389564586),o=J(o,i,n,r,e[a+2],17,606105819),r=J(r,o,i,n,e[a+3],22,-1044525330),n=J(n,r,o,i,e[a+4],7,-176418897),i=J(i,n,r,o,e[a+5],12,1200080426),o=J(o,i,n,r,e[a+6],17,-1473231341),r=J(r,o,i,n,e[a+7],22,-45705983),n=J(n,r,o,i,e[a+8],7,1770035416),i=J(i,n,r,o,e[a+9],12,-1958414417),o=J(o,i,n,r,e[a+10],17,-42063),r=J(r,o,i,n,e[a+11],22,-1990404162),n=J(n,r,o,i,e[a+12],7,1804603682),i=J(i,n,r,o,e[a+13],12,-40341101),o=J(o,i,n,r,e[a+14],17,-1502002290),n=B(n,r=J(r,o,i,n,e[a+15],22,1236535329),o,i,e[a+1],5,-165796510),i=B(i,n,r,o,e[a+6],9,-1069501632),o=B(o,i,n,r,e[a+11],14,643717713),r=B(r,o,i,n,e[a],20,-373897302),n=B(n,r,o,i,e[a+5],5,-701558691),i=B(i,n,r,o,e[a+10],9,38016083),o=B(o,i,n,r,e[a+15],14,-660478335),r=B(r,o,i,n,e[a+4],20,-405537848),n=B(n,r,o,i,e[a+9],5,568446438),i=B(i,n,r,o,e[a+14],9,-1019803690),o=B(o,i,n,r,e[a+3],14,-187363961),r=B(r,o,i,n,e[a+8],20,1163531501),n=B(n,r,o,i,e[a+13],5,-1444681467),i=B(i,n,r,o,e[a+2],9,-51403784),o=B(o,i,n,r,e[a+7],14,1735328473),n=W(n,r=B(r,o,i,n,e[a+12],20,-1926607734),o,i,e[a+5],4,-378558),i=W(i,n,r,o,e[a+8],11,-2022574463),o=W(o,i,n,r,e[a+11],16,1839030562),r=W(r,o,i,n,e[a+14],23,-35309556),n=W(n,r,o,i,e[a+1],4,-1530992060),i=W(i,n,r,o,e[a+4],11,1272893353),o=W(o,i,n,r,e[a+7],16,-155497632),r=W(r,o,i,n,e[a+10],23,-1094730640),n=W(n,r,o,i,e[a+13],4,681279174),i=W(i,n,r,o,e[a],11,-358537222),o=W(o,i,n,r,e[a+3],16,-722521979),r=W(r,o,i,n,e[a+6],23,76029189),n=W(n,r,o,i,e[a+9],4,-640364487),i=W(i,n,r,o,e[a+12],11,-421815835),o=W(o,i,n,r,e[a+15],16,530742520),n=G(n,r=W(r,o,i,n,e[a+2],23,-995338651),o,i,e[a],6,-198630844),i=G(i,n,r,o,e[a+7],10,1126891415),o=G(o,i,n,r,e[a+14],15,-1416354905),r=G(r,o,i,n,e[a+5],21,-57434055),n=G(n,r,o,i,e[a+12],6,1700485571),i=G(i,n,r,o,e[a+3],10,-1894986606),o=G(o,i,n,r,e[a+10],15,-1051523),r=G(r,o,i,n,e[a+1],21,-2054922799),n=G(n,r,o,i,e[a+8],6,1873313359),i=G(i,n,r,o,e[a+15],10,-30611744),o=G(o,i,n,r,e[a+6],15,-1560198380),r=G(r,o,i,n,e[a+13],21,1309151649),n=G(n,r,o,i,e[a+4],6,-145523070),i=G(i,n,r,o,e[a+11],10,-1120210379),o=G(o,i,n,r,e[a+2],15,718787259),r=G(r,o,i,n,e[a+9],21,-343485551),n=K(n,s),r=K(r,c),o=K(o,u),i=K(i,l)}return[n,r,o,i]}(function(e){if(0===e.length)return[];for(var t=8*e.length,n=new Uint32Array(z(t)),r=0;r<t;r+=8)n[r>>5]|=(255&e[r/8])<<r%32;return n}(e),8*e.length))}),Q=X;function Y(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:case 3:return t^n^r;case 2:return t&n^t&r^n&r}}function Z(e,t){return e<<t|e>>>32-t}var ee=q("v5",80,function(e){var t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){var r=unescape(encodeURIComponent(e));e=[];for(var o=0;o<r.length;++o)e.push(r.charCodeAt(o))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var i=e.length/4+2,a=Math.ceil(i/16),s=new Array(a),c=0;c<a;++c){for(var u=new Uint32Array(16),l=0;l<16;++l)u[l]=e[64*c+4*l]<<24|e[64*c+4*l+1]<<16|e[64*c+4*l+2]<<8|e[64*c+4*l+3];s[c]=u}s[a-1][14]=8*(e.length-1)/Math.pow(2,32),s[a-1][14]=Math.floor(s[a-1][14]),s[a-1][15]=8*(e.length-1)&4294967295;for(var d=0;d<a;++d){for(var f=new Uint32Array(80),g=0;g<16;++g)f[g]=s[d][g];for(var v=16;v<80;++v)f[v]=Z(f[v-3]^f[v-8]^f[v-14]^f[v-16],1);for(var p=n[0],m=n[1],h=n[2],y=n[3],w=n[4],b=0;b<80;++b){var k=Math.floor(b/20),E=Z(p,5)+Y(k,m,h,y)+w+t[k]+f[b]>>>0;w=y,y=h,h=Z(m,30)>>>0,m=p,p=E}n[0]=n[0]+p>>>0,n[1]=n[1]+m>>>0,n[2]=n[2]+h>>>0,n[3]=n[3]+y>>>0,n[4]=n[4]+w>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}),te=ee;var ne=Object.freeze({__proto__:null,v1:function(e,t,n){var r=t&&n||0,o=t||new Array(16),i=(e=e||{}).node||j,a=void 0!==e.clockseq?e.clockseq:A;if(null==i||null==a){var s=e.random||(e.rng||F)();null==i&&(i=j=[1|s[0],s[1],s[2],s[3],s[4],s[5]]),null==a&&(a=A=16383&(s[6]<<8|s[7]))}var c=void 0!==e.msecs?e.msecs:Date.now(),u=void 0!==e.nsecs?e.nsecs:H+1,l=c-V+(u-H)/1e4;if(l<0&&void 0===e.clockseq&&(a=a+1&16383),(l<0||c>V)&&void 0===e.nsecs&&(u=0),u>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");V=c,H=u,A=a;var d=(1e4*(268435455&(c+=122192928e5))+u)%4294967296;o[r++]=d>>>24&255,o[r++]=d>>>16&255,o[r++]=d>>>8&255,o[r++]=255&d;var f=c/4294967296*1e4&268435455;o[r++]=f>>>8&255,o[r++]=255&f,o[r++]=f>>>24&15|16,o[r++]=f>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var g=0;g<6;++g)o[r+g]=i[g];return t||$(o)},v3:Q,v4:function(e,t,n){var r=(e=e||{}).random||(e.rng||F)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=r[o];return t}return $(r)},v5:te,NIL:"00000000-0000-0000-0000-000000000000",version:function(e){if(!U(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)},validate:U,stringify:$,parse:M});const re=["debug","info","warn","error","none"];var oe={commonBasicLogger:function(e,t){if(e&&e.destination&&"function"!=typeof e.destination)throw new Error("destination for basicLogger was set to a non-function");function n(e){return function(t){console&&console[e]&&console[e].call(console,t)}}const r=e&&e.destination?[e.destination,e.destination,e.destination,e.destination]:[n("log"),n("info"),n("warn"),n("error")],o=!(!e||!e.destination),i=e&&void 0!==e.prefix&&null!==e.prefix?e.prefix:"[LaunchDarkly] ";let a=1;if(e&&e.level)for(let t=0;t<re.length;t++)re[t]===e.level&&(a=t);function s(e,n,a){if(a.length<1)return;let s;const c=o?n+": "+i:i;if(1!==a.length&&t){const e=[...a];e[0]=c+e[0],s=t(...e)}else s=c+a[0];try{r[e](s)}catch(e){console&&console.log&&console.log("[LaunchDarkly] Configured logger's "+n+" method threw an exception: "+e)}}const c={};for(let e=0;e<re.length;e++){const t=re[e];if("none"!==t)if(e<a)c[t]=()=>{};else{const n=e;c[t]=function(){s(n,t,arguments)}}}return c},validateLogger:function(e){re.forEach(t=>{if("none"!==t&&(!e[t]||"function"!=typeof e[t]))throw new Error("Provided logger instance must support logger."+t+"(...) method")})}};function ie(e){return e&&e.message?e.message:"string"==typeof e||e instanceof String?e:JSON.stringify(e)}const ae=" Please see https://docs.launchdarkly.com/sdk/client-side/javascript#initialize-the-client for instructions on SDK initialization.";var se={bootstrapInvalid:function(){return"LaunchDarkly bootstrap data is not available because the back end could not read the flags."},bootstrapOldFormat:function(){return"LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."+ae},clientInitialized:function(){return"LaunchDarkly client initialized"},clientNotReady:function(){return"LaunchDarkly client is not ready"},debugEnqueueingEvent:function(e){return'enqueueing "'+e+'" event'},debugPostingDiagnosticEvent:function(e){return"sending diagnostic event ("+e.kind+")"},debugPostingEvents:function(e){return"sending "+e+" events"},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'},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'},debugStreamPing:function(){return"received ping message from stream"},debugPolling:function(e){return"polling for feature flags at "+e},debugStreamPut:function(){return"received streaming update for all flags"},deprecated:function(e,t){return t?'"'+e+'" is deprecated, please use "'+t+'"':'"'+e+'" is deprecated'},environmentNotFound:function(){return"Environment not found. Double check that you specified a valid environment/client-side ID."+ae},environmentNotSpecified:function(){return"No environment/client-side ID was specified."+ae},errorFetchingFlags:function(e){return"Error fetching flag settings: "+ie(e)},eventCapacityExceeded:function(){return"Exceeded event queue capacity. Increase capacity to avoid dropping events."},eventWithoutContext:function(){return"Be sure to call `identify` in the LaunchDarkly client: https://docs.launchdarkly.com/sdk/features/identify#javascript"},httpErrorMessage:function(e,t,n){return"Received error "+e+(401===e?" (invalid SDK key)":"")+" for "+t+" - "+(c.isHttpErrorRecoverable(e)?n:"giving up permanently")},httpUnavailable:function(){return"Cannot make HTTP requests in this environment."+ae},identifyDisabled:function(){return"identify() has no effect here; it must be called on the main client instance"},inspectorMethodError:(e,t)=>`an inspector: "${t}" of type: "${e}" generated an exception`,invalidContentType:function(e){return'Expected application/json content type but got "'+e+'"'},invalidData:function(){return"Invalid data received from LaunchDarkly; connection may have been interrupted"},invalidInspector:(e,t)=>`an inspector: "${t}" of an invalid type (${e}) was configured`,invalidKey:function(){return"Event key must be a string"},invalidMetricValue:e=>`The track function was called with a non-numeric "metricValue" (${e}), only numeric metric values are supported.`,invalidContext:function(){return"Invalid context specified."+ae},invalidTagValue:e=>`Config option "${e}" must only contain letters, numbers, ., _ or -.`,localStorageUnavailable:function(e){return"local storage is unavailable: "+ie(e)},networkError:e=>"network error"+(e?" ("+e+")":""),optionBelowMinimum:(e,t,n)=>'Config option "'+e+'" was set to '+t+", changing to minimum value of "+n,streamClosing:function(){return"Closing stream connection"},streamConnecting:function(e){return"Opening stream connection to "+e},streamError:function(e,t){return"Error on stream connection: "+ie(e)+", will continue retrying after "+t+" milliseconds."},tagValueTooLong:e=>`Value of "${e}" was longer than 64 characters and was discarded.`,unknownCustomEventKey:function(e){return'Custom event "'+e+'" does not exist'},unknownOption:e=>'Ignoring unknown config option "'+e+'"',contextNotSpecified:function(){return"No context specified."+ae},unrecoverableStreamError:e=>`Error on stream connection ${ie(e)}, giving up permanently`,wrongOptionType:(e,t,n)=>'Config option "'+e+'" should be of type '+t+", got "+n+", using default value",wrongOptionTypeBoolean:(e,t)=>'Config option "'+e+'" should be a boolean, got '+t+", converting to boolean"};const{validateLogger:ce}=oe,ue={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"},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},privateAttributes:{default:[]},bootstrap:{type:"string|object"},diagnosticRecordingInterval:{default:9e5,minimum:2e3},diagnosticOptOut:{default:!1},wrapperName:{type:"string"},wrapperVersion:{type:"string"},stateProvider:{type:"object"},application:{validator:function(e,t,n){const r={};t.id&&(r.id=fe(`${e}.id`,t.id,n));t.version&&(r.version=fe(`${e}.version`,t.version,n));return r}},inspectors:{default:[]},hooks:{default:[]},plugins:{default:[]}},le=/^(\w|\.|-)+$/;function de(e){return e&&e.replace(/\/+$/,"")}function fe(e,t,n){if("string"==typeof t&&t.match(le)){if(!(t.length>64))return t;n.warn(se.tagValueTooLong(e))}else n.warn(se.invalidTagValue(e))}var ge={baseOptionDefs:ue,validate:function(e,t,n,r){const o=I.extend({logger:{default:r}},ue,n),i={};function a(e){I.onNextTick(()=>{t&&t.maybeReportError(new c.LDInvalidArgumentError(e))})}let s=I.extend({},e||{});return function(e){const t=e;Object.keys(i).forEach(e=>{if(void 0!==t[e]){const n=i[e];r&&r.warn(se.deprecated(e,n)),n&&(void 0===t[n]&&(t[n]=t[e]),delete t[e])}})}(s),s=function(e){const t=I.extend({},e);return Object.keys(o).forEach(e=>{void 0!==t[e]&&null!==t[e]||(t[e]=o[e]&&o[e].default)}),t}(s),s=function(e){const t=I.extend({},e),n=e=>{if(null===e)return"any";if(void 0===e)return;if(Array.isArray(e))return"array";const t=typeof e;return"boolean"===t||"string"===t||"number"===t||"function"===t?t:"object"};return Object.keys(e).forEach(i=>{const s=e[i];if(null!=s){const c=o[i];if(void 0===c)a(se.unknownOption(i));else{const o=c.type||n(c.default),u=c.validator;if(u){const n=u(i,e[i],r);void 0!==n?t[i]=n:delete t[i]}else if("any"!==o){const e=o.split("|"),r=n(s);e.indexOf(r)<0?"boolean"===o?(t[i]=!!s,a(se.wrongOptionTypeBoolean(i,r))):(a(se.wrongOptionType(i,o,r)),t[i]=c.default):"number"===r&&void 0!==c.minimum&&s<c.minimum&&(a(se.optionBelowMinimum(i,s,c.minimum)),t[i]=c.minimum)}}}}),t.baseUrl=de(t.baseUrl),t.streamUrl=de(t.streamUrl),t.eventsUrl=de(t.eventsUrl),t}(s),ce(s.logger),s},getTags:function(e){const 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}};const{getLDUserAgentString:ve}=I;var pe={getLDHeaders:function(e,t){if(t&&!t.sendLDHeaders)return{};const n={};n[e.userAgentHeaderName||"User-Agent"]=ve(e),t&&t.wrapperName&&(n["X-LaunchDarkly-Wrapper"]=t.wrapperVersion?t.wrapperName+"/"+t.wrapperVersion:t.wrapperName);const r=ge.getTags(t),o=Object.keys(r);return o.length&&(n["x-launchdarkly-tags"]=o.sort().map(e=>Array.isArray(r[e])?r[e].sort().map(t=>`${e}/${t}`):[`${e}/${r[e]}`]).reduce((e,t)=>e.concat(t),[]).join(" ")),n},transformHeaders:function(e,t){return t&&t.requestHeaderTransform?t.requestHeaderTransform({...e}):e}};const{v1:me}=ne,{getLDHeaders:he,transformHeaders:ye}=pe;var we=function(e,t,n){const r=I.extend({"Content-Type":"application/json"},he(e,n)),o={};return o.sendEvents=(t,o,i)=>{if(!e.httpRequest)return Promise.resolve();const a=JSON.stringify(t),s=i?null:me();return function t(u){const l=i?r:I.extend({},r,{"X-LaunchDarkly-Event-Schema":"4","X-LaunchDarkly-Payload-ID":s});return e.httpRequest("POST",o,ye(l,n),a).promise.then(e=>{if(e)return e.status>=400&&c.isHttpErrorRecoverable(e.status)&&u?t(!1):function(e){const t={status:e.status},n=e.header("date");if(n){const e=Date.parse(n);e&&(t.serverTime=e)}return t}(e)}).catch(()=>u?t(!1):Promise.reject())}(!0).catch(()=>{})},o};var be=function e(t,n=[]){if(null===t||"object"!=typeof t)return JSON.stringify(t);if(n.includes(t))throw new Error("Cycle detected");if(Array.isArray(t)){return`[${t.map(r=>e(r,[...n,t])).map(e=>void 0===e?"null":e).join(",")}]`}return`{${Object.keys(t).sort().map(r=>{const o=e(t[r],[...n,t]);if(void 0!==o)return`${JSON.stringify(r)}:${o}`}).filter(e=>void 0!==e).join(",")}}`};const{commonBasicLogger:ke}=oe;function Ee(e){return"string"==typeof e&&"kind"!==e&&e.match(/^(\w|\.|-)+$/)}function De(e){return e.includes("%")||e.includes(":")?e.replace(/%/g,"%25").replace(/:/g,"%3A"):e}var xe={checkContext:function(e,t){if(e){if(t&&(void 0===e.kind||null===e.kind))return void 0!==e.key&&null!==e.key;const n=e.key,r=void 0===e.kind?"user":e.kind,o=Ee(r),i="multi"===r||null!=n&&""!==n;if("multi"===r){const t=Object.keys(e).filter(e=>"kind"!==e);return i&&t.every(e=>Ee(e))&&t.every(t=>{const n=e[t].key;return null!=n&&""!==n})}return i&&o}return!1},getContextKeys:function(e,t=ke()){if(!e)return;const n={},{kind:r,key:o}=e;switch(r){case void 0:n.user=`${o}`;break;case"multi":Object.entries(e).filter(([e])=>"kind"!==e).forEach(([e,t])=>{t&&t.key&&(n[e]=t.key)});break;case null:t.warn(`null is not a valid context kind: ${e}`);break;case"":t.warn(`'' is not a valid context kind: ${e}`);break;default:n[r]=`${o}`}return n},getContextKinds:function(e){return e?null===e.kind||void 0===e.kind?["user"]:"multi"!==e.kind?[e.kind]:Object.keys(e).filter(e=>"kind"!==e):[]},getCanonicalKey:function(e){if(e){if((void 0===e.kind||null===e.kind||"user"===e.kind)&&e.key)return e.key;if("multi"!==e.kind&&e.key)return`${e.kind}:${De(e.key)}`;if("multi"===e.kind)return Object.keys(e).sort().filter(e=>"kind"!==e).map(t=>`${t}:${De(e[t].key)}`).join(":")}}};const{getContextKinds:Oe}=xe;var Ce=function(){const e={};let t=0,n=0,r={},o={};return e.summarizeEvent=e=>{if("feature"===e.kind){const i=e.key+":"+(null!==e.variation&&void 0!==e.variation?e.variation:"")+":"+(null!==e.version&&void 0!==e.version?e.version:""),a=r[i];let s=o[e.key];s||(s=new Set,o[e.key]=s),function(e){return e.context?Oe(e.context):e.contextKeys?Object.keys(e.contextKeys):[]}(e).forEach(e=>s.add(e)),a?a.count=a.count+1:r[i]={count:1,key:e.key,version:e.version,variation:e.variation,value:e.value,default:e.default},(0===t||e.creationDate<t)&&(t=e.creationDate),e.creationDate>n&&(n=e.creationDate)}},e.getSummary=()=>{const e={};let i=!0;for(const t of Object.values(r)){let n=e[t.key];n||(n={default:t.default,counters:[],contextKinds:[...o[t.key]]},e[t.key]=n);const r={value:t.value,count:t.count};void 0!==t.variation&&null!==t.variation&&(r.variation=t.variation),void 0!==t.version&&null!==t.version?r.version=t.version:r.unknown=!0,n.counters.push(r),i=!1}return i?null:{startDate:t,endDate:n,features:e,kind:"summary"}},e.clearSummary=()=>{t=0,n=0,r={},o={}},e};var Pe=function(e){let t={},n={};return{summarizeEvent:function(e){if("feature"===e.kind){const r=be(e.context);if(!r)return;let o=t[r];o||(t[r]=Ce(),o=t[r],n[r]=e.context),o.summarizeEvent(e)}},getSummaries:function(){const r=t,o=n;return t={},n={},Object.entries(r).map(([t,n])=>{const r=n.getSummary();return r.context=e.filter(o[t]),r})}}};function Se(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Ie(e){return(e.startsWith("/")?e.substring(1):e).split("/").map(e=>e.indexOf("~")>=0?e.replace(/~1/g,"/").replace(/~0/g,"~"):e)}function Te(e){return!e.startsWith("/")}function Fe(e,t){const n=Te(e),r=Te(t);if(n&&r)return e===t;if(n){const n=Ie(t);return 1===n.length&&e===n[0]}if(r){const n=Ie(e);return 1===n.length&&t===n[0]}return e===t}function Le(e){return`/${Se(e)}`}var Ue={cloneExcluding:function(e,t){const n=[],r={},o=[];for(n.push(...Object.keys(e).map(t=>({key:t,ptr:Le(t),source:e,parent:r,visited:[e]})));n.length;){const e=n.pop();if(t.some(t=>Fe(t,e.ptr)))o.push(e.ptr);else{const t=e.source[e.key];if(null===t)e.parent[e.key]=t;else if(Array.isArray(t))e.parent[e.key]=[...t];else if("object"==typeof t){if(e.visited.includes(t))continue;e.parent[e.key]={},n.push(...Object.keys(t).map(n=>{return{key:n,ptr:(r=e.ptr,o=Se(n),`${r}/${o}`),source:t,parent:e.parent[e.key],visited:[...e.visited,t]};var r,o}))}else e.parent[e.key]=t}}return{cloned:r,excluded:o.sort()}},compare:Fe,literalToReference:Le};var je=function(e){const t={},n=e.allAttributesPrivate,r=e.privateAttributes||[],o=["key","kind","_meta","anonymous"],i=["name","ip","firstName","lastName","email","avatar","country"],a=(e,t)=>{if("object"!=typeof e||null===e||Array.isArray(e))return;const{cloned:i,excluded:a}=Ue.cloneExcluding(e,((e,t)=>(n||t&&e.anonymous?Object.keys(e):[...r,...e._meta&&e._meta.privateAttributes||[]]).filter(e=>!o.some(t=>Ue.compare(e,t))))(e,t));return i.key=String(i.key),a.length&&(i._meta||(i._meta={}),i._meta.redactedAttributes=a),i._meta&&(delete i._meta.privateAttributes,0===Object.keys(i._meta).length&&delete i._meta),void 0!==i.anonymous&&(i.anonymous=!!i.anonymous),i};return t.filter=(e,t=!1)=>void 0===e.kind||null===e.kind?a((e=>{const t={...e.custom||{},kind:"user",key:e.key};void 0!==e.anonymous&&(t.anonymous=!!e.anonymous);for(const n of i)delete t[n],void 0!==e[n]&&null!==e[n]&&(t[n]=String(e[n]));return void 0!==e.privateAttributeNames&&null!==e.privateAttributeNames&&(t._meta=t._meta||{},t._meta.privateAttributes=e.privateAttributeNames.map(e=>e.startsWith("/")?Ue.literalToReference(e):e)),t})(e),t):"multi"===e.kind?((e,t)=>{const n={kind:e.kind},r=Object.keys(e);for(const o of r)if("kind"!==o){const r=a(e[o],t);r&&(n[o]=r)}return n})(e,t):a(e,t),t};const{getContextKeys:Ae}=xe;var Re=function(e,t,n,r=null,o=null,i=null){const a={},s=i||we(e,n,t),u=I.appendUrlPath(t.eventsUrl,"/events/bulk/"+n),l=je(t),d=Pe(l),f=t.samplingInterval,g=t.eventCapacity,v=t.flushInterval,p=t.logger;let m,h=[],y=0,w=!1,b=!1;function k(){return 0===f||0===Math.floor(Math.random()*f)}function E(e){const t=I.extend({},e);return"identify"===e.kind||"feature"===e.kind||"custom"===e.kind?t.context=l.filter(e.context):(t.contextKeys=Ae(e.context,p),delete t.context),"feature"===e.kind&&(delete t.trackEvents,delete t.debugEventsUntilDate),t}function D(e){h.length<g?(h.push(e),b=!1):(b||(b=!0,p.warn(se.eventCapacityExceeded())),r&&r.incrementDroppedEvents())}return a.enqueue=function(e){if(w)return;let t=!1,n=!1;var r;if(d.summarizeEvent(e),"feature"===e.kind?k()&&(t=!!e.trackEvents,n=!!(r=e).debugEventsUntilDate&&r.debugEventsUntilDate>y&&r.debugEventsUntilDate>(new Date).getTime()):t=k(),t&&D(E(e)),n){const t=I.extend({},e,{kind:"debug"});t.context=l.filter(t.context),delete t.trackEvents,delete t.debugEventsUntilDate,D(t)}},a.flush=async function(){if(w)return Promise.resolve();const e=h;return d.getSummaries().forEach(t=>{Object.keys(t.features).length&&e.push(t)}),r&&r.setEventsInLastBatch(e.length),0===e.length?Promise.resolve():(h=[],p.debug(se.debugPostingEvents(e.length)),s.sendEvents(e,u).then(e=>{e&&(e.serverTime&&(y=e.serverTime),c.isHttpErrorRecoverable(e.status)||(w=!0),e.status>=400&&I.onNextTick(()=>{o.maybeReportError(new c.LDUnexpectedResponseError(se.httpErrorMessage(e.status,"event posting","some events were dropped")))}))}))},a.start=function(){const e=()=>{a.flush(),m=setTimeout(e,v)};m=setTimeout(e,v)},a.stop=function(){clearTimeout(m)},a};var Ne=function(e){const t={},n={};return t.on=function(e,t,r){n[e]=n[e]||[],n[e]=n[e].concat({handler:t,context:r})},t.off=function(e,t,r){if(n[e])for(let o=0;o<n[e].length;o++)n[e][o].handler===t&&n[e][o].context===r&&(n[e]=n[e].slice(0,o).concat(n[e].slice(o+1)))},t.emit=function(e){if(!n[e])return;const t=n[e].slice(0);for(let e=0;e<t.length;e++)t[e].handler.apply(t[e].context,Array.prototype.slice.call(arguments,1))},t.getEvents=function(){return Object.keys(n)},t.getEventListenerCount=function(e){return n[e]?n[e].length:0},t.maybeReportError=function(t){t&&(n["error"]?this.emit("error",t):(e||console).error(t.message))},t};const $e="ready",Ve="initialized",He="failed";var Me=function(e){let t=!1,n=!1,r=null,o=null;const i=new Promise(t=>{const n=()=>{e.off($e,n),t()};e.on($e,n)}).catch(()=>{});return{getInitializationPromise:()=>o||(t?Promise.resolve():n?Promise.reject(r):(o=new Promise((t,n)=>{const r=()=>{e.off(Ve,r),t()},o=t=>{e.off(He,o),n(t)};e.on(Ve,r),e.on(He,o)}),o)),getReadyPromise:()=>i,signalSuccess:()=>{t||n||(t=!0,e.emit(Ve),e.emit($e))},signalFailure:o=>{t||n||(n=!0,r=o,e.emit(He,o),e.emit($e)),e.maybeReportError(o)}}};var qe=function(e,t,n,r){const o={};function i(){let e="";const o=r.getContext();return o&&(e=n||I.btoa(JSON.stringify(o))),"ld:"+t+":"+e}return o.loadFlags=()=>e.get(i()).then(e=>{if(null==e)return null;try{let t=JSON.parse(e);if(t){const e=t.$schema;void 0===e||e<1?t=I.transformValuesToVersionedValues(t):delete t.$schema}return t}catch(e){return o.clearFlags().then(()=>null)}}),o.saveFlags=t=>{const n=I.extend({},t,{$schema:1});return e.set(i(),JSON.stringify(n))},o.clearFlags=()=>e.clear(i()),o};var ze=function(e,t){const n={};let r=!1;const o=e=>{r||(r=!0,t.warn(se.localStorageUnavailable(e)))};return n.isEnabled=()=>!!e,n.get=t=>new Promise(n=>{e?e.get(t).then(n).catch(e=>{o(e),n(void 0)}):n(void 0)}),n.set=(t,n)=>new Promise(r=>{e?e.set(t,n).then(()=>r(!0)).catch(e=>{o(e),r(!1)}):r(!1)}),n.clear=t=>new Promise(n=>{e?e.clear(t).then(()=>n(!0)).catch(e=>{o(e),n(!1)}):n(!1)}),n};const{appendUrlPath:Ke,base64URLEncode:_e,objectHasOwnProperty:Je}=I,{getLDHeaders:Be,transformHeaders:We}=pe,{isHttpErrorRecoverable:Ge}=c;var Xe=function(e,t,n,r){const o=t.streamUrl,i=t.logger,a={},s=Ke(o,"/eval/"+n),c=t.useReport,u=t.evaluationReasons,l=t.streamReconnectDelay,d=Be(e,t);let f,g=!1,v=null,p=null,m=null,h=null,y=null,w=0;function b(){const e=(t=function(){const e=l*Math.pow(2,w);return e>3e4?3e4:e}(),t-Math.trunc(.5*Math.random()*t));var t;return w+=1,e}function k(e){if(e.status&&"number"==typeof e.status&&!Ge(e.status))return x(),i.error(se.unrecoverableStreamError(e)),void(p&&(clearTimeout(p),p=null));const t=b();g||(i.warn(se.streamError(e,t)),g=!0),O(!1),x(),E(t)}function E(e){p||(e?p=setTimeout(D,e):D())}function D(){let r;p=null;let a="";const l={headers:d,readTimeoutMillis:3e5};if(e.eventSourceFactory){null!=h&&(a="h="+h),c?e.eventSourceAllowsReport?(r=s,l.method="REPORT",l.headers["Content-Type"]="application/json",l.body=JSON.stringify(m)):(r=Ke(o,"/ping/"+n),a=""):r=s+"/"+_e(JSON.stringify(m)),l.headers=We(l.headers,t),u&&(a=a+(a?"&":"")+"withReasons=true"),r=r+(a?"?":"")+a,x(),i.info(se.streamConnecting(r)),f=(new Date).getTime(),v=e.eventSourceFactory(r,l);for(const e in y)Je(y,e)&&v.addEventListener(e,y[e]);v.onerror=k,v.onopen=()=>{w=0}}}function x(){v&&(i.info(se.streamClosing()),v.close(),v=null)}function O(e){f&&r&&r.recordStreamInit(f,!e,(new Date).getTime()-f),f=null}return a.connect=function(e,t,n){m=e,h=t,y={};for(const e in n||{})y[e]=function(t){g=!1,O(!0),n[e]&&n[e](t)};E()},a.disconnect=function(){clearTimeout(p),p=null,x()},a.isConnected=function(){return!!(v&&e.eventSourceIsActive&&e.eventSourceIsActive(v))},a};var Qe=function(e){let t,n,r,o;const i={addPromise:(i,a)=>{t=i,n&&n(),n=a,i.then(n=>{t===i&&(r(n),e&&e())},n=>{t===i&&(o(n),e&&e())})}};return i.resultPromise=new Promise((e,t)=>{r=e,o=t}),i};const{transformHeaders:Ye,getLDHeaders:Ze}=pe,et="application/json";var tt=function(e,t,n){const r=t.baseUrl,o=t.useReport,i=t.evaluationReasons,a=t.logger,s={},u={};function l(n,r){if(!e.httpRequest)return new Promise((e,t)=>{t(new c.LDFlagFetchError(se.httpUnavailable()))});const o=r?"REPORT":"GET",i=Ze(e,t);r&&(i["Content-Type"]=et);let a=u[n];a||(a=Qe(()=>{delete u[n]}),u[n]=a);const s=e.httpRequest(o,n,Ye(i,t),r),l=s.promise.then(e=>{if(200===e.status){if(e.header("content-type")&&e.header("content-type").substring(0,16)===et)return JSON.parse(e.body);{const t=se.invalidContentType(e.header("content-type")||"");return Promise.reject(new c.LDFlagFetchError(t))}}return Promise.reject(function(e){return 404===e.status?new c.LDInvalidEnvironmentIdError(se.environmentNotFound()):new c.LDFlagFetchError(se.errorFetchingFlags(e.statusText||String(e.status)))}(e))},e=>Promise.reject(new c.LDFlagFetchError(se.networkError(e))));return a.addPromise(l,()=>{s.cancel&&s.cancel()}),a.resultPromise}return s.fetchJSON=function(e){return l(I.appendUrlPath(r,e),null)},s.fetchFlagSettings=function(e,t){let s,c,u,d="";return o?(c=[r,"/sdk/evalx/",n,"/context"].join(""),u=JSON.stringify(e)):(s=I.base64URLEncode(JSON.stringify(e)),c=[r,"/sdk/evalx/",n,"/contexts/",s].join("")),t&&(d="h="+t),i&&(d=d+(d?"&":"")+"withReasons=true"),c=c+(d?"?":"")+d,a.debug(se.debugPolling(c)),l(c,u)},s};var nt=function(e,t){const n={};let r;return n.setContext=function(e){r=I.sanitizeContext(e),r&&t&&t(I.clone(r))},n.getContext=function(){return r?I.clone(r):null},e&&n.setContext(e),n};const{v1:rt}=ne,{getContextKinds:ot}=xe;var it=function(e){function t(e){return null==e||"user"===e?"ld:$anonUserId":`ld:$contextKey:${e}`}function n(n,r){return null!==r.key&&void 0!==r.key?(r.key=r.key.toString(),Promise.resolve(r)):r.anonymous?function(n){return e.get(t(n))}(n).then(o=>{if(o)return r.key=o,r;{const o=rt();return r.key=o,function(n,r){return e.set(t(r),n)}(o,n).then(()=>r)}}):Promise.reject(new c.LDInvalidUserError(se.invalidContext()))}this.processContext=e=>{if(!e)return Promise.reject(new c.LDInvalidUserError(se.contextNotSpecified()));const t=I.clone(e);if("multi"===e.kind){const e=ot(t);return Promise.all(e.map(e=>n(e,t[e]))).then(()=>t)}return n(e.kind,t)}};const{v1:at}=ne,{baseOptionDefs:st}=ge,{appendUrlPath:ct}=I;var ut={DiagnosticId:function(e){const t={diagnosticId:at()};return e&&(t.sdkKeySuffix=e.length>6?e.substring(e.length-6):e),t},DiagnosticsAccumulator:function(e){let t,n,r,o;function i(e){t=e,n=0,r=0,o=[]}return i(e),{getProps:()=>({dataSinceDate:t,droppedEvents:n,eventsInLastBatch:r,streamInits:o}),setProps:e=>{t=e.dataSinceDate,n=e.droppedEvents||0,r=e.eventsInLastBatch||0,o=e.streamInits||[]},incrementDroppedEvents:()=>{n++},setEventsInLastBatch:e=>{r=e},recordStreamInit:(e,t,n)=>{const r={timestamp:e,failed:t,durationMillis:n};o.push(r)},reset:i}},DiagnosticsManager:function(e,t,n,r,o,i,a){const s=!!e.diagnosticUseCombinedEvent,c="ld:"+o+":$diagnostics",u=ct(i.eventsUrl,"/events/diagnostic/"+o),l=i.diagnosticRecordingInterval,d=n;let f,g,v=!!i.streaming;const p={};function m(){return{sdk:w(),configuration:b(),platform:e.diagnosticPlatformData}}function h(e){i.logger&&i.logger.debug(se.debugPostingDiagnosticEvent(e)),r.sendEvents(e,u,!0).then(()=>{}).catch(()=>{})}function y(){h(function(){const e=(new Date).getTime();let t={kind:s?"diagnostic-combined":"diagnostic",id:a,creationDate:e,...d.getProps()};return s&&(t={...t,...m()}),d.reset(e),t}()),g=setTimeout(y,l),f=(new Date).getTime(),s&&function(){if(t.isEnabled()){const e={...d.getProps()};t.set(c,JSON.stringify(e))}}()}function w(){const t={...e.diagnosticSdkData};return i.wrapperName&&(t.wrapperName=i.wrapperName),i.wrapperVersion&&(t.wrapperVersion=i.wrapperVersion),t}function b(){return{customBaseURI:i.baseUrl!==st.baseUrl.default,customStreamURI:i.streamUrl!==st.streamUrl.default,customEventsURI:i.eventsUrl!==st.eventsUrl.default,eventsCapacity:i.eventCapacity,eventsFlushIntervalMillis:i.flushInterval,reconnectTimeMillis:i.streamReconnectDelay,streamingDisabled:!v,allAttributesPrivate:!!i.allAttributesPrivate,diagnosticRecordingIntervalMillis:i.diagnosticRecordingInterval,usingSecureMode:!!i.hash,bootstrapMode:!!i.bootstrap,fetchGoalsDisabled:!i.fetchGoals,sendEventsOnlyForVariation:!!i.sendEventsOnlyForVariation}}return p.start=()=>{s?function(e){if(!t.isEnabled())return e(!1);t.get(c).then(t=>{if(t)try{const e=JSON.parse(t);d.setProps(e),f=e.dataSinceDate}catch(e){}e(!0)}).catch(()=>{e(!1)})}(e=>{if(e){const e=(f||0)+l,t=(new Date).getTime();t>=e?y():g=setTimeout(y,e-t)}else 0===Math.floor(4*Math.random())?y():g=setTimeout(y,l)}):(h({kind:"diagnostic-init",id:a,creationDate:d.getProps().dataSinceDate,...m()}),g=setTimeout(y,l))},p.stop=()=>{g&&clearTimeout(g)},p.setStreaming=e=>{v=e},p}};var lt=function(e,t){let n=!1;const r={type:e.type,name:e.name,synchronous:e.synchronous,method:(...o)=>{try{e.method(...o)}catch{n||(n=!0,t.warn(se.inspectorMethodError(r.type,r.name)))}}};return r};const{onNextTick:dt}=I,ft={flagUsed:"flag-used",flagDetailsChanged:"flag-details-changed",flagDetailChanged:"flag-detail-changed",clientIdentityChanged:"client-identity-changed"};Object.freeze(ft);var gt={InspectorTypes:ft,InspectorManager:function(e,t){const n={},r={[ft.flagUsed]:[],[ft.flagDetailsChanged]:[],[ft.flagDetailChanged]:[],[ft.clientIdentityChanged]:[]},o={[ft.flagUsed]:[],[ft.flagDetailsChanged]:[],[ft.flagDetailChanged]:[],[ft.clientIdentityChanged]:[]},i=e&&e.map(e=>lt(e,t));return i&&i.forEach(e=>{Object.prototype.hasOwnProperty.call(r,e.type)&&!e.synchronous?r[e.type].push(e):Object.prototype.hasOwnProperty.call(o,e.type)&&e.synchronous?o[e.type].push(e):t.warn(se.invalidInspector(e.type,e.name))}),n.hasListeners=e=>r[e]&&r[e].length||o[e]&&o[e].length,n.onFlagUsed=(e,t,n)=>{const i=ft.flagUsed;o[i].length&&o[i].forEach(r=>r.method(e,t,n)),r[i].length&&dt(()=>{r[i].forEach(r=>r.method(e,t,n))})},n.onFlags=e=>{const t=ft.flagDetailsChanged;o[t].length&&o[t].forEach(t=>t.method(e)),r[t].length&&dt(()=>{r[t].forEach(t=>t.method(e))})},n.onFlagChanged=(e,t)=>{const n=ft.flagDetailChanged;o[n].length&&o[n].forEach(n=>n.method(e,t)),r[n].length&&dt(()=>{r[n].forEach(n=>n.method(e,t))})},n.onIdentityChanged=e=>{const t=ft.clientIdentityChanged;o[t].length&&o[t].forEach(t=>t.method(e)),r[t].length&&dt(()=>{r[t].forEach(t=>t.method(e))})},n}};const{LDTimeoutError:vt}=c;var pt=function(e,t){return new Promise((n,r)=>{setTimeout(()=>{r(new vt(`${t} timed out after ${e} seconds.`))},1e3*e)})};const mt="unknown hook";function ht(e,t,n,r,o){try{return r()}catch(r){return e?.error(`An error was encountered in "${t}" of the "${n}" hook: ${r}`),o}}function yt(e,t){try{return t.getMetadata().name||mt}catch{return e.error("Exception thrown getting metadata for hook. Unable to get hook name."),mt}}var wt=function(e,t){const n=t?[...t]:[];return{withEvaluation:function(t,r,o,i){if(0===n.length)return i();const a=[...n],s={flagKey:t,context:r,defaultValue:o},c=function(e,t,n){return t.map(t=>ht(e,"beforeEvaluation",yt(e,t),()=>t?.beforeEvaluation?.(n,{})??{},{}))}(e,a,s),u=i();return function(e,t,n,r,o){for(let i=t.length-1;i>=0;i-=1){const a=t[i],s=r[i];ht(e,"afterEvaluation",yt(e,a),()=>a?.afterEvaluation?.(n,s,o)??{},{})}}(e,a,s,c,u),u},identify:function(t,r){const o=[...n],i={context:t,timeout:r},a=function(e,t,n){return t.map(t=>ht(e,"beforeIdentify",yt(e,t),()=>t?.beforeIdentify?.(n,{})??{},{}))}(e,o,i);return t=>{!function(e,t,n,r,o){for(let i=t.length-1;i>=0;i-=1){const a=t[i],s=r[i];ht(e,"afterIdentify",yt(e,a),()=>a?.afterIdentify?.(n,s,o)??{},{})}}(e,o,i,a,t)}},addHook:function(e){n.push(e)},afterTrack:function(t){if(0===n.length)return;const r=[...n];!function(e,t,n){for(let r=t.length-1;r>=0;r-=1){const o=t[r];ht(e,"afterTrack",yt(e,o),()=>o?.afterTrack?.(n),void 0)}}(e,r,t)}}};var bt=function(){let e,t={};function n(n){return e&&I.objectHasOwnProperty(e,n)&&e[n]?e[n]:t&&I.objectHasOwnProperty(t,n)&&t[n]&&!t[n].deleted?t[n]:null}return{clearAllOverrides:function(){if(!e)return{};const t={...e};return e=void 0,t},get:n,getFlagOverrides:function(){return e||{}},getFlags:function(){return t},getFlagsWithOverrides:function(){const r={};for(const e in t){const t=n(e);t&&(r[e]=t)}if(e)for(const t in e){const e=n(t);e&&(r[t]=e)}return r},removeOverride:function(t){e&&e[t]&&(delete e[t],0===Object.keys(e).length&&(e=void 0))},setFlags:function(e){t={...e}},setOverride:function(t,n){e||(e={}),e[t]={value:n}}}};const kt="unknown plugin";function Et(e,t){try{return t.getMetadata().name||kt}catch(t){return e.error("Exception thrown getting metadata for plugin. Unable to get plugin name."),kt}}var Dt={getPluginHooks:function(e,t,n){const r=[];return n.forEach(n=>{try{const o=n.getHooks?.(t);void 0===o?e.error(`Plugin ${Et(e,n)} returned undefined from getHooks.`):o&&o.length>0&&r.push(...o)}catch(t){e.error(`Exception thrown getting hooks for plugin ${Et(e,n)}. Unable to get hooks.`)}}),r},registerPlugins:function(e,t,n,r){r.forEach(r=>{try{r.register(n,t)}catch(t){e.error(`Exception thrown registering plugin ${Et(e,r)}.`)}})},registerPluginsForDebugOverride:function(e,t,n){n.forEach(n=>{try{n.registerDebug?.(t)}catch(t){e.error(`Exception thrown registering debug override with plugin ${Et(e,n)}.`)}})},createPluginEnvironment:function(e,t,n){const r={};e.userAgent&&(r.name=e.userAgent),e.version&&(r.version=e.version),n.wrapperName&&(r.wrapperName=n.wrapperName),n.wrapperVersion&&(r.wrapperVersion=n.wrapperVersion);const o={};n.application&&(n.application.name&&(o.name=n.application.name),n.application.version&&(o.version=n.application.version));const i={sdk:r,clientSideId:t};return Object.keys(o).length>0&&(i.application=o),i}};const{commonBasicLogger:xt}=oe,{checkContext:Ot,getContextKeys:Ct}=xe,{InspectorTypes:Pt,InspectorManager:St}=gt,{getPluginHooks:It,registerPlugins:Tt,registerPluginsForDebugOverride:Ft,createPluginEnvironment:Lt}=Dt,Ut="change",jt="internal-change";var At={initialize:function(e,t,n,r,o){const i=function(){if(n&&n.logger)return n.logger;return o&&o.logger&&o.logger.default||xt("warn")}(),a=Ne(i),s=Me(a),u=ge.validate(n,a,o,i),l=St(u.inspectors,i),d=u.sendEvents;let f=e,g=u.hash;const v=[...u.plugins],p=Lt(r,e,u),m=It(i,p,v),h=wt(i,[...u.hooks,...m]),y=ze(r.localStorage,i),w=we(r,f,u),b=u.sendEvents&&!u.diagnosticOptOut,k=b?ut.DiagnosticId(f):null,E=b?ut.DiagnosticsAccumulator((new Date).getTime()):null,D=b?ut.DiagnosticsManager(r,y,E,w,f,u,k):null,x=Xe(r,u,f,E),O=u.eventProcessor||Re(r,u,f,E,a,w),C=tt(r,u,f),P=bt();let S,T,F,L=u.streaming,U=!1,j=!1,A=!0;const R=u.stateProvider,N=nt(null,function(e){(function(e){if(R)return;e&&H({kind:"identify",context:e,creationDate:(new Date).getTime()})})(e),l.hasListeners(Pt.clientIdentityChanged)&&l.onIdentityChanged(N.getContext())}),$=new it(y),V=y.isEnabled()?qe(y,f,g,N):null;function H(e){f&&(R&&R.enqueueEvent&&R.enqueueEvent(e)||(e.context?(A=!1,!d||j||r.isDoNotTrack()||(i.debug(se.debugEnqueueingEvent(e.kind)),O.enqueue(e))):A&&(i.warn(se.eventWithoutContext()),A=!1)))}function M(e,t){l.hasListeners(Pt.flagDetailChanged)&&l.onFlagChanged(e.key,J(t))}function q(){l.hasListeners(Pt.flagDetailsChanged)&&l.onFlags(Object.entries(P.getFlagsWithOverrides()).map(([e,t])=>({key:e,detail:J(t)})).reduce((e,t)=>(e[t.key]=t.detail,e),{}))}function z(e,t,n,r){const o=N.getContext(),i=new Date,a={kind:"feature",key:e,context:o,value:t?t.value:null,variation:t?t.variationIndex:null,default:n,creationDate:i.getTime()},s=P.getFlags()[e];s&&(a.version=s.flagVersion?s.flagVersion:s.version,a.trackEvents=s.trackEvents,a.debugEventsUntilDate=s.debugEventsUntilDate),(r||s&&s.trackReason)&&t&&(a.reason=t.reason),H(a)}function K(e){return Ot(e,!1)?Promise.resolve(e):Promise.reject(new c.LDInvalidUserError(se.invalidContext()))}function _(e,t,n,r,o,i){let a;const s=P.get(e);return s?(a=J(s),null!==s.value&&void 0!==s.value||(a.value=t)):a={value:t,variationIndex:null,reason:{kind:"ERROR",errorKind:"FLAG_NOT_FOUND"}},n&&(o||s?.prerequisites?.forEach(e=>{_(e,void 0,n,!1,!1,!1)}),z(e,a,t,r)),!o&&i&&function(e,t){l.hasListeners(Pt.flagUsed)&&l.onFlagUsed(e,t,N.getContext())}(e,a),a}function J(e){return{value:e.value,variationIndex:void 0===e.variation?null:e.variation,reason:e.reason||null}}function B(){if(T=!0,!N.getContext())return;const e=e=>{try{return JSON.parse(e)}catch(e){return void a.maybeReportError(new c.LDInvalidDataError(se.invalidData()))}};x.connect(N.getContext(),g,{ping:function(){i.debug(se.debugStreamPing());const e=N.getContext();C.fetchFlagSettings(e,g).then(t=>{I.deepEquals(e,N.getContext())&&G(t||{})}).catch(e=>{a.maybeReportError(new c.LDFlagFetchError(se.errorFetchingFlags(e)))})},put:function(t){const n=e(t.data);n&&(i.debug(se.debugStreamPut()),G(n))},patch:function(t){const n=e(t.data);if(!n)return;const r=P.getFlags(),o=r[n.key];if(!o||!o.version||!n.version||o.version<n.version){i.debug(se.debugStreamPatch(n.key));const e={},t=I.extend({},n);delete t.key,r[n.key]=t,P.setFlags(r);const a=J(t);e[n.key]=o?{previous:o.value,current:a}:{current:a},M(n,t),X(e)}else i.debug(se.debugStreamPatchIgnored(n.key))},delete:function(t){const n=e(t.data);if(!n)return;const r=P.getFlags();if(!r[n.key]||r[n.key].version<n.version){i.debug(se.debugStreamDelete(n.key));const e={};r[n.key]&&!r[n.key].deleted&&(e[n.key]={previous:r[n.key].value}),r[n.key]={version:n.version,deleted:!0},P.setFlags(r),M(n,r[n.key]),X(e)}else i.debug(se.debugStreamDeleteIgnored(n.key))}})}function W(){T&&(x.disconnect(),T=!1)}function G(e){const t={};if(!e)return Promise.resolve();const n=P.getFlags();for(const r in n)I.objectHasOwnProperty(n,r)&&n[r]&&(e[r]&&!I.deepEquals(e[r].value,n[r].value)?t[r]={previous:n[r].value,current:J(e[r])}:e[r]&&!e[r].deleted||(t[r]={previous:n[r].value}));for(const r in e)I.objectHasOwnProperty(e,r)&&e[r]&&(!n[r]||n[r].deleted)&&(t[r]={current:J(e[r])});return P.setFlags({...e}),q(),X(t).catch(()=>{})}function X(e){const t=Object.keys(e);if(t.length>0){const n={};t.forEach(t=>{const r=e[t].current,o=r?r.value:void 0,i=e[t].previous;a.emit(Ut+":"+t,o,i),n[t]=r?{current:o,previous:i}:{previous:i}}),a.emit(Ut,n),a.emit(jt,P.getFlagsWithOverrides()),u.sendEventsOnlyForVariation||R||t.forEach(t=>{z(t,e[t].current)})}return S&&V?V.saveFlags(P.getFlags()):Promise.resolve()}function Q(){const e=L||F&&void 0===L;e&&!T?B():!e&&T&&W(),D&&D.setStreaming(e)}function Y(e){return e===Ut||e.substr(0,7)===Ut+":"}if("string"==typeof u.bootstrap&&"LOCALSTORAGE"===u.bootstrap.toUpperCase()&&(V?S=!0:i.warn(se.localStorageUnavailable())),"object"==typeof u.bootstrap&&P.setFlags(function(e){const t=Object.keys(e),n="$flagsState",r="$valid",o=e[n];!o&&t.length&&i.warn(se.bootstrapOldFormat()),!1===e[r]&&i.warn(se.bootstrapInvalid());const a={};return t.forEach(t=>{if(t!==n&&t!==r){let n={value:e[t]};o&&o[t]?n=I.extend(n,o[t]):n.version=0,a[t]=n}}),a}(u.bootstrap)),R){const e=R.getInitialState();e?Z(e):R.on("init",Z),R.on("update",function(e){e.context&&N.setContext(e.context);e.flags&&G(e.flags)})}else(function(){if(!e)return Promise.reject(new c.LDInvalidEnvironmentIdError(se.environmentNotSpecified()));let n;return $.processContext(t).then(K).then(e=>(n=I.once(h.identify(e,void 0)),e)).then(e=>(n?.({status:"completed"}),N.setContext(e),"object"==typeof u.bootstrap?ee():S?V.loadFlags().then(e=>null==e?(P.setFlags({}),C.fetchFlagSettings(N.getContext(),g).then(e=>G(e||{})).then(ee).catch(e=>{te(new c.LDFlagFetchError(se.errorFetchingFlags(e)))})):(P.setFlags(e),I.onNextTick(ee),C.fetchFlagSettings(N.getContext(),g).then(e=>G(e)).catch(e=>a.maybeReportError(e)))):C.fetchFlagSettings(N.getContext(),g).then(e=>{P.setFlags(e||{}),q(),ee()}).catch(e=>{P.setFlags({}),te(e)}))).catch(e=>{throw n?.({status:"error"}),e})})().catch(te);function Z(e){f=e.environment,N.setContext(e.context),P.setFlags({...e.flags}),I.onNextTick(ee)}function ee(){i.info(se.clientInitialized()),U=!0,Q(),s.signalSuccess()}function te(e){s.signalFailure(e)}const ne={waitForInitialization:function(e=void 0){if(null!=e){if("number"==typeof e)return function(e){e>5&&i.warn("The waitForInitialization function was called with a timeout greater than 5 seconds. We recommend a timeout of 5 seconds or less.");const t=s.getInitializationPromise(),n=pt(e,"waitForInitialization");return Promise.race([n,t]).catch(e=>{throw e instanceof c.LDTimeoutError&&i.error(`waitForInitialization error: ${e}`),e})}(e);i.warn("The waitForInitialization method was provided with a non-numeric timeout.")}return i.warn("The waitForInitialization function was called without a timeout specified. In a future ver