@launchdarkly/js-client-sdk 0.5.1 → 0.5.3
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 +16 -0
- package/dist/compat.cjs +1 -1
- package/dist/compat.cjs.map +1 -1
- package/dist/compat.js +1 -1
- package/dist/compat.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var bi=Object.defineProperty,Di=Object.defineProperties;var ki=Object.getOwnPropertyDescriptors;var lt=Object.getOwnPropertySymbols;var Ie=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var Re=(i,t,e)=>t in i?bi(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,p=(i,t)=>{for(var e in t||(t={}))Ie.call(t,e)&&Re(i,e,t[e]);if(lt)for(var e of lt(t))Ne.call(t,e)&&Re(i,e,t[e]);return i},b=(i,t)=>Di(i,ki(t));var Nt=(i,t)=>{var e={};for(var n in i)Ie.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&<)for(var n of lt(i))t.indexOf(n)<0&&Ne.call(i,n)&&(e[n]=i[n]);return e};function xi(i){return`/${i.replace(/~/g,"~0").replace(/\//g,"~1")}`}function je(i){return i.indexOf("~")?i.replace(/~1/g,"/").replace(/~0/g,"~"):i}function Si(i){return(i.startsWith("/")?i.substring(1):i).split("/").map(e=>je(e))}function Li(i){return!i.startsWith("/")}function Ai(i){return!i.match(/\/\/|(^\/.*~[^0|^1])|~$/)}var C=class{constructor(t,e=!1){if(e){let n=t;this.a=[n],this.isValid=n!=="",this.redactionName=n.startsWith("/")?xi(n):n}else{if(this.redactionName=t,t===""||t==="/"||!Ai(t)){this.isValid=!1,this.a=[];return}Li(t)?this.a=[t]:t.indexOf("/",1)<0?this.a=[je(t.slice(1))]:this.a=Si(t),this.a[0]==="_meta"?this.isValid=!1:this.isValid=!0}}get(t){let{a:e,isValid:n}=this;if(!n)return;let s=t;for(let r=0;r<e.length;r+=1){let a=e[r];if(s!=null&&Object.prototype.hasOwnProperty.call(s,a)&&typeof s=="object"&&!Array.isArray(s))s=s[a];else return}return s}getComponent(t){return this.a[t]}get depth(){return this.a.length}get isKind(){return this.a.length===1&&this.a[0]==="kind"}compare(t){return this.depth===t.depth&&this.a.every((e,n)=>e===t.getComponent(n))}};C.InvalidReference=new C("");var Ut=class{is(t){if(Array.isArray(t))return!1;let n=typeof t;return n==="function"||n==="object"}getType(){return"factory method or object"}},O=class{constructor(t,e){this.dt=t,this.typeOf=typeof e}is(t){return Array.isArray(t)?!1:typeof t===this.typeOf}getType(){return this.dt}},ft=class{constructor(t,e){this.dt=t,this.typeOf=typeof e}is(t){return Array.isArray(t)?t.length>0?t.every(e=>typeof e===this.typeOf):!0:!1}getType(){return this.dt}},_=class extends O{constructor(t){super(`number with minimum value of ${t}`,0),this.min=t}is(t){return typeof t===this.typeOf&&t>=this.min}},gt=class extends O{constructor(t){super(`string matching ${t}`,""),this.expression=t}is(t){return typeof t=="string"&&!!t.match(this.expression)}},Ft=class{is(t){return typeof t=="function"}getType(){return"function"}},jt=class{is(t){return typeof t=="boolean"||typeof t=="undefined"||t===null}getType(){return"boolean | undefined | null"}},Ci=/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d\d*)?(Z|[-+]\d\d(:\d\d)?)/,Bt=class{is(t){return typeof t=="number"||typeof t=="string"&&Ci.test(t)}getType(){return"date"}},Ht=class extends gt{constructor(){super(/^(\w|\.|-)+$/)}is(t){return super.is(t)&&t!=="kind"}},l=class{static createTypeArray(t,e){return new ft(t,e)}static numberWithMin(t){return new _(t)}static stringMatchingRegex(t){return new gt(t)}};l.String=new O("string","");l.Number=new O("number",0);l.ObjectOrFactory=new Ut;l.Object=new O("object",{});l.StringArray=new ft("string[]","");l.Boolean=new O("boolean",!0);l.Function=new Ft;l.Date=new Bt;l.Kind=new Ht;l.NullableBoolean=new jt;function Be(i){return"kind"in i?l.String.is(i.kind)&&i.kind!=="multi":!1}function He(i){return"kind"in i?l.String.is(i.kind)&&i.kind==="multi":!1}function Ve(i){return!("kind"in i)||i.kind===null||i.kind===void 0}var Vt="user";function Me(i){return i.includes("%")||i.includes(":")?i.replace(/%/g,"%25").replace(/:/g,"%3A"):i}function Oi(i){return i&&l.Object.is(i)}function Pe(i){return l.Kind.is(i)}function Ue(i){return l.String.is(i)&&i!==""}function Mt(i,t=!1){return i?i.map(e=>new C(e,t)):[]}function $i(i){return i!=null}function Ti(i){let t=b(p({},i.custom||[]),{kind:"user",key:String(i.key)});if($i(i.anonymous)){let e=!!i.anonymous;delete t.anonymous,t.anonymous=e}return i.name!==null&&i.name!==void 0&&(t.name=i.name),i.ip!==null&&i.ip!==void 0&&(t.ip=i.ip),i.firstName!==null&&i.firstName!==void 0&&(t.firstName=i.firstName),i.lastName!==null&&i.lastName!==void 0&&(t.lastName=i.lastName),i.email!==null&&i.email!==void 0&&(t.email=i.email),i.avatar!==null&&i.avatar!==void 0&&(t.avatar=i.avatar),i.country!==null&&i.country!==void 0&&(t.country=i.country),i.privateAttributeNames!==null&&i.privateAttributeNames!==void 0&&(t._meta={privateAttributes:i.privateAttributeNames}),t}var k=class i{constructor(t,e,n){this.w=!1,this.q=!1,this.Vt=!1,this.x={},this.kind=e,this.valid=t,this.message=n}static g(t,e){return new i(!1,t,e)}static De(t,e){if(!(!e||!t.isValid))return t.depth===1&&t.getComponent(0)==="anonymous"?!!(e!=null&&e.anonymous):t.get(e)}_t(t){if(this.w)return this.x[t];if(this.kind===t)return this.S}static ke(t){let e=Object.keys(t).filter(c=>c!=="kind"),n=e.every(Pe);if(!e.length)return i.g("multi","A multi-kind context must contain at least one kind");if(!n)return i.g("multi","Context contains invalid kinds");let s={},r=!0,a=e.reduce((c,u)=>{var d;let h=t[u];return Oi(h)?(c[u]=h,s[u]=Mt((d=h._meta)==null?void 0:d.privateAttributes)):r=!1,c},{});if(!r)return i.g("multi","Context contained contexts that were not objects");if(!Object.values(a).every(c=>Ue(c.key)))return i.g("multi","Context contained invalid keys");if(e.length===1){let c=e[0],u=new i(!0,c);return u.S=b(p({},a[c]),{kind:c}),u.J=s,u.q=c==="user",u}let o=new i(!0,t.kind);return o.x=a,o.J=s,o.w=!0,o}static xe(t){var c;let{key:e,kind:n}=t,s=Pe(n),r=Ue(e);if(!s)return i.g(n!=null?n:"unknown","The kind was not valid for the context");if(!r)return i.g(n,"The key for the context was not valid");let a=Mt((c=t._meta)==null?void 0:c.privateAttributes),o=new i(!0,n);return o.q=n==="user",o.S=t,o.J={[n]:a},o}static Se(t){if(!(t.key!==void 0&&t.key!==null))return i.g("user","The key for the context was not valid");let n=new i(!0,"user");return n.q=!0,n.Vt=!0,n.S=Ti(t),n.J={user:Mt(t.privateAttributeNames,!0)},n}static fromLDContext(t){return t?Be(t)?i.xe(t):He(t)?i.ke(t):Ve(t)?i.Se(t):i.g("unknown","Context was not of a valid kind"):i.g("unknown","No context specified. Returning default value")}static toLDContext(t){if(!t.valid)return;let e=t.getContexts();if(!t.w)return e[0][1];let n={kind:"multi"};return e.forEach(s=>{let r=s[0],a=s[1];n[r]=a}),n}valueForKind(t,e=Vt){return t.isKind?this.kinds:i.De(t,this._t(e))}key(t=Vt){var e;return(e=this._t(t))==null?void 0:e.key}get isMultiKind(){return this.w}get canonicalKey(){return this.q?this.S.key:this.w?Object.keys(this.x).sort().map(t=>`${t}:${Me(this.x[t].key)}`).join(":"):`${this.kind}:${Me(this.S.key)}`}get kinds(){return this.w?Object.keys(this.x):[this.kind]}get kindsAndKeys(){return this.w?Object.entries(this.x).reduce((t,[e,n])=>(t[e]=n.key,t),{}):{[this.kind]:this.S.key}}privateAttributes(t){var e;return((e=this.J)==null?void 0:e[t])||[]}getContexts(){return this.w?Object.entries(this.x):[[this.kind,this.S]]}get legacy(){return this.Vt}};k.UserKind=Vt;var Ri=["key","kind","_meta","anonymous"].map(i=>new C(i,!0)),Ii=["name","ip","firstName","lastName","email","avatar","country"];function Ni(i,t){return i.depth===t.length&&t.every((e,n)=>e===i.getComponent(n))}function Mi(i,t){let e=[],n={},s=[];for(e.push(...Object.keys(i).map(r=>({key:r,ptr:[r],source:i,parent:n,visited:[i]})));e.length;){let r=e.pop(),a=t.find(o=>Ni(o,r.ptr));if(a)s.push(a.redactionName);else{let o=r.source[r.key];o===null?r.parent[r.key]=o:Array.isArray(o)?r.parent[r.key]=[...o]:typeof o=="object"?r.visited.includes(o)||(r.parent[r.key]={},e.push(...Object.keys(o).map(c=>({key:c,ptr:[...r.ptr,c],source:o,parent:r.parent[r.key],visited:[...r.visited,o]})))):r.parent[r.key]=o}}return{cloned:n,excluded:s.sort()}}var _t=class{constructor(t,e){this.Le=t,this.Ae=e}filter(t,e=!1){let n=t.getContexts();if(n.length===1)return this.Kt(t,n[0][1],n[0][0],e);let s={kind:"multi"};return n.forEach(([r,a])=>{s[r]=this.Kt(t,a,r,e)}),s}Ce(t,e,n,s){return(s?Object.keys(e).map(r=>new C(r,!0)):[...this.Ae,...t.privateAttributes(n)]).filter(r=>!Ri.some(a=>a.compare(r)))}Kt(t,e,n,s){let r=this.Le||s&&e.anonymous===!0,{cloned:a,excluded:o}=Mi(e,this.Ce(t,e,n,r));return t.legacy&&Ii.forEach(c=>{c in a&&(a[c]=String(a[c]))}),o.length&&(a._meta||(a._meta={}),a._meta.redactedAttributes=o),a._meta&&(delete a._meta.privateAttributes,Object.keys(a._meta).length===0&&delete a._meta),a}},w;(function(i){i.Unknown="UNKNOWN",i.NetworkError="NETWORK_ERROR",i.ErrorResponse="ERROR_RESPONSE",i.InvalidData="INVALID_DATA"})(w||(w={}));var I=class extends Error{constructor(t,e,n,s=!0){super(e),this.kind=t,this.status=n,this.name="LaunchDarklyPollingError",this.recoverable=s}},U=class extends Error{constructor(t,e,n,s=!0){super(e),this.kind=t,this.code=n,this.name="LaunchDarklyStreamingError",this.recoverable=s}},F;(function(i){i[i.Disabled=0]="Disabled",i[i.Enabled=1]="Enabled"})(F||(F={}));var j;(function(i){i[i.AnalyticsEvents=0]="AnalyticsEvents",i[i.DiagnosticEvent=1]="DiagnosticEvent"})(j||(j={}));var R;(function(i){i[i.Succeeded=0]="Succeeded",i[i.Failed=1]="Failed",i[i.FailedAndMustShutDown=2]="FailedAndMustShutDown"})(R||(R={}));function P(i){if(typeof i=="string")return i;if(i===void 0)return"undefined";if(i===null)return"null";if(Object.prototype.hasOwnProperty.call(i,"toString"))try{return i.toString()}catch(t){}if(typeof i=="bigint")return`${i}n`;try{return JSON.stringify(i)}catch(t){return t instanceof TypeError&&t.message.indexOf("circular")>=0?"[Circular]":"[Not Stringifiable]"}}function Pi(i){return typeof i=="symbol"?"NaN":typeof i=="bigint"?`${i}n`:String(Number(i))}function Ui(i){return typeof i=="symbol"?"NaN":typeof i=="bigint"?`${i}n`:String(parseInt(i,10))}function Fi(i){return typeof i=="symbol"?"NaN":String(parseFloat(i))}var ht={s:i=>P(i),d:i=>Pi(i),i:i=>Ui(i),f:i=>Fi(i),j:i=>P(i),o:i=>P(i),O:i=>P(i),c:()=>""};function Kt(...i){var e;let t=i.shift();if(l.String.is(t)){let n="",s=0;for(;s<t.length;){let r=t.charAt(s);if(r==="%"){if(s+1<t.length){let o=t.charAt(s+1);if(o in ht&&i.length){let c=i.shift();n+=(e=ht[o])==null?void 0:e.call(ht,c)}else o==="%"?n+="%":n+=`%${o}`;s+=2}}else n+=r,s+=1}return i.length&&(n.length&&(n+=" "),n+=i.map(P).join(" ")),n}return i.map(P).join(" ")}var v;(function(i){i[i.debug=0]="debug",i[i.info=1]="info",i[i.warn=2]="warn",i[i.error=3]="error",i[i.none=4]="none"})(v||(v={}));var ji=["debug","info","warn","error","none"],N=class i{static get(){return new i({})}constructor(t){var e,n,s;if(this.Oe=(n=v[(e=t.level)!=null?e:"info"])!=null?n:v.info,this.$e=(s=t.name)!=null?s:"LaunchDarkly",this.Gt=t.formatter,typeof t.destination=="object")this.qt={[v.debug]:t.destination.debug,[v.info]:t.destination.info,[v.warn]:t.destination.warn,[v.error]:t.destination.error};else if(typeof t.destination=="function"){let{destination:r}=t;this.qt={[v.debug]:r,[v.info]:r,[v.warn]:r,[v.error]:r}}}Te(...t){var e;try{return this.Gt?(e=this.Gt)==null?void 0:e.call(this,...t):Kt(...t)}catch(n){return Kt(...t)}}Re(t,e){try{t(e)}catch(n){console.error(e)}}p(t,e){var n;if(t>=this.Oe){let s=`${ji[t]}: [${this.$e}]`;try{let r=(n=this.qt)==null?void 0:n[t];r?this.Re(r,`${s} ${this.Te(...e)}`):console.error(...e)}catch(r){console.error(...e)}}}error(...t){this.p(v.error,t)}warn(...t){this.p(v.warn,t)}info(...t){this.p(v.info,t)}debug(...t){this.p(v.debug,t)}},Bi={error:l.Function,warn:l.Function,info:l.Function,debug:l.Function},K=class{constructor(t,e){Object.entries(Bi).forEach(([n,s])=>{if(!s.is(t[n]))throw new Error(`Provided logger instance must support logger.${n}(...) method`)}),this.t=t,this.Ie=e}p(t,e){try{this.t[t](...e)}catch(n){this.Ie[t](...e)}}error(...t){this.p("error",t)}warn(...t){this.p("warn",t)}info(...t){this.p("info",t)}debug(...t){this.p("debug",t)}},ne=i=>{let t=new N({level:"info",destination:console.error,formatter:Kt});return i?new K(i,t):t},D=class{static deprecated(t,e){return`"${t}" is deprecated, please use "${e}"`}static optionBelowMinimum(t,e,n){return`Config option "${t}" had invalid value of ${e}, using minimum of ${n} instead`}static unknownOption(t){return`Ignoring unknown config option "${t}"`}static wrongOptionType(t,e,n){return`Config option "${t}" should be of type ${e}, got ${n}, using default value`}static wrongOptionTypeBoolean(t,e){return`Config option "${t}" should be a boolean, got ${e}, converting to boolean`}static invalidTagValue(t){return`Config option "${t}" must only contain letters, numbers, ., _ or -.`}static tagValueTooLong(t){return`Value of "${t}" was longer than 64 characters and was discarded.`}static partialEndpoint(t){return`You have set custom uris without specifying the ${t} URI; connections may not work properly`}},Hi=/^(\w|\.|-)+$/,Vi=l.stringMatchingRegex(Hi),_i={is:(i,t)=>Vi.is(i)?i.length>64?{valid:!1,message:D.tagValueTooLong(t)}:{valid:!0}:{valid:!1,message:D.invalidTagValue(t)}},pt=class{constructor(t){let e={},n=t==null?void 0:t.application,s=t==null?void 0:t.logger;n&&Object.entries(n).forEach(([a,o])=>{if(o!=null){let{valid:c,message:u}=_i.is(o,`application.${a}`);c?a==="versionName"?e["application-version-name"]=[o]:e[`application-${a}`]=[o]:s==null||s.warn(u)}});let r=Object.keys(e);r.length&&(this.value=r.sort().flatMap(a=>e[a].sort().map(o=>`${a}/${o}`)).join(" "))}},mt=class{constructor(t,e,n){this.platform=n,this.basicConfiguration={tags:e.tags,logger:e.logger,offline:e.offline,serviceEndpoints:e.serviceEndpoints,sdkKey:t}}};function Pt(i){return i.replace(/\/+$/,"")}function se(i){return i.replace(/^\/+/,"").replace(/\?$/,"")}var M=class i{constructor(t,e,n=i.DEFAULT_EVENTS,s="/bulk",r="/diagnostic",a=!0,o){this.streaming=Pt(t),this.polling=Pt(e),this.events=Pt(n),this.analyticsEventPath=s,this.diagnosticEventPath=r,this.includeAuthorizationHeader=a,this.payloadFilterKey=o}};M.DEFAULT_EVENTS="https://events.launchdarkly.com";function re(i,t){if(t.length===0)return i;let e=t.map(({key:n,value:s})=>`${n}=${s}`);return`${i}?${e.join("&")}`}function _e(i,t,e){let n=se(t),s=[...e];return i.payloadFilterKey&&s.push({key:"filter",value:i.payloadFilterKey}),re(`${i.streaming}/${n}`,s)}function Ke(i,t,e){let n=se(t),s=[...e];return i.payloadFilterKey&&s.push({key:"filter",value:i.payloadFilterKey}),re(`${i.polling}/${n}`,s)}function Fe(i,t,e){let n=se(t);return re(`${i.events}/${n}`,e)}var G=class extends Error{constructor(t){super(t),this.name="LaunchDarklyUnexpectedResponseError"}},q=class extends Error{constructor(t){super(t),this.name="LaunchDarklyClientError"}},Gt=class extends Error{constructor(t){super(t),this.name="LaunchDarklyTimeoutError"}};function z(i){return i>=400&&i<500?i===400||i===408||i===429:!0}function Ki(i){return i===413?!0:z(i)}function ae(i){return i==null?i:JSON.parse(JSON.stringify(i))}function Et(i){return Math.trunc(i*1e3)}var Gi=i=>JSON.stringify(i)==="{}",bt=(i,t)=>i&&Object.entries(i).reduce((e,[n,s])=>(s&&!Gi(s)&&!(t!=null&&t.includes(n))&&(e[n]=typeof s=="object"?bt(s,t):s),e),{});function V(i,t){if(i===t)return!0;if(i&&t&&typeof i=="object"&&typeof t=="object"){if(i.constructor!==t.constructor)return!1;var e,n,s;if(Array.isArray(i)){if(e=i.length,e!=t.length)return!1;for(n=e;n--!==0;)if(!V(i[n],t[n]))return!1;return!0}if(i instanceof Map&&t instanceof Map){if(i.size!==t.size)return!1;for(n of i.entries())if(!t.has(n[0]))return!1;for(n of i.entries())if(!V(n[1],t.get(n[0])))return!1;return!0}if(i instanceof Set&&t instanceof Set){if(i.size!==t.size)return!1;for(n of i.entries())if(!t.has(n[0]))return!1;return!0}if(ArrayBuffer.isView(i)&&ArrayBuffer.isView(t)){if(e=i.length,e!=t.length)return!1;for(n=e;n--!==0;)if(i[n]!==t[n])return!1;return!0}if(i.constructor===RegExp)return i.source===t.source&&i.flags===t.flags;if(i.valueOf!==Object.prototype.valueOf)return i.valueOf()===t.valueOf();if(i.toString!==Object.prototype.toString)return i.toString()===t.toString();if(s=Object.keys(i),e=s.length,e!==Object.keys(t).length)return!1;for(n=e;n--!==0;)if(!Object.prototype.hasOwnProperty.call(t,s[n]))return!1;for(n=e;n--!==0;){var r=s[n];if(!V(i[r],t[r]))return!1}return!0}return i!==i&&t!==t}function Ge(i,t,e,n=!0,s="user-agent"){let{userAgentBase:r,version:a,wrapperName:o,wrapperVersion:c}=t.sdkData(),u={[s]:`${r!=null?r:"NodeJSClient"}/${a}`};return n&&(u.authorization=i),o&&(u["x-launchdarkly-wrapper"]=c?`${o}/${c}`:o),e!=null&&e.value&&(u["x-launchdarkly-tags"]=e.value),u}function B(i,t,e){let n;i.status?n=`error ${i.status}${i.status===401?" (invalid SDK key)":""}`:n=`I/O error (${i.message||"unknown error"})`;let s=e!=null?e:"giving up permanently";return`Received ${n} for ${t} - ${s}`}function qe({status:i}){return i?z(i):!0}var oe=(i,t)=>t.btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");var qi=async(i=1e3)=>new Promise(t=>{setTimeout(t,i)}),Je=(i,t)=>new Promise((e,n)=>{setTimeout(()=>{let s=`${t} timed out after ${i} seconds.`;n(new Gt(s))},i*1e3)}),qt=class{constructor(t,e,n){this.r=e,this.Ne=n,this.ft=[],this.Jt=Date.now(),this.zt=this.Jt,this.Wt={diagnosticId:e.crypto.randomUUID(),sdkKeySuffix:t.length>6?t.substring(t.length-6):t}}createInitEvent(){var n,s,r;let t=this.r.info.sdkData(),e=this.r.info.platformData();return{kind:"diagnostic-init",id:this.Wt,creationDate:this.Jt,sdk:t,configuration:this.Ne,platform:p({name:e.name,osArch:(n=e.os)==null?void 0:n.arch,osName:(s=e.os)==null?void 0:s.name,osVersion:(r=e.os)==null?void 0:r.version},e.additional||{})}}recordStreamInit(t,e,n){let s={timestamp:t,failed:e,durationMillis:n};this.ft.push(s)}createStatsEventAndReset(t,e,n){let s=Date.now(),r={kind:"diagnostic",id:this.Wt,creationDate:s,dataSinceDate:this.zt,droppedEvents:t,deduplicatedUsers:e,eventsInLastBatch:n,streamInits:this.ft};return this.ft=[],this.zt=s,r}},Jt;(function(i){i.MalformedFlag="MALFORMED_FLAG",i.UserNotSpecified="USER_NOT_SPECIFIED",i.FlagNotFound="FLAG_NOT_FOUND",i.ClientNotReady="CLIENT_NOT_READY",i.WrongType="WRONG_TYPE"})(Jt||(Jt={}));var Ji=Jt,yt=class{static invalidMetricValue(t){return`The track function was called with a non-numeric "metricValue" (${t}), only numeric metric values are supported.`}};yt.MissingContextKeyNoEvent="Context was unspecified or had no key; event will not be sent";var zt=class{constructor(t,e){let{basicConfiguration:n,platform:s}=t,{serviceEndpoints:{analyticsEventPath:r,diagnosticEventPath:a}}=n,{crypto:o,requests:c}=s;this.Me=p({},e),this.Yt=Fe(n.serviceEndpoints,r,[]),this.Pe=Fe(n.serviceEndpoints,a,[]),this.E=c,this.Ue=o}async z(t,e,n,s){let r={status:R.Succeeded},a=b(p({},this.Me),{"content-type":"application/json"});n&&(a["x-launchdarkly-payload-id"]=n,a["x-launchDarkly-event-schema"]="4");let o;try{let{status:c,headers:u}=await this.E.fetch(e,{headers:a,body:JSON.stringify(t),compressBodyIfPossible:!0,method:"POST",keepalive:!0}),h=Date.parse(u.get("date")||"");if(h&&(r.serverTime=h),c<=204)return r;if(o=new G(B({status:c,message:"some events were dropped"},"event posting")),!z(c))return Ki(c)?r.status=R.Failed:r.status=R.FailedAndMustShutDown,r.error=o,r}catch(c){o=c}return o&&!s?(r.status=R.Failed,r.error=o,r):(await qi(),this.z(t,this.Yt,n,!1))}async sendEventData(t,e){let n=t===j.AnalyticsEvents?this.Ue.randomUUID():void 0,s=t===j.AnalyticsEvents?this.Yt:this.Pe;return this.z(e,s,n,!0)}};function Wt(i){return i.kind==="feature"}function zi(i){return i.kind==="identify"}function Wi(i){return i.kind==="migration_op"}var Yt=class{constructor(t,e,n,s,r,a){this.count=t,this.key=e,this.value=n,this.version=r,this.variation=a,this.default=s}increment(){this.count+=1}};function Yi(i){return`${i.key}:${i.variation!==null&&i.variation!==void 0?i.variation:""}:${i.version!==null&&i.version!==void 0?i.version:""}`}var Xt=class{constructor(){this.P=0,this.W=0,this.Y={},this.X={}}summarizeEvent(t){if(Wt(t)&&!t.excludeFromSummaries){let e=Yi(t),n=this.Y[e],s=this.X[t.key];s||(s=new Set,this.X[t.key]=s),t.context.kinds.forEach(r=>s.add(r)),n?n.increment():this.Y[e]=new Yt(1,t.key,t.value,t.default,t.version,t.variation),(this.P===0||t.creationDate<this.P)&&(this.P=t.creationDate),t.creationDate>this.W&&(this.W=t.creationDate)}}getSummary(){let t=Object.values(this.Y).reduce((e,n)=>{let s=e[n.key];s||(s={default:n.default,counters:[],contextKinds:[...this.X[n.key]]},e[n.key]=s);let r={value:n.value,count:n.count};return n.variation!==void 0&&n.variation!==null&&(r.variation=n.variation),n.version!==void 0&&n.version!==null?r.version=n.version:r.unknown=!0,s.counters.push(r),e},{});return{startDate:this.P,endDate:this.W,features:t,kind:"summary"}}clearSummary(){this.P=0,this.W=0,this.Y={},this.X={}}},Zt=class extends Error{constructor(t){super(t),this.name="LaunchDarklyInvalidSDKKeyError"}};function dt(i){let t=Math.trunc(i);return t===1?!0:t===0?!1:Math.floor(Math.random()*t)===0}var Qt=class{constructor(t,e,n,s,r,a=!0){this.n=t,this.Z=s,this.m=r,this.gt=new Xt,this.Q=[],this.Xt=0,this.pt=0,this.mt=0,this.yt=!1,this.Zt=0,this.vt=!1,this.wt=null,this.Fe=t.eventsCapacity,this.t=e.basicConfiguration.logger,this.Qt=new zt(e,n),this.tt=new _t(t.allAttributesPrivate,t.privateAttributes.map(o=>new C(o))),a&&this.start()}start(){var t,e;if(((t=this.Z)==null?void 0:t.flushInterval)!==void 0&&(this.wt=setInterval(()=>{var n;(n=this.Z)==null||n.flush()},this.Z.flushInterval*1e3)),this.je=setInterval(async()=>{var n;try{await this.flush()}catch(s){(n=this.t)==null||n.debug(`Flush failed: ${s}`)}},this.n.flushInterval*1e3),this.m){let n=this.m.createInitEvent();this.te(n),this.ee=setInterval(()=>{let s=this.m.createStatsEventAndReset(this.pt,this.mt,this.Zt);this.pt=0,this.mt=0,this.te(s)},this.n.diagnosticRecordingInterval*1e3)}(e=this.t)==null||e.debug("Started EventProcessor.")}te(t){this.Qt.sendEventData(j.DiagnosticEvent,t)}close(){clearInterval(this.je),this.wt&&clearInterval(this.wt),this.ee&&clearInterval(this.ee)}async flush(){var n;if(this.vt)throw new Zt("Events cannot be posted because a permanent error has been encountered. This is most likely an invalid SDK key. The specific error information is logged independently.");let t=this.Q;this.Q=[];let e=this.gt.getSummary();this.gt.clearSummary(),Object.keys(e.features).length&&t.push(e),t.length&&(this.Zt=t.length,(n=this.t)==null||n.debug("Flushing %d events",t.length),await this.z(t))}sendEvent(t){var c;if(this.vt)return;if(Wi(t)){if(dt(t.samplingRatio)){let u=b(p({},t),{context:t.context?this.tt.filter(t.context):void 0});u.samplingRatio===1&&delete u.samplingRatio,this.et(u)}return}this.gt.summarizeEvent(t);let e=Wt(t),n=e&&t.trackEvents||!e,s=this.Be(t),r=zi(t),a=(c=this.Z)==null?void 0:c.processContext(t.context);a||r||(this.mt+=1),a&&!r&&this.et(this.Et({kind:"index",creationDate:t.creationDate,context:t.context,samplingRatio:1},!1)),n&&dt(t.samplingRatio)&&this.et(this.Et(t,!1)),s&&dt(t.samplingRatio)&&this.et(this.Et(t,!0))}Et(t,e){switch(t.kind){case"feature":{let n={kind:e?"debug":"feature",creationDate:t.creationDate,context:this.tt.filter(t.context,!e),key:t.key,value:t.value,default:t.default};return t.samplingRatio!==1&&(n.samplingRatio=t.samplingRatio),t.prereqOf&&(n.prereqOf=t.prereqOf),t.variation!==void 0&&(n.variation=t.variation),t.version!==void 0&&(n.version=t.version),t.reason&&(n.reason=t.reason),n}case"index":case"identify":{let n={kind:t.kind,creationDate:t.creationDate,context:this.tt.filter(t.context)};return t.samplingRatio!==1&&(n.samplingRatio=t.samplingRatio),n}case"custom":{let n={kind:"custom",creationDate:t.creationDate,key:t.key,context:this.tt.filter(t.context)};return t.samplingRatio!==1&&(n.samplingRatio=t.samplingRatio),t.data!==void 0&&(n.data=t.data),t.metricValue!==void 0&&(n.metricValue=t.metricValue),t.url!==void 0&&(n.url=t.url),n}case"click":return{kind:"click",creationDate:t.creationDate,contextKeys:t.context.kindsAndKeys,key:t.key,url:t.url,selector:t.selector};case"pageview":return{kind:"pageview",creationDate:t.creationDate,contextKeys:t.context.kindsAndKeys,key:t.key,url:t.url};default:return t}}et(t){var e;this.Q.length<this.Fe?(this.Q.push(t),this.yt=!1):(this.yt||(this.yt=!0,(e=this.t)==null||e.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),this.pt+=1)}Be(t){return Wt(t)&&t.debugEventsUntilDate&&t.debugEventsUntilDate>this.Xt&&t.debugEventsUntilDate>Date.now()}async z(t){let e=await this.Qt.sendEventData(j.AnalyticsEvents,t);if(e.status===R.FailedAndMustShutDown&&(this.vt=!0),e.serverTime&&(this.Xt=e.serverTime),e.error)throw e.error}},vt=class{constructor(t,e,n,s,r=1,a){this.context=t,this.key=e,this.data=n,this.metricValue=s,this.samplingRatio=r,this.url=a,this.kind="custom",this.creationDate=Date.now(),this.context=t}},J=class{constructor(t,e,n,s,r,a,o,c,u,h,d,f,g=1){this.withReasons=t,this.context=e,this.key=n,this.samplingRatio=g,this.kind="feature",this.creationDate=Date.now(),this.value=s,this.default=r,a!==void 0&&(this.version=a),o!==void 0&&(this.variation=o),c!==void 0&&(this.trackEvents=c),u!==void 0&&(this.prereqOf=u),h!==void 0&&(this.reason=h),d!==void 0&&(this.debugEventsUntilDate=d),f!==void 0&&(this.excludeFromSummaries=f)}},wt=class{constructor(t,e=1){this.context=t,this.samplingRatio=e,this.kind="identify",this.creationDate=Date.now()}},te=class{close(){}async flush(){}sendEvent(){}},ee=class{constructor(t){this.bt=t}evalEvent(t){var e;return new J(this.bt,t.context,t.flagKey,t.value,t.defaultVal,t.version,(e=t.variation)!=null?e:void 0,t.trackEvents||t.addExperimentData,t.prereqOfFlagKey,this.bt||t.addExperimentData?t.reason:void 0,t.debugEventsUntilDate,t.excludeFromSummaries,t.samplingRatio)}unknownFlagEvent(t,e,n){return new J(this.bt,n,t,e,e,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0)}identifyEvent(t){return new wt(t,1)}customEvent(t,e,n,s,r=1){return new vt(e,t,n!=null?n:void 0,s!=null?s:void 0,r)}},ie=class{constructor(t,e,n,s){this.He=e,this.u=n,this.t=s,this.e=[],this.L=void 0,this.U=void 0,this.it=[],this.Ve=r=>{if(this.F(),!r.payloads.length)return;let a=r.payloads[0];switch(a==null?void 0:a.code){case"xfer-full":this.U=!0;break;case"xfer-changes":case"none":this.U=!1;break;default:return}this.L=a==null?void 0:a.id},this._e=r=>{var o;if(!this.L||!r.kind||!r.key||!r.version||!r.object)return;let a=this.Ke(r.kind,r.object);if(!a){(o=this.t)==null||o.warn(`Unable to prcoess object for kind: '${r.kind}'`);return}this.it.push({kind:r.kind,key:r.key,version:r.version,object:a})},this.Ge=r=>{!this.L||!r.kind||!r.key||!r.version||this.it.push({kind:r.kind,key:r.key,version:r.version,deleted:!0})},this.qe=r=>{if(!this.L||!r.state||!r.version||this.U===void 0){this.F();return}let a={id:this.L,version:r.version,state:r.state,basis:this.U,updates:this.it};this.e.forEach(o=>o(a)),this.F()},this.Je=r=>{var a;(a=this.t)==null||a.info(`Goodbye was received from the LaunchDarkly connection with reason: ${r.reason}.`),this.F()},this.ze=r=>{var a;(a=this.t)==null||a.info(`An issue was encountered receiving updates for payload ${this.L} with reason: ${r.reason}. Automatic retry will occur.`),this.F()},this.A(t,"server-intent",this.Ve),this.A(t,"put-object",this._e),this.A(t,"delete-object",this.Ge),this.A(t,"payload-transferred",this.qe),this.A(t,"goodbye",this.Je),this.A(t,"error",this.ze)}addPayloadListener(t){this.e.push(t)}removePayloadListener(t){let e=this.e.indexOf(t,0);e>-1&&this.e.splice(e,1)}A(t,e,n){t.addEventListener(e,async s=>{var r,a,o,c,u;if(s!=null&&s.data){(r=this.t)==null||r.debug(`Received ${e} event. Data is ${s.data}`);try{n(JSON.parse(s.data))}catch(h){(a=this.t)==null||a.error(`Stream received data that was unable to be processed in "${e}" message`),(o=this.t)==null||o.debug(`Data follows: ${s.data}`),(c=this.u)==null||c.call(this,w.InvalidData,"Malformed data in event stream")}}else(u=this.u)==null||u.call(this,w.Unknown,"Unexpected message from event stream")})}Ke(t,e){var n,s;return(s=(n=this.He)[t])==null?void 0:s.call(n,e)}F(){this.L=void 0,this.U=void 0,this.it=[]}},S=Object.freeze({__proto__:null,ClientMessages:yt,DiagnosticsManager:qt,ErrorKinds:Ji,EventFactoryBase:ee,EventProcessor:Qt,InputCustomEvent:vt,InputEvalEvent:J,InputIdentifyEvent:wt,NullEventProcessor:te,PayloadReader:ie,isLegacyUser:Ve,isMultiKind:He,isSingleKind:Be,shouldSample:dt});var E;(function(i){i.Initializing="INITIALIZING",i.Valid="VALID",i.Interrupted="INTERRUPTED",i.SetOffline="SET_OFFLINE",i.Closed="CLOSED"})(E||(E={}));function Zi(i){return i>=200&&i<=299}var Dt=class extends Error{constructor(t,e){super(t),this.status=e,this.name="LaunchDarklyRequestError"}},de=class{constructor(t,e,n,s,r){this.E=t,this.We=e,this.nt=n,this.Ye=s,this.Xe=r}async requestPayload(){let t;try{let e=await this.E.fetch(this.We,{method:this.Ye,headers:this.nt,body:this.Xe});if(Zi(e.status))return await e.text();t=e.status}catch(e){throw new Dt(e==null?void 0:e.message)}throw new Dt(`Unexpected status code: ${t}`,t)}};function Se(i,t,e,n,s,r,a,o,c,u){let h,d="GET",f=p({},r);c&&(d="REPORT",f["content-type"]="application/json",h=i);let g=c?e.pathReport(s,i):e.pathGet(s,i),m=[...a!=null?a:[]];o&&m.push({key:"withReasons",value:"true"}),u&&m.push({key:"h",value:u});let y=Ke(t,g,m);return new de(n,y,f,d,h)}var Qi={logger:l.Object,maxCachedContexts:l.numberWithMin(0),baseUri:l.String,streamUri:l.String,eventsUri:l.String,capacity:l.numberWithMin(1),diagnosticRecordingInterval:l.numberWithMin(2),flushInterval:l.numberWithMin(2),streamInitialReconnectDelay:l.numberWithMin(0),allAttributesPrivate:l.Boolean,debug:l.Boolean,diagnosticOptOut:l.Boolean,withReasons:l.Boolean,sendEvents:l.Boolean,pollInterval:l.numberWithMin(30),useReport:l.Boolean,privateAttributes:l.StringArray,applicationInfo:l.Object,wrapperName:l.String,wrapperVersion:l.String,payloadFilterKey:l.stringMatchingRegex(/^[a-zA-Z0-9](\w|\.|-)*$/),hooks:l.createTypeArray("Hook[]",{}),inspectors:l.createTypeArray("LDInspection",{})},tn=60*5,Ze="https://clientsdk.launchdarkly.com",Qe="https://clientstream.launchdarkly.com";function en(i){return i instanceof K?i:ne(i)}var fe=class{constructor(t={},e={}){var s,r,a;this.logger=ne(),this.baseUri=Ze,this.eventsUri=M.DEFAULT_EVENTS,this.streamUri=Qe,this.maxCachedContexts=5,this.capacity=100,this.diagnosticRecordingInterval=900,this.flushInterval=30,this.streamInitialReconnectDelay=1,this.allAttributesPrivate=!1,this.debug=!1,this.diagnosticOptOut=!1,this.sendEvents=!0,this.sendLDHeaders=!0,this.useReport=!1,this.withReasons=!1,this.privateAttributes=[],this.pollInterval=tn,this.hooks=[],this.inspectors=[],this.logger=en(t.logger),this.Ze(t).forEach(o=>this.logger.warn(o)),this.serviceEndpoints=new M(this.streamUri,this.baseUri,this.eventsUri,e.analyticsEventPath,e.diagnosticEventPath,e.includeAuthorizationHeader,t.payloadFilterKey),this.useReport=(s=t.useReport)!=null?s:!1,this.tags=new pt({application:this.applicationInfo,logger:this.logger}),this.userAgentHeaderName=(r=e.userAgentHeaderName)!=null?r:"user-agent",this.trackEventModifier=(a=e.trackEventModifier)!=null?a:o=>o}Ze(t){let e=[];return Object.entries(t).forEach(([n,s])=>{let r=Qi[n];if(r)if(r.is(s))n==="logger"||(this[n]=s!=null?s:void 0);else{let a=r.getType();if(a==="boolean")e.push(D.wrongOptionTypeBoolean(n,typeof s)),this[n]=!!s;else if(a==="boolean | undefined | null")e.push(D.wrongOptionTypeBoolean(n,typeof s)),typeof s!="boolean"&&typeof s!="undefined"&&s!==null&&(this[n]=!!s);else if(r instanceof _&&l.Number.is(s)){let{min:o}=r;e.push(D.optionBelowMinimum(n,s,o)),this[n]=o}else e.push(D.wrongOptionType(n,r.getType(),typeof s))}else e.push(D.unknownOption(n))}),e}};async function ti(i,t){if(i.digest)return i.digest(t);if(i.asyncDigest)return i.asyncDigest(t);throw new Error("Platform must implement digest or asyncDigest")}var ei=async(i,{crypto:t,storage:e})=>{let n=await(e==null?void 0:e.get(i));return n||(n=t.randomUUID(),await(e==null?void 0:e.set(i,n))),n};function ii(i){return async t=>ti(i.createHash("sha256").update(t),"base64")}var x=async i=>i;async function Y(i){return(await Promise.all(i.map(e=>e.transform(e.value)))).join("_")}async function nn(i,t){return Y([{value:"LaunchDarkly",transform:x},{value:t,transform:ii(i)}])}async function sn(i){return Y([{value:"LaunchDarkly",transform:x},{value:"AnonymousKeys",transform:x},{value:i,transform:x}])}async function rn(i){return Y([{value:"LaunchDarkly",transform:x},{value:"ContextKeys",transform:x},{value:i,transform:x}])}async function an(i){return Y([{value:i,transform:x},{value:"ContextIndex",transform:x}])}async function ze(i,t,e){return Y([{value:t,transform:x},{value:e.canonicalKey,transform:ii(i)}])}var{isLegacyUser:on,isSingleKind:ce,isMultiKind:We}=S,ni="1.0",cn=i=>{let n=i,{kind:t}=n,e=Nt(n,["kind"]);return{kind:"multi",[t]:e}},un=async({crypto:i,info:t},{applicationInfo:e})=>{var a;let{ld_application:n}=t.platformData(),s=(a=bt(n))!=null?a:{},r=(e==null?void 0:e.id)||(s==null?void 0:s.id);if(r){let o=(e==null?void 0:e.version)||(s==null?void 0:s.version),c=(e==null?void 0:e.name)||(s==null?void 0:s.name),u=(e==null?void 0:e.versionName)||(s==null?void 0:s.versionName);return s=p(p(p(b(p({},s),{id:r}),o?{version:o}:{}),c?{name:c}:{}),u?{versionName:u}:{}),s.key=await ti(i.createHash("sha256").update(r),"base64"),s.envAttributesVersion=s.envAttributesVersion||ni,s}},ln=async i=>{var o,c,u,h;let{ld_device:t,os:e}=i.info.platformData(),n=(o=bt(t))!=null?o:{},s=(e==null?void 0:e.name)||((c=n.os)==null?void 0:c.name),r=(e==null?void 0:e.version)||((u=n.os)==null?void 0:u.version),a=(h=n.os)==null?void 0:h.family;if((s||r||a)&&(n.os=p(p(p({},s?{name:s}:{}),r?{version:r}:{}),a?{family:a}:{})),Object.keys(n).filter(d=>d!=="key"&&d!=="envAttributesVersion").length){let d=await rn("ld_device");return n.key=await ei(d,i),n.envAttributesVersion=n.envAttributesVersion||ni,n}},hn=async(i,t,e)=>{if(on(i))return i;let n,s;if(ce(i)&&i.kind!=="ld_application"||We(i)&&!i.ld_application?n=await un(t,e):e.logger.warn("Not adding ld_application environment attributes because it already exists."),ce(i)&&i.kind!=="ld_device"||We(i)&&!i.ld_device?s=await ln(t):e.logger.warn("Not adding ld_device environment attributes because it already exists."),n||s){let r=ce(i)?cn(i):i;return p(p(p({},r),n?{ld_application:n}:{}),s?{ld_device:s}:{})}return i},{isLegacyUser:dn,isMultiKind:fn,isSingleKind:gn}=S,Le=async(i,t,e)=>{let{anonymous:n,key:s}=t;if(n&&!s){let r=await sn(i);t.key=await ei(r,e)}},pn=async(i,t)=>{await Le(i.kind,i,t)},mn=async(i,t)=>{let s=i,{kind:e}=s,n=Nt(s,["kind"]);return Promise.all(Object.entries(n).map(([r,a])=>Le(r,a,t)))},yn=async(i,t)=>{await Le("user",i,t)},vn=async(i,t)=>{let e=ae(i);return gn(e)&&await pn(e,t),fn(e)&&await mn(e,t),dn(e)&&await yn(e,t),e},wn=i=>({customBaseURI:i.serviceEndpoints.polling!==Ze,customStreamURI:i.serviceEndpoints.streaming!==Qe,customEventsURI:i.serviceEndpoints.events!==M.DEFAULT_EVENTS,eventsCapacity:i.capacity,eventsFlushIntervalMillis:Et(i.flushInterval),reconnectTimeMillis:Et(i.streamInitialReconnectDelay),diagnosticRecordingIntervalMillis:Et(i.diagnosticRecordingInterval),allAttributesPrivate:i.allAttributesPrivate,usingSecureMode:!1,bootstrapMode:!1}),En=(i,t,e)=>{if(t.sendEvents&&!t.diagnosticOptOut)return new S.DiagnosticsManager(i,e,wn(t))};function ue(i,t){return{value:t!=null?t:null,variationIndex:null,reason:{kind:"ERROR",errorKind:i}}}function Ye(i,t,e){return{value:i,variationIndex:t!=null?t:null,reason:e!=null?e:null}}var bn=(i,t,e,n,s)=>{if(t.sendEvents)return new S.EventProcessor(b(p({},t),{eventsCapacity:t.capacity}),new mt(i,t,e),n,void 0,s,!1)},kt=class extends S.EventFactoryBase{evalEventClient(t,e,n,s,r,a){let{trackEvents:o,debugEventsUntilDate:c,trackReason:u,flagVersion:h,version:d,variation:f}=s;return super.evalEvent({addExperimentData:u,context:r,debugEventsUntilDate:c,defaultVal:n,flagKey:t,reason:a,trackEvents:!!o,value:e,variation:f,version:h!=null?h:d})}},W=class i{constructor(){this.container={index:new Array}}static fromJson(t){let e=new i;try{e.container=JSON.parse(t)}catch(n){}return e}toJson(){return JSON.stringify(this.container)}notice(t,e){let n=this.container.index.find(s=>s.id===t);n===void 0?this.container.index.push({id:t,timestamp:e}):n.timestamp=e}prune(t){let e=Math.max(t,0);return this.container.index.length>e?(this.container.index.sort((n,s)=>n.timestamp-s.timestamp),this.container.index.splice(0,this.container.index.length-e)):[]}},ge=class{constructor(t,e,n,s,r,a,o=()=>Date.now()){this.r=t,this.Dt=e,this.Qe=n,this.l=s,this.b=r,this.t=a,this.st=o,this.ie=an(this.Dt)}async init(t,e){this.b.init(t,e),await this.ne(t)}async upsert(t,e,n){return this.b.upsert(t,e,n)?(await this.ne(t),!0):!1}async loadCached(t){var s,r,a,o;let e=await ze(this.r.crypto,this.Dt,t),n=await((s=this.r.storage)==null?void 0:s.get(e));if(n==null){if(n=await((r=this.r.storage)==null?void 0:r.get(t.canonicalKey)),n==null)return!1;await((a=this.r.storage)==null?void 0:a.set(e,n)),await((o=this.r.storage)==null?void 0:o.clear(t.canonicalKey))}try{let c=JSON.parse(n),u=Object.entries(c).reduce((h,[d,f])=>(h[d]={version:f.version,flag:f},h),{});return this.b.initCached(t,u),this.t.debug("Loaded cached flag evaluations from persistent storage"),!0}catch(c){return this.t.warn(`Could not load cached flag evaluations from persistent storage: ${c.message}`),!1}}async ti(){var e;if(this.C!==void 0)return this.C;let t=await((e=this.r.storage)==null?void 0:e.get(await this.ie));if(!t)return this.C=new W,this.C;try{this.C=W.fromJson(t),this.t.debug("Loaded context index from persistent storage")}catch(n){this.t.warn(`Could not load index from persistent storage: ${n.message}`),this.C=new W}return this.C}async ne(t){var c,u;let e=await this.ti(),n=await ze(this.r.crypto,this.Dt,t);e.notice(n,this.st());let s=e.prune(this.Qe);await Promise.all(s.map(async h=>{var d;return(d=this.r.storage)==null?void 0:d.clear(h.id)})),await((c=this.r.storage)==null?void 0:c.set(await this.ie,e.toJson()));let r=this.l.getAll(),a=Object.entries(r).reduce((h,[d,f])=>(f.flag!==null&&f.flag!==void 0&&(h[d]=f.flag),h),{}),o=JSON.stringify(a);await((u=this.r.storage)==null?void 0:u.set(n,o))}},pe=class{constructor(){this.B={}}init(t){this.B=Object.entries(t).reduce((e,[n,s])=>(e[n]=s,e),{})}insertOrUpdate(t,e){this.B[t]=e}get(t){if(Object.prototype.hasOwnProperty.call(this.B,t))return this.B[t]}getAll(){return this.B}};function Dn(i,t){let e=[];return Object.entries(i).forEach(([n,s])=>{let r=t[n];(!r||!V(s,r))&&e.push(n)}),Object.keys(t).forEach(n=>{i[n]||e.push(n)}),e}var me=class{constructor(t,e){this.H=new Array,this.l=t,this.t=e}init(t,e){this.se=t.canonicalKey;let n=this.l.getAll();this.l.init(e);let s=Dn(n,e);s.length>0&&this.H.forEach(r=>{try{r(t,s,"init")}catch(a){}})}initCached(t,e){this.se!==t.canonicalKey&&this.init(t,e)}upsert(t,e,n){if(this.se!==t.canonicalKey)return this.t.warn("Received an update for an inactive context."),!1;let s=this.l.get(e);return s!==void 0&&s.version>=n.version?!1:(this.l.insertOrUpdate(e,n),this.H.forEach(r=>{try{r(t,[e],"patch")}catch(a){}}),!0)}on(t){this.H.push(t)}off(t){let e=this.H.indexOf(t);e>-1&&this.H.splice(e,1)}},ye=class{constructor(t,e,n,s,r=()=>Date.now()){this.l=new pe,this.b=new me(this.l,s),this.kt=this.ei(t,e,n,s,r)}async ei(t,e,n,s,r=()=>Date.now()){let a=await nn(t.crypto,e);return new ge(t,a,n,this.l,this.b,s,r)}get(t){return this.l.get(t)}getAll(){return this.l.getAll()}setBootstrap(t,e){this.b.init(t,e)}async init(t,e){return(await this.kt).init(t,e)}async upsert(t,e,n){return(await this.kt).upsert(t,e,n)}async loadCached(t){return(await this.kt).loadCached(t)}on(t){this.b.on(t)}off(t){this.b.off(t)}},Xe="unknown hook",si="beforeEvaluation",ri="afterEvaluation";function Lt(i,t,e,n,s){try{return n()}catch(r){return i==null||i.error(`An error was encountered in "${t}" of the "${e}" hook: ${r}`),s}}function At(i,t){try{return t.getMetadata().name||Xe}catch(e){return i.error("Exception thrown getting metadata for hook. Unable to get hook name."),Xe}}function kn(i,t,e){return t.map(n=>Lt(i,si,At(i,n),()=>{var s,r;return(r=(s=n==null?void 0:n.beforeEvaluation)==null?void 0:s.call(n,e,{}))!=null?r:{}},{}))}function xn(i,t,e,n,s){for(let r=t.length-1;r>=0;r-=1){let a=t[r],o=n[r];Lt(i,ri,At(i,a),()=>{var c,u;return(u=(c=a==null?void 0:a.afterEvaluation)==null?void 0:c.call(a,e,o,s))!=null?u:{}},{})}}function Sn(i,t,e){return t.map(n=>Lt(i,si,At(i,n),()=>{var s,r;return(r=(s=n==null?void 0:n.beforeIdentify)==null?void 0:s.call(n,e,{}))!=null?r:{}},{}))}function Ln(i,t,e,n,s){for(let r=t.length-1;r>=0;r-=1){let a=t[r],o=n[r];Lt(i,ri,At(i,a),()=>{var c,u;return(u=(c=a==null?void 0:a.afterIdentify)==null?void 0:c.call(a,e,o,s))!=null?u:{}},{})}}var ve=class{constructor(t,e){this.t=t,this.V=[],this.V.push(...e)}withEvaluation(t,e,n,s){if(this.V.length===0)return s();let r=[...this.V],a={flagKey:t,context:e,defaultValue:n},o=kn(this.t,r,a),c=s();return xn(this.t,r,a,o,c),c}identify(t,e){let n=[...this.V],s={context:t,timeout:e},r=Sn(this.t,n,s);return a=>{Ln(this.t,n,s,r,a)}}addHook(t){this.V.push(t)}};function An(i){return{getMetadata(){return{name:"LaunchDarkly-Inspector-Adapter"}},afterEvaluation:(t,e,n)=>(i.onFlagUsed(t.flagKey,n,t.context),e),afterIdentify(t,e,n){return i.onIdentityChanged(t.context),e}}}function Cn(i,t){return`an inspector: "${t}" of an invalid type (${i}) was configured`}function On(i,t){return`an inspector: "${t}" of type: "${i}" generated an exception`}function $n(i,t){let e=!1,n={method:(...s)=>{try{i.method(...s)}catch(r){e||(e=!0,t.warn(On(n.type,n.name)))}},type:i.type,name:i.name,synchronous:i.synchronous};return n}var ai="flag-used",oi="flag-details-changed",ci="flag-detail-changed",ui="client-identity-changed",Tn=[ai,oi,ci,ui];function Rn(i,t){let e=Tn.includes(i.type)&&i.method&&typeof i.method=="function";return e||t.warn(Cn(i.type,i.name)),e}var we=class{constructor(t,e){this.$=[];let n=t.filter(s=>Rn(s,e));this.$=n.map(s=>$n(s,e))}hasInspectors(){return this.$.length!==0}onFlagUsed(t,e,n){this.$.forEach(s=>{s.type===ai&&s.method(t,e,n)})}onFlagsChanged(t){this.$.forEach(e=>{e.type===oi&&e.method(t)})}onFlagChanged(t,e){this.$.forEach(n=>{n.type===ci&&n.method(t,e)})}onIdentityChanged(t){this.$.forEach(e=>{e.type===ui&&e.method(t)})}},Ee=class{constructor(t){this.t=t,this.e=new Map}on(t,e){var n;this.e.has(t)?(n=this.e.get(t))==null||n.push(e):this.e.set(t,[e])}off(t,e){let n=this.e.get(t);if(n){if(e){let s=n.filter(r=>r!==e);s.length===0?this.e.delete(t):this.e.set(t,s);return}this.e.delete(t)}}ii(t,e,...n){var s;try{t(...n)}catch(r){(s=this.t)==null||s.error(`Encountered error invoking handler for "${e}", detail: "${r}"`)}}emit(t,...e){let n=this.e.get(t);n==null||n.forEach(s=>this.ii(s,t,...e))}eventNames(){return[...this.e.keys()]}listenerCount(t){var e,n;return(n=(e=this.e.get(t))==null?void 0:e.length)!=null?n:0}},{ClientMessages:le,ErrorKinds:he}=S,In=5,xt=class{constructor(t,e,n,s,r,a){if(this.sdkKey=t,this.autoEnvAttributes=e,this.platform=n,this.xt=15,this.D=new kt(!1),this.rt=new kt(!0),this.St=!1,!t)throw new Error("You must configure the client with a client-side SDK key");if(!n.encoding)throw new Error("Platform must implement Encoding because btoa is required.");this.n=new fe(s,a),this.logger=this.n.logger,this.re=Ge(this.sdkKey,this.platform.info,this.n.tags,this.n.serviceEndpoints.includeAuthorizationHeader,this.n.userAgentHeaderName),this.y=new ye(this.platform,t,this.n.maxCachedContexts,this.n.logger),this.m=En(t,this.n,n),this.h=bn(t,this.n,n,this.re,this.m),this.emitter=new Ee,this.emitter.on("error",(o,c)=>{this.logger.error(`error: ${c}, context: ${JSON.stringify(o)}`)}),this.y.on((o,c,u)=>{this.ni(c,u);let h=k.toLDContext(o);this.emitter.emit("change",h,c),c.forEach(d=>{this.emitter.emit(`change:${d}`,h)})}),this.dataManager=r(this.y,this.n,this.re,this.emitter,this.m),this.T=new ve(this.logger,this.n.hooks),this._=new we(this.n.inspectors,this.logger),this._.hasInspectors()&&this.T.addHook(An(this._))}allFlags(){return Object.entries(this.y.getAll()).reduce((e,[n,s])=>(s.flag!==null&&s.flag!==void 0&&!s.flag.deleted&&(e[n]=s.flag.value),e),{})}async close(){var t;await this.flush(),(t=this.h)==null||t.close(),this.dataManager.close(),this.logger.debug("Closed event processor and data source.")}async flush(){var t;try{await((t=this.h)==null?void 0:t.flush()),this.logger.debug("Successfully flushed event processor.")}catch(e){return this.logger.error(`Error flushing event processor: ${e}.`),{error:e,result:!1}}return{result:!0}}getContext(){return this.v?ae(this.v):void 0}getInternalContext(){return this.R}si(t,e){let n,s,r=new Promise((c,u)=>{n=c,s=u});if(e)return{identifyPromise:r,identifyResolve:n,identifyReject:s};let a=Je(t,"identify");return{identifyPromise:Promise.race([a,r]).catch(c=>{throw c.message.includes("timed out")&&this.logger.error(`identify error: ${c}`),c}),identifyResolve:n,identifyReject:s}}async identify(t,e){var d,f;let n=(d=e==null?void 0:e.timeout)!=null?d:In,s=(e==null?void 0:e.timeout)===void 0&&(e==null?void 0:e.noTimeout)===!0;n>this.xt&&this.logger.warn(`The identify function was called with a timeout greater than ${this.xt} seconds. We recommend a timeout of less than ${this.xt} seconds.`);let r=await vn(t,this.platform);this.autoEnvAttributes===F.Enabled&&(r=await hn(r,this.platform,this.n));let a=k.fromLDContext(r);if(!a.valid){let g=new Error("Context was unspecified or had no key");return this.emitter.emit("error",r,g),Promise.reject(g)}this.v=r,this.R=a,(f=this.h)==null||f.sendEvent(this.D.identifyEvent(this.R));let{identifyPromise:o,identifyResolve:c,identifyReject:u}=this.si(n,s);this.logger.debug(`Identifying ${JSON.stringify(this.R)}`);let h=this.T.identify(r,e==null?void 0:e.timeout);return await this.dataManager.identify(c,u,a,e),o.then(g=>(h({status:"completed"}),g),g=>{throw h({status:"error"}),g})}on(t,e){this.emitter.on(t,e)}off(t,e){this.emitter.off(t,e)}track(t,e,n){var s,r;if(!this.R||!this.R.valid){this.logger.warn(le.MissingContextKeyNoEvent);return}n!==void 0&&!l.Number.is(n)&&((s=this.logger)==null||s.warn(le.invalidMetricValue(typeof n))),(r=this.h)==null||r.sendEvent(this.n.trackEventModifier(this.D.customEvent(t,this.R,e,n)))}at(t,e,n,s){var f,g,m;if(!this.v)return this.logger.debug(le.MissingContextKeyNoEvent),ue(he.UserNotSpecified,e);let r=k.fromLDContext(this.v),a=this.y.get(t);if(a===void 0||a.flag.deleted){let y=e!=null?e:null,A=new q(`Unknown feature flag "${t}"; returning default value ${y}.`);return this.emitter.emit("error",this.v,A),(f=this.h)==null||f.sendEvent(this.D.unknownFlagEvent(t,y,r)),ue(he.FlagNotFound,e)}let{reason:o,value:c,variation:u,prerequisites:h}=a.flag;if(s){let[y,A]=s(c);if(!y){(g=this.h)==null||g.sendEvent(n.evalEventClient(t,e,e,a.flag,r,o));let It=new q(`Wrong type "${A}" for feature flag "${t}"; returning default value`);return this.emitter.emit("error",this.v,It),ue(he.WrongType,e)}}let d=Ye(c,u,o);return c==null&&(this.logger.debug("Result value is null. Providing default value."),d.value=e),h==null||h.forEach(y=>{this.at(y,void 0,this.D)}),(m=this.h)==null||m.sendEvent(n.evalEventClient(t,c,e,a.flag,r,o)),d}variation(t,e){let{value:n}=this.T.withEvaluation(t,this.v,e,()=>this.at(t,e,this.D));return n}variationDetail(t,e){return this.T.withEvaluation(t,this.v,e,()=>this.at(t,e,this.rt))}I(t,e,n,s){return this.T.withEvaluation(t,this.v,e,()=>this.at(t,e,n,s))}boolVariation(t,e){return this.I(t,e,this.D,n=>[l.Boolean.is(n),l.Boolean.getType()]).value}jsonVariation(t,e){return this.variation(t,e)}numberVariation(t,e){return this.I(t,e,this.D,n=>[l.Number.is(n),l.Number.getType()]).value}stringVariation(t,e){return this.I(t,e,this.D,n=>[l.String.is(n),l.String.getType()]).value}boolVariationDetail(t,e){return this.I(t,e,this.rt,n=>[l.Boolean.is(n),l.Boolean.getType()])}numberVariationDetail(t,e){return this.I(t,e,this.rt,n=>[l.Number.is(n),l.Number.getType()])}stringVariationDetail(t,e){return this.I(t,e,this.rt,n=>[l.String.is(n),l.String.getType()])}jsonVariationDetail(t,e){return this.variationDetail(t,e)}addHook(t){this.T.addHook(t)}setEventSendingEnabled(t,e){var n,s,r,a;this.St!==t&&(this.St=t,t?(this.logger.debug("Starting event processor"),(n=this.h)==null||n.start()):e?((s=this.logger)==null||s.debug("Flushing event processor before disabling."),this.flush().then(()=>{var o,c;this.St||((o=this.logger)==null||o.debug("Stopping event processor."),(c=this.h)==null||c.close())})):((r=this.logger)==null||r.debug("Stopping event processor."),(a=this.h)==null||a.close()))}sendEvent(t){var e;(e=this.h)==null||e.sendEvent(t)}ni(t,e){if(!this._.hasInspectors())return;let n={};t.forEach(s=>{let r=this.y.get(s);if(r!=null&&r.flag&&!r.flag.deleted){let{reason:a,value:o,variation:c}=r.flag;n[s]=Ye(o,c,a)}else n[s]={value:void 0,reason:null,variationIndex:null}}),e==="init"?this._.onFlagsChanged(n):e==="patch"&&Object.entries(n).forEach(([s,r])=>{this._.onFlagChanged(s,r)})}},be=class{constructor(t,e,n){this.y=t,this.Lt=e,this.t=n}async handlePut(t,e){this.t.debug(`Got PUT: ${Object.keys(e)}`);let n=Object.entries(e).reduce((s,[r,a])=>(s[r]={version:a.version,flag:a},s),{});await this.y.init(t,n),this.Lt.requestStateUpdate(E.Valid)}async handlePatch(t,e){this.t.debug(`Got PATCH ${JSON.stringify(e,null,2)}`),this.y.upsert(t,e.key,{version:e.version,flag:e})}async handleDelete(t,e){this.t.debug(`Got DELETE ${JSON.stringify(e,null,2)}`),this.y.upsert(t,e.key,{version:e.version,flag:b(p({},e),{deleted:!0,flagVersion:0,value:void 0,variation:0,trackEvents:!1})})}handleStreamingError(t){this.Lt.reportError(t.kind,t.message,t.code,t.recoverable)}handlePollingError(t){this.Lt.reportError(t.kind,t.message,t.status,t.recoverable)}},De=class{constructor(t,e=()=>Date.now()){this.ri=t,this.ot=E.Closed,this.ae=e(),this.st=e}get status(){return{state:this.ot,stateSince:this.ae,lastError:this.ai}}oe(t,e=!1){let n=t===E.Interrupted&&this.ot===E.Initializing?E.Initializing:t,s=this.ot!==n;s&&(this.ot=n,this.ae=this.st()),(s||e)&&this.ri.emit("dataSourceStatus",this.status)}requestStateUpdate(t){this.oe(t)}reportError(t,e,n,s=!1){let r={kind:t,message:e,statusCode:n,time:this.st()};this.ai=r,this.oe(s?E.Interrupted:E.Closed,!0)}},ke=class{constructor(t,e,n,s,r){this.oi=t,this.ci=e,this.ui=n,this.u=s,this.t=r,this.ce=!1}async ue(){var r,a,o,c,u,h,d;if(this.ce)return;let t=f=>{var g,m,y;(g=this.t)==null||g.error("Polling received invalid data"),(m=this.t)==null||m.debug(`Invalid JSON follows: ${f}`),(y=this.u)==null||y.call(this,new I(w.InvalidData,"Malformed JSON data in polling response"))};(r=this.t)==null||r.debug("Polling LaunchDarkly for feature flag updates");let e=Date.now();try{let f=await this.oi.requestPayload();try{let g=JSON.parse(f);try{(a=this.ui)==null||a.call(this,g)}catch(m){(o=this.t)==null||o.error(`Exception from data handler: ${m}`)}}catch(g){t(f)}}catch(f){let g=f;if(g.status!==void 0&&!z(g.status)){(c=this.t)==null||c.error(B(f,"polling request")),(u=this.u)==null||u.call(this,new I(w.ErrorResponse,g.message,g.status));return}(h=this.t)==null||h.error(B(f,"polling request","will retry"))}let n=Date.now()-e,s=Math.max(this.ci*1e3-n,0);(d=this.t)==null||d.debug("Elapsed: %d ms, sleeping for %d ms",n,s),this.At=setTimeout(()=>{this.ue()},s)}start(){this.ue()}stop(){this.At&&(clearTimeout(this.At),this.At=void 0),this.ce=!0}close(){this.stop()}},Nn=(i,t,e,n)=>{e==null||e.error(`Stream received invalid data in "${i}" message`),e==null||e.debug(`Invalid JSON follows: ${t}`),n==null||n(new U(w.InvalidData,"Malformed JSON data in event stream"))},xe=class{constructor(t,e,n,s,r,a,o,c,u){var f;this.li=t,this.Ct=e,this.e=n,this.E=s,this.hi=a,this.m=o,this.u=c,this.t=u;let h;e.useReport&&!s.getEventSourceCapabilities().customMethod?h=e.paths.pathPing(r,t):h=e.useReport?e.paths.pathReport(r,t):e.paths.pathGet(r,t);let d=[...(f=e.queryParameters)!=null?f:[]];this.Ct.withReasons&&d.push({key:"withReasons",value:"true"}),this.E=s,this.nt=p({},e.baseHeaders),this.t=u,this.di=_e(e.serviceEndpoints,h,d)}le(){this.ct=Date.now()}Ot(t){this.ct&&this.m&&this.m.recordStreamInit(this.ct,!t,Date.now()-this.ct),this.ct=void 0}fi(t){var e,n,s;return qe(t)?((s=this.t)==null||s.warn(B(t,"streaming request","will retry")),this.Ot(!1),this.le(),!0):(this.Ot(!1),(e=this.u)==null||e.call(this,new U(w.ErrorResponse,t.message,t.status,!1)),(n=this.t)==null||n.error(B(t,"streaming request")),!1)}start(){this.le();let t;this.Ct.useReport?(this.nt["content-type"]="application/json",t={method:"REPORT",body:this.li}):t={};let e=this.E.createEventSource(this.di,b(p({headers:this.nt},t),{errorFilter:n=>this.fi(n),initialRetryDelayMillis:this.Ct.initialRetryDelayMillis,readTimeoutMillis:5*60*1e3,retryResetIntervalMillis:60*1e3}));this.he=e,e.onclose=()=>{var n;(n=this.t)==null||n.info("Closed LaunchDarkly stream connection")},e.onerror=()=>{},e.onopen=()=>{var n;(n=this.t)==null||n.info("Opened LaunchDarkly stream connection")},e.onretrying=n=>{var s;(s=this.t)==null||s.info(`Will retry stream connection in ${n.delayMillis} milliseconds`)},this.e.forEach(({deserializeData:n,processJson:s},r)=>{e.addEventListener(r,a=>{var o,c;if((o=this.t)==null||o.debug(`Received ${r} event`),a!=null&&a.data){this.Ot(!0);let{data:u}=a,h=n(u);if(!h){Nn(r,u,this.t,this.u);return}s(h)}else(c=this.u)==null||c.call(this,new U(w.InvalidData,"Unexpected payload from event stream"))})}),e.addEventListener("ping",async()=>{var n,s,r,a,o,c,u;(n=this.t)==null||n.debug("Got PING, going to poll LaunchDarkly for feature flag updates");try{let h=await this.hi.requestPayload();try{let d=JSON.parse(h);try{(s=this.e.get("put"))==null||s.processJson(d)}catch(f){(r=this.t)==null||r.error(`Exception from data handler: ${f}`)}}catch(d){(a=this.t)==null||a.error("Polling after ping received invalid data"),(o=this.t)==null||o.debug(`Invalid JSON follows: ${h}`),(c=this.u)==null||c.call(this,new I(w.InvalidData,"Malformed JSON data in ping polling response"))}}catch(h){let d=h;(u=this.u)==null||u.call(this,new I(w.ErrorResponse,d.message,d.status))}})}stop(){var t;(t=this.he)==null||t.close(),this.he=void 0}close(){this.stop()}},St=class{constructor(t,e,n,s,r,a,o,c,u){this.platform=t,this.flagManager=e,this.credential=n,this.config=s,this.getPollingPaths=r,this.getStreamingPaths=a,this.baseHeaders=o,this.emitter=c,this.diagnosticsManager=u,this.closed=!1,this.logger=s.logger,this.dataSourceStatusManager=new De(c),this.N=new be(e,this.dataSourceStatusManager,this.config.logger)}setConnectionParams(t){this.gi=t}createPollingProcessor(t,e,n,s,r){let a=new ke(n,this.config.pollInterval,async o=>{await this.N.handlePut(e,o),s==null||s()},o=>{this.emitter.emit("error",t,o),this.N.handlePollingError(o),r==null||r(o)},this.logger);this.updateProcessor=this.de(a,this.dataSourceStatusManager)}createStreamingProcessor(t,e,n,s,r){var o;let a=new xe(JSON.stringify(t),{credential:this.credential,serviceEndpoints:this.config.serviceEndpoints,paths:this.getStreamingPaths(),baseHeaders:this.baseHeaders,initialRetryDelayMillis:this.config.streamInitialReconnectDelay*1e3,withReasons:this.config.withReasons,useReport:this.config.useReport,queryParameters:(o=this.gi)==null?void 0:o.queryParameters},this.createStreamListeners(e,s),this.platform.requests,this.platform.encoding,n,this.diagnosticsManager,c=>{this.emitter.emit("error",t,c),this.N.handleStreamingError(c),r==null||r(c)},this.logger);this.updateProcessor=this.de(a,this.dataSourceStatusManager)}createStreamListeners(t,e){let n=new Map;return n.set("put",{deserializeData:JSON.parse,processJson:async s=>{await this.N.handlePut(t,s),e==null||e()}}),n.set("patch",{deserializeData:JSON.parse,processJson:async s=>{this.N.handlePatch(t,s)}}),n.set("delete",{deserializeData:JSON.parse,processJson:async s=>{this.N.handleDelete(t,s)}}),n}de(t,e){return{start:()=>{e.requestStateUpdate(E.Initializing),t.start()},stop:()=>{t.stop(),e.requestStateUpdate(E.Closed)},close:()=>{t.close(),e.requestStateUpdate(E.Closed)}}}close(){var t;(t=this.updateProcessor)==null||t.close(),this.closed=!0}};function Ct(){return typeof document!==void 0}function Ae(){return typeof window!==void 0}function Ot(i,t,e){return Ct()?(document.addEventListener(i,t,e),()=>{document.removeEventListener(i,t,e)}):()=>{}}function $t(i,t,e){return Ct()?(window.addEventListener(i,t,e),()=>{window.removeEventListener(i,t,e)}):()=>{}}function L(){return Ae()?window.location.href:""}function li(){return Ae()?window.location.search:""}function hi(){return Ae()?window.location.hash:""}function di(){if(typeof crypto!==void 0)return crypto;throw Error("Access to a web crypto API is required")}function fi(){return Ct()?document.visibilityState:"visibile"}function gi(i){if(Ct())return document.querySelectorAll(i)}function pi(i,t){let e=Object.keys(t),n="$flagsState",s="$valid",r=t[n];!r&&e.length&&i.warn("LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."),t[s]===!1&&i.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");let a={};return e.forEach(o=>{if(o!==n&&o!==s){let c;r&&r[o]?c=p({value:t[o]},r[o]):c={value:t[o],version:0},a[o]={version:c.version,flag:c}}}),a}var Mn="[BrowserDataManager]",X=class extends St{constructor(e,n,s,r,a,o,c,u,h,d){super(e,n,s,r,o,c,u,h,d);this.Oi=a;this.K=void 0;this.$t=!1;this.K=a.streaming}k(e,...n){this.logger.debug(`${Mn} ${e}`,...n)}async identify(e,n,s,r){if(this.closed){this.k("Identify called after data manager was closed.");return}this.context=s;let a=r;a!=null&&a.hash?this.setConnectionParams({queryParameters:[{key:"h",value:a.hash}]}):this.setConnectionParams(),this.Tt=a==null?void 0:a.hash,a!=null&&a.bootstrap?this.pi(s,a.bootstrap,e):(await this.flagManager.loadCached(s)&&this.k("Identify - Flags loaded from cache. Continuing to initialize via a poll."),await this.mi(s,e,n)),this.Rt()}async mi(e,n,s){var r,a;try{this.dataSourceStatusManager.requestStateUpdate(E.Initializing);let o=JSON.stringify(k.toLDContext(e)),u=await Se(o,this.config.serviceEndpoints,this.getPollingPaths(),this.platform.requests,this.platform.encoding,this.baseHeaders,[],this.config.withReasons,this.config.useReport,this.Tt).requestPayload();try{let d=this.createStreamListeners(e,n).get("put");d.processJson(d.deserializeData(u))}catch(h){this.dataSourceStatusManager.reportError(w.InvalidData,(r=h.message)!=null?r:"Could not parse poll response")}}catch(o){this.dataSourceStatusManager.reportError(w.NetworkError,(a=o.message)!=null?a:"unexpected network error",o.status),s(o)}}pi(e,n,s){this.flagManager.setBootstrap(e,pi(this.logger,n)),this.k("Identify - Initialization completed from bootstrap"),s()}setForcedStreaming(e){this.K=e,this.Rt()}setAutomaticStreamingState(e){this.$t=e,this.Rt()}Rt(){let e=this.K||this.$t&&this.K===void 0;this.k(`Updating streaming state. forced(${this.K}) automatic(${this.$t})`),e?this.yi():this.vi()}vi(){var e;this.updateProcessor&&this.k("Stopping update processor."),(e=this.updateProcessor)==null||e.close(),this.updateProcessor=void 0}yi(){if(this.updateProcessor){this.k("Update processor already active. Not changing state.");return}if(!this.context){this.k("Context not set, not starting update processor.");return}this.k("Starting update processor."),this.wi(this.context)}wi(e,n,s){var c;let r=k.toLDContext(e);(c=this.updateProcessor)==null||c.close();let a=JSON.stringify(k.toLDContext(e)),o=Se(a,this.config.serviceEndpoints,this.getPollingPaths(),this.platform.requests,this.platform.encoding,this.baseHeaders,[],this.config.withReasons,this.config.useReport,this.Tt);this.createStreamingProcessor(r,e,o,n,s),this.updateProcessor.start()}};function mi(i){let e=Ot("visibilitychange",()=>{fi()==="hidden"&&i()}),n=$t("pagehide",i);return()=>{e(),n()}}function Z(i){if(typeof i!="string")throw new TypeError("Expected a string");return i.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Pn(i,t,e,n){let r=((i.kind==="substring"||i.kind==="regex")&&n.includes("/")?t:t.replace(n,"")).replace(e,"");switch(i.kind){case"exact":return new RegExp(`^${Z(i.url)}/?$`).test(t);case"canonical":return new RegExp(`^${Z(i.url)}/?$`).test(r);case"substring":return new RegExp(`.*${Z(i.substring)}.*$`).test(r);case"regex":return new RegExp(i.pattern).test(r);default:return!1}}function Un(i,t){let e=[];return t.forEach(n=>{let s=i.target,{selector:r}=n,a=gi(r);for(;s&&(a!=null&&a.length);){for(let o=0;o<a.length;o+=1)if(s===a[o]){e.push(n);break}s=s.parentNode}}),e}var Q=class{constructor(t,e){let n=t.filter(a=>{var o;return(o=a.urls)==null?void 0:o.some(c=>Pn(c,L(),li(),hi()))}),s=n.filter(a=>a.kind==="pageview"),r=n.filter(a=>a.kind==="click");if(s.forEach(a=>e(a)),r.length){let a=o=>{Un(o,r).forEach(c=>{e(c)})};this.fe=Ot("click",a)}}close(){var t;(t=this.fe)==null||t.call(this)}};var Fn=300,Tt=class{constructor(t){this.It=L();let e=()=>{let s=L();s!==this.It&&(this.It=s,t())};this.Nt=setInterval(e,Fn);let n=$t("popstate",e);this.ge=()=>{n()}}close(){var t;this.Nt&&clearInterval(this.Nt),(t=this.ge)==null||t.call(this)}};var tt=class{constructor(t,e,n,s,r,a=o=>new Tt(o)){this.E=e;this.Di=s;this.bi=r;this.ut=[];this.me=!1;this.lt=`${n}/sdk/goals/${t}`,this.pe=a(()=>{this.Pt()})}async initialize(){await this.Ei(),this.Pt()}startTracking(){this.me=!0,this.Pt()}Pt(){var t;this.me&&((t=this.Mt)==null||t.close(),this.ut&&this.ut.length&&(this.Mt=new Q(this.ut,e=>{this.bi(L(),e)})))}async Ei(){try{let t=await this.E.fetch(this.lt);this.ut=await t.json()}catch(t){this.Di(new G(`Encountered error fetching goals: ${t}`))}}close(){var t,e;(t=this.pe)==null||t.close(),(e=this.Mt)==null||e.close()}};function yi(i){return i.kind==="click"}var jn=2,vi={fetchGoals:!0,eventUrlTransformer:i=>i,streaming:void 0},Bn={fetchGoals:l.Boolean,eventUrlTransformer:l.Function,streaming:l.Boolean};function wi(i){let t=p({},i);return Object.keys(vi).forEach(e=>{delete t[e]}),t}function Hn(i){var t;(t=i.flushInterval)!=null||(i.flushInterval=jn)}function Ce(i,t){let e=p({},vi);return Hn(e),Object.entries(Bn).forEach(n=>{let[s,r]=n,a=i[s];a!==void 0&&(r.is(a)?e[s]=a:t.warn(D.wrongOptionType(s,r.getType(),typeof a)))}),e}var et=class{constructor(t,e){this.ki=t;this.ye=[];switch(e){case"sha1":this.Ut="SHA-1";break;case"sha256":this.Ut="SHA-256";break;default:throw new Error(`Algorithm is not supported ${e}`)}}async asyncDigest(t){let e=this.ye.join(""),n=new TextEncoder().encode(e),s=await this.ki.subtle.digest(this.Ut,n);switch(t){case"base64":return btoa(String.fromCharCode(...new Uint8Array(s)));case"hex":return[...new Uint8Array(s)].map(r=>r.toString(16).padStart(2,"0")).join("");default:throw new Error(`Encoding is not supported ${t}`)}}update(t){return this.ye.push(t),this}};var Vn={start:0,end:3},_n={start:4,end:5},Oe={start:6,end:7},$e={start:8,end:8},Kn={start:9,end:9},Gn={start:10,end:15};function qn(){if(crypto&&crypto.getRandomValues){let t=new Uint8Array(16);return crypto.getRandomValues(t),[...t.values()]}let i=[];for(let t=0;t<16;t+=1)i.push(Math.floor(Math.random()*256));return i}function H(i,t){let e="";for(let n=t.start;n<=t.end;n+=1)e+=i[n].toString(16).padStart(2,"0");return e}function Jn(i){return i[$e.start]=(i[$e.start]|128)&191,i[Oe.start]=i[Oe.start]&15|64,`${H(i,Vn)}-${H(i,_n)}-${H(i,Oe)}-${H(i,$e)}${H(i,Kn)}-${H(i,Gn)}`}function zn(){let i=qn();return Jn(i)}function Te(){return typeof crypto!==void 0&&typeof crypto.randomUUID=="function"?crypto.randomUUID():zn()}var it=class{createHash(t){return new et(di(),t)}randomUUID(){return Te()}};function Wn(i){let t=Array.from(i,e=>String.fromCodePoint(e)).join("");return btoa(t)}var nt=class{btoa(t){return Wn(new TextEncoder().encode(t))}};var st=class{platformData(){return{name:"JS"}}sdkData(){return{name:"@launchdarkly/js-client-sdk",version:"0.0.0",userAgentBase:"JSClient"}}};var rt=class{constructor(t,e,n=Math.random){this.Li=e;this.Si=n;this.Ft=0;this.jt=Math.max(1,t),this.ve=Math.ceil(Math.log2(3e4/this.jt))}G(){let t=Math.min(this.Ft,this.ve),e=this.jt*2**t;return Math.min(e,3e4)}xi(t){return t-Math.trunc(this.Si()*.5*t)}success(t=Date.now()){this.ht=t}fail(t=Date.now()){this.ht!==void 0&&t-this.ht>this.Li&&(this.Ft=0),this.ht=void 0;let e=this.xi(this.G());return this.Ft+=1,e}};var at=class{constructor(t,e){this.lt=t;this.e={};this.G=new rt(e.initialRetryDelayMillis,e.retryResetIntervalMillis),this.we=e.errorFilter,this.Ee()}Ee(){this.M=new EventSource(this.lt),this.M.onopen=()=>{var t;this.G.success(),(t=this.onopen)==null||t.call(this)},this.M.onerror=t=>{var e;this.Ai(t),(e=this.onerror)==null||e.call(this,t)},Object.entries(this.e).forEach(([t,e])=>{e.forEach(n=>{var s;(s=this.M)==null||s.addEventListener(t,n)})})}addEventListener(t,e){var n,s,r;(s=(n=this.e)[t])!=null||(n[t]=[]),this.e[t].push(e),(r=this.M)==null||r.addEventListener(t,e)}close(){var t,e;clearTimeout(this.Bt),this.Bt=void 0,(t=this.M)==null||t.close(),(e=this.onclose)==null||e.call(this)}Ci(t){var e;(e=this.onretrying)==null||e.call(this,{delayMillis:t}),this.Bt=setTimeout(()=>{this.Ee()},t)}Ai(t){this.close(),!(t.status&&typeof t.status=="number"&&!this.we(t))&&this.Ci(this.G.fail())}};var ot=class{fetch(t,e){return fetch(t,e)}createEventSource(t,e){return new at(t,e)}getEventSourceCapabilities(){return{customMethod:!1,readTimeout:!1,headers:!1}}};function Ei(){return typeof localStorage!="undefined"}var ct=class{constructor(t){this.t=t}async clear(t){var e;try{localStorage.removeItem(t)}catch(n){(e=this.t)==null||e.error(`Error clearing key from localStorage: ${t}, reason: ${n}`)}}async get(t){var e;try{let n=localStorage.getItem(t);return n!=null?n:null}catch(n){return(e=this.t)==null||e.error(`Error getting key from localStorage: ${t}, reason: ${n}`),null}}async set(t,e){var n;try{localStorage.setItem(t,e)}catch(s){(n=this.t)==null||n.error(`Error setting key in localStorage: ${t}, reason: ${s}`)}}};var ut=class{constructor(t){this.encoding=new nt;this.info=new st;this.crypto=new it;this.requests=new ot;Ei()&&(this.storage=new ct(t))}};var Rt=class extends xt{constructor(t,e,n={},s){var f;let{logger:r,debug:a}=n,o=r!=null?r:new N({destination:{debug:console.debug,info:console.info,warn:console.warn,error:console.error},level:a?"debug":"info"}),c=(f=n.baseUri)!=null?f:"https://clientsdk.launchdarkly.com",u=s!=null?s:new ut(o),h=Ce(n,o),{eventUrlTransformer:d}=h;super(t,e,u,wi(b(p({},n),{logger:o})),(g,m,y,A,It)=>new X(u,g,t,m,h,()=>({pathGet($,T){return`/sdk/evalx/${t}/contexts/${oe(T,$)}`},pathReport($,T){return`/sdk/evalx/${t}/context`},pathPing($,T){throw new Error("Ping for polling unsupported.")}}),()=>({pathGet($,T){return`/eval/${t}/${oe(T,$)}`},pathReport($,T){return`/eval/${t}`},pathPing($,T){return`/ping/${t}`}}),y,A,It),{analyticsEventPath:`/events/bulk/${t}`,diagnosticEventPath:`/events/diagnostic/${t}`,includeAuthorizationHeader:!1,highTimeoutThreshold:5,userAgentHeaderName:"x-launchdarkly-user-agent",trackEventModifier:g=>new S.InputCustomEvent(g.context,g.key,g.data,g.metricValue,g.samplingRatio,d(L()))}),this.setEventSendingEnabled(!0,!1),h.fetchGoals&&(this.Ht=new tt(t,u.requests,c,g=>{o.error(g.message)},(g,m)=>{let y=this.getInternalContext();if(!y)return;let A=d(g);yi(m)?this.sendEvent({kind:"click",url:A,samplingRatio:1,key:m.key,creationDate:Date.now(),context:y,selector:m.selector}):this.sendEvent({kind:"pageview",url:A,samplingRatio:1,key:m.key,creationDate:Date.now(),context:y})}),this.Ht.initialize(),h.automaticBackgroundHandling&&mi(()=>this.flush()))}async identify(t,e){var n;await super.identify(t,e),(n=this.Ht)==null||n.startTracking()}setStreaming(t){this.dataManager.setForcedStreaming(t)}be(){this.dataManager.setAutomaticStreamingState(!!this.emitter.listenerCount("change"))}on(t,e){super.on(t,e),this.be()}off(t,e){super.off(t,e),this.be()}};function Or(i){return new N(i)}function Nr(i,t){return new Rt(i,F.Disabled,t)}export{Or as basicLogger,Nr as initialize};
|
|
1
|
+
var Di=Object.defineProperty,ki=Object.defineProperties;var xi=Object.getOwnPropertyDescriptors;var ht=Object.getOwnPropertySymbols;var Ie=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var Re=(i,t,e)=>t in i?Di(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,g=(i,t)=>{for(var e in t||(t={}))Ie.call(t,e)&&Re(i,e,t[e]);if(ht)for(var e of ht(t))Ne.call(t,e)&&Re(i,e,t[e]);return i},b=(i,t)=>ki(i,xi(t));var Nt=(i,t)=>{var e={};for(var n in i)Ie.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&ht)for(var n of ht(i))t.indexOf(n)<0&&Ne.call(i,n)&&(e[n]=i[n]);return e};function Si(i){return`/${i.replace(/~/g,"~0").replace(/\//g,"~1")}`}function je(i){return i.indexOf("~")?i.replace(/~1/g,"/").replace(/~0/g,"~"):i}function Li(i){return(i.startsWith("/")?i.substring(1):i).split("/").map(e=>je(e))}function Ai(i){return!i.startsWith("/")}function Ci(i){return!i.match(/\/\/|(^\/.*~[^0|^1])|~$/)}var C=class{constructor(t,e=!1){if(e){let n=t;this.a=[n],this.isValid=n!=="",this.redactionName=n.startsWith("/")?Si(n):n}else{if(this.redactionName=t,t===""||t==="/"||!Ci(t)){this.isValid=!1,this.a=[];return}Ai(t)?this.a=[t]:t.indexOf("/",1)<0?this.a=[je(t.slice(1))]:this.a=Li(t),this.a[0]==="_meta"?this.isValid=!1:this.isValid=!0}}get(t){let{a:e,isValid:n}=this;if(!n)return;let s=t;for(let r=0;r<e.length;r+=1){let a=e[r];if(s!=null&&Object.prototype.hasOwnProperty.call(s,a)&&typeof s=="object"&&!Array.isArray(s))s=s[a];else return}return s}getComponent(t){return this.a[t]}get depth(){return this.a.length}get isKind(){return this.a.length===1&&this.a[0]==="kind"}compare(t){return this.depth===t.depth&&this.a.every((e,n)=>e===t.getComponent(n))}};C.InvalidReference=new C("");var Ut=class{is(t){if(Array.isArray(t))return!1;let n=typeof t;return n==="function"||n==="object"}getType(){return"factory method or object"}},O=class{constructor(t,e){this.dt=t,this.typeOf=typeof e}is(t){return Array.isArray(t)?!1:typeof t===this.typeOf}getType(){return this.dt}},gt=class{constructor(t,e){this.dt=t,this.typeOf=typeof e}is(t){return Array.isArray(t)?t.length>0?t.every(e=>typeof e===this.typeOf):!0:!1}getType(){return this.dt}},K=class extends O{constructor(t){super(`number with minimum value of ${t}`,0),this.min=t}is(t){return typeof t===this.typeOf&&t>=this.min}},pt=class extends O{constructor(t){super(`string matching ${t}`,""),this.expression=t}is(t){return typeof t=="string"&&!!t.match(this.expression)}},Ft=class{is(t){return typeof t=="function"}getType(){return"function"}},jt=class{is(t){return typeof t=="boolean"||typeof t=="undefined"||t===null}getType(){return"boolean | undefined | null"}},Oi=/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d\d*)?(Z|[-+]\d\d(:\d\d)?)/,Bt=class{is(t){return typeof t=="number"||typeof t=="string"&&Oi.test(t)}getType(){return"date"}},Ht=class extends pt{constructor(){super(/^(\w|\.|-)+$/)}is(t){return super.is(t)&&t!=="kind"}},l=class{static createTypeArray(t,e){return new gt(t,e)}static numberWithMin(t){return new K(t)}static stringMatchingRegex(t){return new pt(t)}};l.String=new O("string","");l.Number=new O("number",0);l.ObjectOrFactory=new Ut;l.Object=new O("object",{});l.StringArray=new gt("string[]","");l.Boolean=new O("boolean",!0);l.Function=new Ft;l.Date=new Bt;l.Kind=new Ht;l.NullableBoolean=new jt;function Be(i){return"kind"in i?l.String.is(i.kind)&&i.kind!=="multi":!1}function He(i){return"kind"in i?l.String.is(i.kind)&&i.kind==="multi":!1}function Ve(i){return!("kind"in i)||i.kind===null||i.kind===void 0}var Vt="user";function Me(i){return i.includes("%")||i.includes(":")?i.replace(/%/g,"%25").replace(/:/g,"%3A"):i}function $i(i){return i&&l.Object.is(i)}function Pe(i){return l.Kind.is(i)}function Ue(i){return l.String.is(i)&&i!==""}function Mt(i,t=!1){return i?i.map(e=>new C(e,t)):[]}function Ti(i){return i!=null}function Ri(i){let t=b(g({},i.custom||[]),{kind:"user",key:String(i.key)});if(Ti(i.anonymous)){let e=!!i.anonymous;delete t.anonymous,t.anonymous=e}return i.name!==null&&i.name!==void 0&&(t.name=i.name),i.ip!==null&&i.ip!==void 0&&(t.ip=i.ip),i.firstName!==null&&i.firstName!==void 0&&(t.firstName=i.firstName),i.lastName!==null&&i.lastName!==void 0&&(t.lastName=i.lastName),i.email!==null&&i.email!==void 0&&(t.email=i.email),i.avatar!==null&&i.avatar!==void 0&&(t.avatar=i.avatar),i.country!==null&&i.country!==void 0&&(t.country=i.country),i.privateAttributeNames!==null&&i.privateAttributeNames!==void 0&&(t._meta={privateAttributes:i.privateAttributeNames}),t}var k=class i{constructor(t,e,n){this.w=!1,this.q=!1,this.Vt=!1,this.x={},this.kind=e,this.valid=t,this.message=n}static g(t,e){return new i(!1,t,e)}static De(t,e){if(!(!e||!t.isValid))return t.depth===1&&t.getComponent(0)==="anonymous"?!!(e!=null&&e.anonymous):t.get(e)}_t(t){if(this.w)return this.x[t];if(this.kind===t)return this.S}static ke(t){let e=Object.keys(t).filter(c=>c!=="kind"),n=e.every(Pe);if(!e.length)return i.g("multi","A multi-kind context must contain at least one kind");if(!n)return i.g("multi","Context contains invalid kinds");let s={},r=!0,a=e.reduce((c,u)=>{var d;let h=t[u];return $i(h)?(c[u]=h,s[u]=Mt((d=h._meta)==null?void 0:d.privateAttributes)):r=!1,c},{});if(!r)return i.g("multi","Context contained contexts that were not objects");if(!Object.values(a).every(c=>Ue(c.key)))return i.g("multi","Context contained invalid keys");if(e.length===1){let c=e[0],u=new i(!0,c);return u.S=b(g({},a[c]),{kind:c}),u.J=s,u.q=c==="user",u}let o=new i(!0,t.kind);return o.x=a,o.J=s,o.w=!0,o}static xe(t){var c;let{key:e,kind:n}=t,s=Pe(n),r=Ue(e);if(!s)return i.g(n!=null?n:"unknown","The kind was not valid for the context");if(!r)return i.g(n,"The key for the context was not valid");let a=Mt((c=t._meta)==null?void 0:c.privateAttributes),o=new i(!0,n);return o.q=n==="user",o.S=t,o.J={[n]:a},o}static Se(t){if(!(t.key!==void 0&&t.key!==null))return i.g("user","The key for the context was not valid");let n=new i(!0,"user");return n.q=!0,n.Vt=!0,n.S=Ri(t),n.J={user:Mt(t.privateAttributeNames,!0)},n}static fromLDContext(t){return t?Be(t)?i.xe(t):He(t)?i.ke(t):Ve(t)?i.Se(t):i.g("unknown","Context was not of a valid kind"):i.g("unknown","No context specified. Returning default value")}static toLDContext(t){if(!t.valid)return;let e=t.getContexts();if(!t.w)return e[0][1];let n={kind:"multi"};return e.forEach(s=>{let r=s[0],a=s[1];n[r]=a}),n}valueForKind(t,e=Vt){return t.isKind?this.kinds:i.De(t,this._t(e))}key(t=Vt){var e;return(e=this._t(t))==null?void 0:e.key}get isMultiKind(){return this.w}get canonicalKey(){return this.q?this.S.key:this.w?Object.keys(this.x).sort().map(t=>`${t}:${Me(this.x[t].key)}`).join(":"):`${this.kind}:${Me(this.S.key)}`}get kinds(){return this.w?Object.keys(this.x):[this.kind]}get kindsAndKeys(){return this.w?Object.entries(this.x).reduce((t,[e,n])=>(t[e]=n.key,t),{}):{[this.kind]:this.S.key}}privateAttributes(t){var e;return((e=this.J)==null?void 0:e[t])||[]}getContexts(){return this.w?Object.entries(this.x):[[this.kind,this.S]]}get legacy(){return this.Vt}};k.UserKind=Vt;var Ii=["key","kind","_meta","anonymous"].map(i=>new C(i,!0)),Ni=["name","ip","firstName","lastName","email","avatar","country"];function Mi(i,t){return i.depth===t.length&&t.every((e,n)=>e===i.getComponent(n))}function Pi(i,t){let e=[],n={},s=[];for(e.push(...Object.keys(i).map(r=>({key:r,ptr:[r],source:i,parent:n,visited:[i]})));e.length;){let r=e.pop(),a=t.find(o=>Mi(o,r.ptr));if(a)s.push(a.redactionName);else{let o=r.source[r.key];o===null?r.parent[r.key]=o:Array.isArray(o)?r.parent[r.key]=[...o]:typeof o=="object"?r.visited.includes(o)||(r.parent[r.key]={},e.push(...Object.keys(o).map(c=>({key:c,ptr:[...r.ptr,c],source:o,parent:r.parent[r.key],visited:[...r.visited,o]})))):r.parent[r.key]=o}}return{cloned:n,excluded:s.sort()}}var _t=class{constructor(t,e){this.Le=t,this.Ae=e}filter(t,e=!1){let n=t.getContexts();if(n.length===1)return this.Kt(t,n[0][1],n[0][0],e);let s={kind:"multi"};return n.forEach(([r,a])=>{s[r]=this.Kt(t,a,r,e)}),s}Ce(t,e,n,s){return(s?Object.keys(e).map(r=>new C(r,!0)):[...this.Ae,...t.privateAttributes(n)]).filter(r=>!Ii.some(a=>a.compare(r)))}Kt(t,e,n,s){let r=this.Le||s&&e.anonymous===!0,{cloned:a,excluded:o}=Pi(e,this.Ce(t,e,n,r));return t.legacy&&Ni.forEach(c=>{c in a&&(a[c]=String(a[c]))}),o.length&&(a._meta||(a._meta={}),a._meta.redactedAttributes=o),a._meta&&(delete a._meta.privateAttributes,Object.keys(a._meta).length===0&&delete a._meta),a}},w;(function(i){i.Unknown="UNKNOWN",i.NetworkError="NETWORK_ERROR",i.ErrorResponse="ERROR_RESPONSE",i.InvalidData="INVALID_DATA"})(w||(w={}));var I=class extends Error{constructor(t,e,n,s=!0){super(e),this.kind=t,this.status=n,this.name="LaunchDarklyPollingError",this.recoverable=s}},F=class extends Error{constructor(t,e,n,s=!0){super(e),this.kind=t,this.code=n,this.name="LaunchDarklyStreamingError",this.recoverable=s}},j;(function(i){i[i.Disabled=0]="Disabled",i[i.Enabled=1]="Enabled"})(j||(j={}));var B;(function(i){i[i.AnalyticsEvents=0]="AnalyticsEvents",i[i.DiagnosticEvent=1]="DiagnosticEvent"})(B||(B={}));var R;(function(i){i[i.Succeeded=0]="Succeeded",i[i.Failed=1]="Failed",i[i.FailedAndMustShutDown=2]="FailedAndMustShutDown"})(R||(R={}));function U(i){if(typeof i=="string")return i;if(i===void 0)return"undefined";if(i===null)return"null";if(Object.prototype.hasOwnProperty.call(i,"toString"))try{return i.toString()}catch(t){}if(typeof i=="bigint")return`${i}n`;try{return JSON.stringify(i)}catch(t){return t instanceof TypeError&&t.message.indexOf("circular")>=0?"[Circular]":"[Not Stringifiable]"}}function Ui(i){return typeof i=="symbol"?"NaN":typeof i=="bigint"?`${i}n`:String(Number(i))}function Fi(i){return typeof i=="symbol"?"NaN":typeof i=="bigint"?`${i}n`:String(parseInt(i,10))}function ji(i){return typeof i=="symbol"?"NaN":String(parseFloat(i))}var dt={s:i=>U(i),d:i=>Ui(i),i:i=>Fi(i),f:i=>ji(i),j:i=>U(i),o:i=>U(i),O:i=>U(i),c:()=>""};function Kt(...i){var e;let t=i.shift();if(l.String.is(t)){let n="",s=0;for(;s<t.length;){let r=t.charAt(s);if(r==="%"){if(s+1<t.length){let o=t.charAt(s+1);if(o in dt&&i.length){let c=i.shift();n+=(e=dt[o])==null?void 0:e.call(dt,c)}else o==="%"?n+="%":n+=`%${o}`;s+=2}}else n+=r,s+=1}return i.length&&(n.length&&(n+=" "),n+=i.map(U).join(" ")),n}return i.map(U).join(" ")}var v;(function(i){i[i.debug=0]="debug",i[i.info=1]="info",i[i.warn=2]="warn",i[i.error=3]="error",i[i.none=4]="none"})(v||(v={}));var Bi=["debug","info","warn","error","none"],N=class i{static get(){return new i({})}constructor(t){var e,n,s;if(this.Oe=(n=v[(e=t.level)!=null?e:"info"])!=null?n:v.info,this.$e=(s=t.name)!=null?s:"LaunchDarkly",this.Gt=t.formatter,typeof t.destination=="object")this.qt={[v.debug]:t.destination.debug,[v.info]:t.destination.info,[v.warn]:t.destination.warn,[v.error]:t.destination.error};else if(typeof t.destination=="function"){let{destination:r}=t;this.qt={[v.debug]:r,[v.info]:r,[v.warn]:r,[v.error]:r}}}Te(...t){var e;try{return this.Gt?(e=this.Gt)==null?void 0:e.call(this,...t):Kt(...t)}catch(n){return Kt(...t)}}Re(t,e){try{t(e)}catch(n){console.error(e)}}p(t,e){var n;if(t>=this.Oe){let s=`${Bi[t]}: [${this.$e}]`;try{let r=(n=this.qt)==null?void 0:n[t];r?this.Re(r,`${s} ${this.Te(...e)}`):console.error(...e)}catch(r){console.error(...e)}}}error(...t){this.p(v.error,t)}warn(...t){this.p(v.warn,t)}info(...t){this.p(v.info,t)}debug(...t){this.p(v.debug,t)}},Hi={error:l.Function,warn:l.Function,info:l.Function,debug:l.Function},G=class{constructor(t,e){Object.entries(Hi).forEach(([n,s])=>{if(!s.is(t[n]))throw new Error(`Provided logger instance must support logger.${n}(...) method`)}),this.t=t,this.Ie=e}p(t,e){try{this.t[t](...e)}catch(n){this.Ie[t](...e)}}error(...t){this.p("error",t)}warn(...t){this.p("warn",t)}info(...t){this.p("info",t)}debug(...t){this.p("debug",t)}},ne=i=>{let t=new N({level:"info",destination:console.error,formatter:Kt});return i?new G(i,t):t},D=class{static deprecated(t,e){return`"${t}" is deprecated, please use "${e}"`}static optionBelowMinimum(t,e,n){return`Config option "${t}" had invalid value of ${e}, using minimum of ${n} instead`}static unknownOption(t){return`Ignoring unknown config option "${t}"`}static wrongOptionType(t,e,n){return`Config option "${t}" should be of type ${e}, got ${n}, using default value`}static wrongOptionTypeBoolean(t,e){return`Config option "${t}" should be a boolean, got ${e}, converting to boolean`}static invalidTagValue(t){return`Config option "${t}" must only contain letters, numbers, ., _ or -.`}static tagValueTooLong(t){return`Value of "${t}" was longer than 64 characters and was discarded.`}static partialEndpoint(t){return`You have set custom uris without specifying the ${t} URI; connections may not work properly`}},Vi=/^(\w|\.|-)+$/,_i=l.stringMatchingRegex(Vi),Ki={is:(i,t)=>_i.is(i)?i.length>64?{valid:!1,message:D.tagValueTooLong(t)}:{valid:!0}:{valid:!1,message:D.invalidTagValue(t)}},mt=class{constructor(t){let e={},n=t==null?void 0:t.application,s=t==null?void 0:t.logger;n&&Object.entries(n).forEach(([a,o])=>{if(o!=null){let{valid:c,message:u}=Ki.is(o,`application.${a}`);c?a==="versionName"?e["application-version-name"]=[o]:e[`application-${a}`]=[o]:s==null||s.warn(u)}});let r=Object.keys(e);r.length&&(this.value=r.sort().flatMap(a=>e[a].sort().map(o=>`${a}/${o}`)).join(" "))}},yt=class{constructor(t,e,n){this.platform=n,this.basicConfiguration={tags:e.tags,logger:e.logger,offline:e.offline,serviceEndpoints:e.serviceEndpoints,sdkKey:t}}};function Pt(i){return i.replace(/\/+$/,"")}function se(i){return i.replace(/^\/+/,"").replace(/\?$/,"")}var M=class i{constructor(t,e,n=i.DEFAULT_EVENTS,s="/bulk",r="/diagnostic",a=!0,o){this.streaming=Pt(t),this.polling=Pt(e),this.events=Pt(n),this.analyticsEventPath=s,this.diagnosticEventPath=r,this.includeAuthorizationHeader=a,this.payloadFilterKey=o}};M.DEFAULT_EVENTS="https://events.launchdarkly.com";function re(i,t){if(t.length===0)return i;let e=t.map(({key:n,value:s})=>`${n}=${s}`);return`${i}?${e.join("&")}`}function _e(i,t,e){let n=se(t),s=[...e];return i.payloadFilterKey&&s.push({key:"filter",value:i.payloadFilterKey}),re(`${i.streaming}/${n}`,s)}function Ke(i,t,e){let n=se(t),s=[...e];return i.payloadFilterKey&&s.push({key:"filter",value:i.payloadFilterKey}),re(`${i.polling}/${n}`,s)}function Fe(i,t,e){let n=se(t);return re(`${i.events}/${n}`,e)}var q=class extends Error{constructor(t){super(t),this.name="LaunchDarklyUnexpectedResponseError"}},J=class extends Error{constructor(t){super(t),this.name="LaunchDarklyClientError"}},Gt=class extends Error{constructor(t){super(t),this.name="LaunchDarklyTimeoutError"}};function z(i){return i>=400&&i<500?i===400||i===408||i===429:!0}function Gi(i){return i===413?!0:z(i)}function ae(i){return i==null?i:JSON.parse(JSON.stringify(i))}function bt(i){return Math.trunc(i*1e3)}var qi=i=>JSON.stringify(i)==="{}",Dt=(i,t)=>i&&Object.entries(i).reduce((e,[n,s])=>(s&&!qi(s)&&!(t!=null&&t.includes(n))&&(e[n]=typeof s=="object"?Dt(s,t):s),e),{});function _(i,t){if(i===t)return!0;if(i&&t&&typeof i=="object"&&typeof t=="object"){if(i.constructor!==t.constructor)return!1;var e,n,s;if(Array.isArray(i)){if(e=i.length,e!=t.length)return!1;for(n=e;n--!==0;)if(!_(i[n],t[n]))return!1;return!0}if(i instanceof Map&&t instanceof Map){if(i.size!==t.size)return!1;for(n of i.entries())if(!t.has(n[0]))return!1;for(n of i.entries())if(!_(n[1],t.get(n[0])))return!1;return!0}if(i instanceof Set&&t instanceof Set){if(i.size!==t.size)return!1;for(n of i.entries())if(!t.has(n[0]))return!1;return!0}if(ArrayBuffer.isView(i)&&ArrayBuffer.isView(t)){if(e=i.length,e!=t.length)return!1;for(n=e;n--!==0;)if(i[n]!==t[n])return!1;return!0}if(i.constructor===RegExp)return i.source===t.source&&i.flags===t.flags;if(i.valueOf!==Object.prototype.valueOf)return i.valueOf()===t.valueOf();if(i.toString!==Object.prototype.toString)return i.toString()===t.toString();if(s=Object.keys(i),e=s.length,e!==Object.keys(t).length)return!1;for(n=e;n--!==0;)if(!Object.prototype.hasOwnProperty.call(t,s[n]))return!1;for(n=e;n--!==0;){var r=s[n];if(!_(i[r],t[r]))return!1}return!0}return i!==i&&t!==t}function Ge(i,t,e,n=!0,s="user-agent"){let{userAgentBase:r,version:a,wrapperName:o,wrapperVersion:c}=t.sdkData(),u={[s]:`${r!=null?r:"NodeJSClient"}/${a}`};return n&&(u.authorization=i),o&&(u["x-launchdarkly-wrapper"]=c?`${o}/${c}`:o),e!=null&&e.value&&(u["x-launchdarkly-tags"]=e.value),u}function H(i,t,e){let n;i.status?n=`error ${i.status}${i.status===401?" (invalid SDK key)":""}`:n=`I/O error (${i.message||"unknown error"})`;let s=e!=null?e:"giving up permanently";return`Received ${n} for ${t} - ${s}`}function qe({status:i}){return i?z(i):!0}var oe=(i,t)=>t.btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");var Ji=async(i=1e3)=>new Promise(t=>{setTimeout(t,i)}),Je=(i,t)=>new Promise((e,n)=>{setTimeout(()=>{let s=`${t} timed out after ${i} seconds.`;n(new Gt(s))},i*1e3)}),qt=class{constructor(t,e,n){this.r=e,this.Ne=n,this.ft=[],this.Jt=Date.now(),this.Wt=this.Jt,this.zt={diagnosticId:e.crypto.randomUUID(),sdkKeySuffix:t.length>6?t.substring(t.length-6):t}}createInitEvent(){var n,s,r;let t=this.r.info.sdkData(),e=this.r.info.platformData();return{kind:"diagnostic-init",id:this.zt,creationDate:this.Jt,sdk:t,configuration:this.Ne,platform:g({name:e.name,osArch:(n=e.os)==null?void 0:n.arch,osName:(s=e.os)==null?void 0:s.name,osVersion:(r=e.os)==null?void 0:r.version},e.additional||{})}}recordStreamInit(t,e,n){let s={timestamp:t,failed:e,durationMillis:n};this.ft.push(s)}createStatsEventAndReset(t,e,n){let s=Date.now(),r={kind:"diagnostic",id:this.zt,creationDate:s,dataSinceDate:this.Wt,droppedEvents:t,deduplicatedUsers:e,eventsInLastBatch:n,streamInits:this.ft};return this.ft=[],this.Wt=s,r}},Jt;(function(i){i.MalformedFlag="MALFORMED_FLAG",i.UserNotSpecified="USER_NOT_SPECIFIED",i.FlagNotFound="FLAG_NOT_FOUND",i.ClientNotReady="CLIENT_NOT_READY",i.WrongType="WRONG_TYPE"})(Jt||(Jt={}));var Wi=Jt,vt=class{static invalidMetricValue(t){return`The track function was called with a non-numeric "metricValue" (${t}), only numeric metric values are supported.`}};vt.MissingContextKeyNoEvent="Context was unspecified or had no key; event will not be sent";var Wt=class{constructor(t,e){let{basicConfiguration:n,platform:s}=t,{serviceEndpoints:{analyticsEventPath:r,diagnosticEventPath:a}}=n,{crypto:o,requests:c}=s;this.Me=g({},e),this.Yt=Fe(n.serviceEndpoints,r,[]),this.Pe=Fe(n.serviceEndpoints,a,[]),this.E=c,this.Ue=o}async W(t,e,n,s){let r={status:R.Succeeded},a=b(g({},this.Me),{"content-type":"application/json"});n&&(a["x-launchdarkly-payload-id"]=n,a["x-launchDarkly-event-schema"]="4");let o;try{let{status:c,headers:u}=await this.E.fetch(e,{headers:a,body:JSON.stringify(t),compressBodyIfPossible:!0,method:"POST",keepalive:!0}),h=Date.parse(u.get("date")||"");if(h&&(r.serverTime=h),c<=204)return r;if(o=new q(H({status:c,message:"some events were dropped"},"event posting")),!z(c))return Gi(c)?r.status=R.Failed:r.status=R.FailedAndMustShutDown,r.error=o,r}catch(c){o=c}return o&&!s?(r.status=R.Failed,r.error=o,r):(await Ji(),this.W(t,this.Yt,n,!1))}async sendEventData(t,e){let n=t===B.AnalyticsEvents?this.Ue.randomUUID():void 0,s=t===B.AnalyticsEvents?this.Yt:this.Pe;return this.W(e,s,n,!0)}};function zt(i){return i.kind==="feature"}function zi(i){return i.kind==="identify"}function Yi(i){return i.kind==="migration_op"}var Yt=class{constructor(t,e,n,s,r,a){this.count=t,this.key=e,this.value=n,this.version=r,this.variation=a,this.default=s}increment(){this.count+=1}};function Xi(i){return`${i.key}:${i.variation!==null&&i.variation!==void 0?i.variation:""}:${i.version!==null&&i.version!==void 0?i.version:""}`}var Xt=class{constructor(){this.P=0,this.z=0,this.Y={},this.X={}}summarizeEvent(t){if(zt(t)&&!t.excludeFromSummaries){let e=Xi(t),n=this.Y[e],s=this.X[t.key];s||(s=new Set,this.X[t.key]=s),t.context.kinds.forEach(r=>s.add(r)),n?n.increment():this.Y[e]=new Yt(1,t.key,t.value,t.default,t.version,t.variation),(this.P===0||t.creationDate<this.P)&&(this.P=t.creationDate),t.creationDate>this.z&&(this.z=t.creationDate)}}getSummary(){let t=Object.values(this.Y).reduce((e,n)=>{let s=e[n.key];s||(s={default:n.default,counters:[],contextKinds:[...this.X[n.key]]},e[n.key]=s);let r={value:n.value,count:n.count};return n.variation!==void 0&&n.variation!==null&&(r.variation=n.variation),n.version!==void 0&&n.version!==null?r.version=n.version:r.unknown=!0,s.counters.push(r),e},{});return{startDate:this.P,endDate:this.z,features:t,kind:"summary"}}clearSummary(){this.P=0,this.z=0,this.Y={},this.X={}}},Zt=class extends Error{constructor(t){super(t),this.name="LaunchDarklyInvalidSDKKeyError"}};function ft(i){let t=Math.trunc(i);return t===1?!0:t===0?!1:Math.floor(Math.random()*t)===0}var Qt=class{constructor(t,e,n,s,r,a=!0){this.n=t,this.Z=s,this.m=r,this.gt=new Xt,this.Q=[],this.Xt=0,this.pt=0,this.mt=0,this.yt=!1,this.Zt=0,this.vt=!1,this.wt=null,this.Fe=t.eventsCapacity,this.t=e.basicConfiguration.logger,this.Qt=new Wt(e,n),this.tt=new _t(t.allAttributesPrivate,t.privateAttributes.map(o=>new C(o))),a&&this.start()}start(){var t,e;if(((t=this.Z)==null?void 0:t.flushInterval)!==void 0&&(this.wt=setInterval(()=>{var n;(n=this.Z)==null||n.flush()},this.Z.flushInterval*1e3)),this.je=setInterval(async()=>{var n;try{await this.flush()}catch(s){(n=this.t)==null||n.debug(`Flush failed: ${s}`)}},this.n.flushInterval*1e3),this.m){let n=this.m.createInitEvent();this.te(n),this.ee=setInterval(()=>{let s=this.m.createStatsEventAndReset(this.pt,this.mt,this.Zt);this.pt=0,this.mt=0,this.te(s)},this.n.diagnosticRecordingInterval*1e3)}(e=this.t)==null||e.debug("Started EventProcessor.")}te(t){this.Qt.sendEventData(B.DiagnosticEvent,t)}close(){clearInterval(this.je),this.wt&&clearInterval(this.wt),this.ee&&clearInterval(this.ee)}async flush(){var n;if(this.vt)throw new Zt("Events cannot be posted because a permanent error has been encountered. This is most likely an invalid SDK key. The specific error information is logged independently.");let t=this.Q;this.Q=[];let e=this.gt.getSummary();this.gt.clearSummary(),Object.keys(e.features).length&&t.push(e),t.length&&(this.Zt=t.length,(n=this.t)==null||n.debug("Flushing %d events",t.length),await this.W(t))}sendEvent(t){var c;if(this.vt)return;if(Yi(t)){if(ft(t.samplingRatio)){let u=b(g({},t),{context:t.context?this.tt.filter(t.context):void 0});u.samplingRatio===1&&delete u.samplingRatio,this.et(u)}return}this.gt.summarizeEvent(t);let e=zt(t),n=e&&t.trackEvents||!e,s=this.Be(t),r=zi(t),a=(c=this.Z)==null?void 0:c.processContext(t.context);a||r||(this.mt+=1),a&&!r&&this.et(this.Et({kind:"index",creationDate:t.creationDate,context:t.context,samplingRatio:1},!1)),n&&ft(t.samplingRatio)&&this.et(this.Et(t,!1)),s&&ft(t.samplingRatio)&&this.et(this.Et(t,!0))}Et(t,e){switch(t.kind){case"feature":{let n={kind:e?"debug":"feature",creationDate:t.creationDate,context:this.tt.filter(t.context,!e),key:t.key,value:t.value,default:t.default};return t.samplingRatio!==1&&(n.samplingRatio=t.samplingRatio),t.prereqOf&&(n.prereqOf=t.prereqOf),t.variation!==void 0&&(n.variation=t.variation),t.version!==void 0&&(n.version=t.version),t.reason&&(n.reason=t.reason),n}case"index":case"identify":{let n={kind:t.kind,creationDate:t.creationDate,context:this.tt.filter(t.context)};return t.samplingRatio!==1&&(n.samplingRatio=t.samplingRatio),n}case"custom":{let n={kind:"custom",creationDate:t.creationDate,key:t.key,context:this.tt.filter(t.context)};return t.samplingRatio!==1&&(n.samplingRatio=t.samplingRatio),t.data!==void 0&&(n.data=t.data),t.metricValue!==void 0&&(n.metricValue=t.metricValue),t.url!==void 0&&(n.url=t.url),n}case"click":return{kind:"click",creationDate:t.creationDate,contextKeys:t.context.kindsAndKeys,key:t.key,url:t.url,selector:t.selector};case"pageview":return{kind:"pageview",creationDate:t.creationDate,contextKeys:t.context.kindsAndKeys,key:t.key,url:t.url};default:return t}}et(t){var e;this.Q.length<this.Fe?(this.Q.push(t),this.yt=!1):(this.yt||(this.yt=!0,(e=this.t)==null||e.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),this.pt+=1)}Be(t){return zt(t)&&t.debugEventsUntilDate&&t.debugEventsUntilDate>this.Xt&&t.debugEventsUntilDate>Date.now()}async W(t){let e=await this.Qt.sendEventData(B.AnalyticsEvents,t);if(e.status===R.FailedAndMustShutDown&&(this.vt=!0),e.serverTime&&(this.Xt=e.serverTime),e.error)throw e.error}},wt=class{constructor(t,e,n,s,r=1,a){this.context=t,this.key=e,this.data=n,this.metricValue=s,this.samplingRatio=r,this.url=a,this.kind="custom",this.creationDate=Date.now(),this.context=t}},W=class{constructor(t,e,n,s,r,a,o,c,u,h,d,f,p=1){this.withReasons=t,this.context=e,this.key=n,this.samplingRatio=p,this.kind="feature",this.creationDate=Date.now(),this.value=s,this.default=r,a!==void 0&&(this.version=a),o!==void 0&&(this.variation=o),c!==void 0&&(this.trackEvents=c),u!==void 0&&(this.prereqOf=u),h!==void 0&&(this.reason=h),d!==void 0&&(this.debugEventsUntilDate=d),f!==void 0&&(this.excludeFromSummaries=f)}},Et=class{constructor(t,e=1){this.context=t,this.samplingRatio=e,this.kind="identify",this.creationDate=Date.now()}},te=class{close(){}async flush(){}sendEvent(){}},ee=class{constructor(t){this.bt=t}evalEvent(t){var e;return new W(this.bt,t.context,t.flagKey,t.value,t.defaultVal,t.version,(e=t.variation)!=null?e:void 0,t.trackEvents||t.addExperimentData,t.prereqOfFlagKey,this.bt||t.addExperimentData?t.reason:void 0,t.debugEventsUntilDate,t.excludeFromSummaries,t.samplingRatio)}unknownFlagEvent(t,e,n){return new W(this.bt,n,t,e,e,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0)}identifyEvent(t){return new Et(t,1)}customEvent(t,e,n,s,r=1){return new wt(e,t,n!=null?n:void 0,s!=null?s:void 0,r)}},ie=class{constructor(t,e,n,s){this.He=e,this.u=n,this.t=s,this.e=[],this.L=void 0,this.U=void 0,this.it=[],this.Ve=r=>{if(this.F(),!r.payloads.length)return;let a=r.payloads[0];switch(a==null?void 0:a.code){case"xfer-full":this.U=!0;break;case"xfer-changes":case"none":this.U=!1;break;default:return}this.L=a==null?void 0:a.id},this._e=r=>{var o;if(!this.L||!r.kind||!r.key||!r.version||!r.object)return;let a=this.Ke(r.kind,r.object);if(!a){(o=this.t)==null||o.warn(`Unable to prcoess object for kind: '${r.kind}'`);return}this.it.push({kind:r.kind,key:r.key,version:r.version,object:a})},this.Ge=r=>{!this.L||!r.kind||!r.key||!r.version||this.it.push({kind:r.kind,key:r.key,version:r.version,deleted:!0})},this.qe=r=>{if(!this.L||!r.state||!r.version||this.U===void 0){this.F();return}let a={id:this.L,version:r.version,state:r.state,basis:this.U,updates:this.it};this.e.forEach(o=>o(a)),this.F()},this.Je=r=>{var a;(a=this.t)==null||a.info(`Goodbye was received from the LaunchDarkly connection with reason: ${r.reason}.`),this.F()},this.We=r=>{var a;(a=this.t)==null||a.info(`An issue was encountered receiving updates for payload ${this.L} with reason: ${r.reason}. Automatic retry will occur.`),this.F()},this.A(t,"server-intent",this.Ve),this.A(t,"put-object",this._e),this.A(t,"delete-object",this.Ge),this.A(t,"payload-transferred",this.qe),this.A(t,"goodbye",this.Je),this.A(t,"error",this.We)}addPayloadListener(t){this.e.push(t)}removePayloadListener(t){let e=this.e.indexOf(t,0);e>-1&&this.e.splice(e,1)}A(t,e,n){t.addEventListener(e,async s=>{var r,a,o,c,u;if(s!=null&&s.data){(r=this.t)==null||r.debug(`Received ${e} event. Data is ${s.data}`);try{n(JSON.parse(s.data))}catch(h){(a=this.t)==null||a.error(`Stream received data that was unable to be processed in "${e}" message`),(o=this.t)==null||o.debug(`Data follows: ${s.data}`),(c=this.u)==null||c.call(this,w.InvalidData,"Malformed data in event stream")}}else(u=this.u)==null||u.call(this,w.Unknown,"Unexpected message from event stream")})}Ke(t,e){var n,s;return(s=(n=this.He)[t])==null?void 0:s.call(n,e)}F(){this.L=void 0,this.U=void 0,this.it=[]}};function Zi(i){if(i){let t=Object.keys(i).find(e=>e.toLowerCase()==="x-ld-envid");if(t)return{environmentId:i[t]}}}var L=Object.freeze({__proto__:null,ClientMessages:vt,DiagnosticsManager:qt,ErrorKinds:Wi,EventFactoryBase:ee,EventProcessor:Qt,InputCustomEvent:wt,InputEvalEvent:W,InputIdentifyEvent:Et,NullEventProcessor:te,PayloadReader:ie,initMetadataFromHeaders:Zi,isLegacyUser:Ve,isMultiKind:He,isSingleKind:Be,shouldSample:ft});var E;(function(i){i.Initializing="INITIALIZING",i.Valid="VALID",i.Interrupted="INTERRUPTED",i.SetOffline="SET_OFFLINE",i.Closed="CLOSED"})(E||(E={}));function tn(i){return i>=200&&i<=299}var kt=class extends Error{constructor(t,e){super(t),this.status=e,this.name="LaunchDarklyRequestError"}},de=class{constructor(t,e,n,s,r){this.E=t,this.ze=e,this.nt=n,this.Ye=s,this.Xe=r}async requestPayload(){let t;try{let e=await this.E.fetch(this.ze,{method:this.Ye,headers:this.nt,body:this.Xe});if(tn(e.status))return await e.text();t=e.status}catch(e){throw new kt(e==null?void 0:e.message)}throw new kt(`Unexpected status code: ${t}`,t)}};function Se(i,t,e,n,s,r,a,o,c,u){let h,d="GET",f=g({},r);c&&(d="REPORT",f["content-type"]="application/json",h=i);let p=c?e.pathReport(s,i):e.pathGet(s,i),m=[...a!=null?a:[]];o&&m.push({key:"withReasons",value:"true"}),u&&m.push({key:"h",value:u});let y=Ke(t,p,m);return new de(n,y,f,d,h)}var en={logger:l.Object,maxCachedContexts:l.numberWithMin(0),baseUri:l.String,streamUri:l.String,eventsUri:l.String,capacity:l.numberWithMin(1),diagnosticRecordingInterval:l.numberWithMin(2),flushInterval:l.numberWithMin(2),streamInitialReconnectDelay:l.numberWithMin(0),allAttributesPrivate:l.Boolean,debug:l.Boolean,diagnosticOptOut:l.Boolean,withReasons:l.Boolean,sendEvents:l.Boolean,pollInterval:l.numberWithMin(30),useReport:l.Boolean,privateAttributes:l.StringArray,applicationInfo:l.Object,wrapperName:l.String,wrapperVersion:l.String,payloadFilterKey:l.stringMatchingRegex(/^[a-zA-Z0-9](\w|\.|-)*$/),hooks:l.createTypeArray("Hook[]",{}),inspectors:l.createTypeArray("LDInspection",{})},nn=60*5,Ze="https://clientsdk.launchdarkly.com",Qe="https://clientstream.launchdarkly.com";function sn(i){return i instanceof G?i:ne(i)}var fe=class{constructor(t={},e={}){var s,r,a;this.logger=ne(),this.baseUri=Ze,this.eventsUri=M.DEFAULT_EVENTS,this.streamUri=Qe,this.maxCachedContexts=5,this.capacity=100,this.diagnosticRecordingInterval=900,this.flushInterval=30,this.streamInitialReconnectDelay=1,this.allAttributesPrivate=!1,this.debug=!1,this.diagnosticOptOut=!1,this.sendEvents=!0,this.sendLDHeaders=!0,this.useReport=!1,this.withReasons=!1,this.privateAttributes=[],this.pollInterval=nn,this.hooks=[],this.inspectors=[],this.logger=sn(t.logger),this.Ze(t).forEach(o=>this.logger.warn(o)),this.serviceEndpoints=new M(this.streamUri,this.baseUri,this.eventsUri,e.analyticsEventPath,e.diagnosticEventPath,e.includeAuthorizationHeader,t.payloadFilterKey),this.useReport=(s=t.useReport)!=null?s:!1,this.tags=new mt({application:this.applicationInfo,logger:this.logger}),this.userAgentHeaderName=(r=e.userAgentHeaderName)!=null?r:"user-agent",this.trackEventModifier=(a=e.trackEventModifier)!=null?a:o=>o}Ze(t){let e=[];return Object.entries(t).forEach(([n,s])=>{let r=en[n];if(r)if(r.is(s))n==="logger"||(this[n]=s!=null?s:void 0);else{let a=r.getType();if(a==="boolean")e.push(D.wrongOptionTypeBoolean(n,typeof s)),this[n]=!!s;else if(a==="boolean | undefined | null")e.push(D.wrongOptionTypeBoolean(n,typeof s)),typeof s!="boolean"&&typeof s!="undefined"&&s!==null&&(this[n]=!!s);else if(r instanceof K&&l.Number.is(s)){let{min:o}=r;e.push(D.optionBelowMinimum(n,s,o)),this[n]=o}else e.push(D.wrongOptionType(n,r.getType(),typeof s))}else e.push(D.unknownOption(n))}),e}};async function ti(i,t){if(i.digest)return i.digest(t);if(i.asyncDigest)return i.asyncDigest(t);throw new Error("Platform must implement digest or asyncDigest")}var ei=async(i,{crypto:t,storage:e})=>{let n=await(e==null?void 0:e.get(i));return n||(n=t.randomUUID(),await(e==null?void 0:e.set(i,n))),n};function ii(i){return async t=>ti(i.createHash("sha256").update(t),"base64")}var x=async i=>i;async function X(i){return(await Promise.all(i.map(e=>e.transform(e.value)))).join("_")}async function rn(i,t){return X([{value:"LaunchDarkly",transform:x},{value:t,transform:ii(i)}])}async function an(i){return X([{value:"LaunchDarkly",transform:x},{value:"AnonymousKeys",transform:x},{value:i,transform:x}])}async function on(i){return X([{value:"LaunchDarkly",transform:x},{value:"ContextKeys",transform:x},{value:i,transform:x}])}async function cn(i){return X([{value:i,transform:x},{value:"ContextIndex",transform:x}])}async function We(i,t,e){return X([{value:t,transform:x},{value:e.canonicalKey,transform:ii(i)}])}var{isLegacyUser:un,isSingleKind:ce,isMultiKind:ze}=L,ni="1.0",ln=i=>{let n=i,{kind:t}=n,e=Nt(n,["kind"]);return{kind:"multi",[t]:e}},hn=async({crypto:i,info:t},{applicationInfo:e})=>{var a;let{ld_application:n}=t.platformData(),s=(a=Dt(n))!=null?a:{},r=(e==null?void 0:e.id)||(s==null?void 0:s.id);if(r){let o=(e==null?void 0:e.version)||(s==null?void 0:s.version),c=(e==null?void 0:e.name)||(s==null?void 0:s.name),u=(e==null?void 0:e.versionName)||(s==null?void 0:s.versionName);return s=g(g(g(b(g({},s),{id:r}),o?{version:o}:{}),c?{name:c}:{}),u?{versionName:u}:{}),s.key=await ti(i.createHash("sha256").update(r),"base64"),s.envAttributesVersion=s.envAttributesVersion||ni,s}},dn=async i=>{var o,c,u,h;let{ld_device:t,os:e}=i.info.platformData(),n=(o=Dt(t))!=null?o:{},s=(e==null?void 0:e.name)||((c=n.os)==null?void 0:c.name),r=(e==null?void 0:e.version)||((u=n.os)==null?void 0:u.version),a=(h=n.os)==null?void 0:h.family;if((s||r||a)&&(n.os=g(g(g({},s?{name:s}:{}),r?{version:r}:{}),a?{family:a}:{})),Object.keys(n).filter(d=>d!=="key"&&d!=="envAttributesVersion").length){let d=await on("ld_device");return n.key=await ei(d,i),n.envAttributesVersion=n.envAttributesVersion||ni,n}},fn=async(i,t,e)=>{if(un(i))return i;let n,s;if(ce(i)&&i.kind!=="ld_application"||ze(i)&&!i.ld_application?n=await hn(t,e):e.logger.warn("Not adding ld_application environment attributes because it already exists."),ce(i)&&i.kind!=="ld_device"||ze(i)&&!i.ld_device?s=await dn(t):e.logger.warn("Not adding ld_device environment attributes because it already exists."),n||s){let r=ce(i)?ln(i):i;return g(g(g({},r),n?{ld_application:n}:{}),s?{ld_device:s}:{})}return i},{isLegacyUser:gn,isMultiKind:pn,isSingleKind:mn}=L,Le=async(i,t,e)=>{let{anonymous:n,key:s}=t;if(n&&!s){let r=await an(i);t.key=await ei(r,e)}},yn=async(i,t)=>{await Le(i.kind,i,t)},vn=async(i,t)=>{let s=i,{kind:e}=s,n=Nt(s,["kind"]);return Promise.all(Object.entries(n).map(([r,a])=>Le(r,a,t)))},wn=async(i,t)=>{await Le("user",i,t)},En=async(i,t)=>{let e=ae(i);return mn(e)&&await yn(e,t),pn(e)&&await vn(e,t),gn(e)&&await wn(e,t),e},bn=i=>({customBaseURI:i.serviceEndpoints.polling!==Ze,customStreamURI:i.serviceEndpoints.streaming!==Qe,customEventsURI:i.serviceEndpoints.events!==M.DEFAULT_EVENTS,eventsCapacity:i.capacity,eventsFlushIntervalMillis:bt(i.flushInterval),reconnectTimeMillis:bt(i.streamInitialReconnectDelay),diagnosticRecordingIntervalMillis:bt(i.diagnosticRecordingInterval),allAttributesPrivate:i.allAttributesPrivate,usingSecureMode:!1,bootstrapMode:!1}),Dn=(i,t,e)=>{if(t.sendEvents&&!t.diagnosticOptOut)return new L.DiagnosticsManager(i,e,bn(t))};function ue(i,t){return{value:t!=null?t:null,variationIndex:null,reason:{kind:"ERROR",errorKind:i}}}function Ye(i,t,e){return{value:i,variationIndex:t!=null?t:null,reason:e!=null?e:null}}var kn=(i,t,e,n,s)=>{if(t.sendEvents)return new L.EventProcessor(b(g({},t),{eventsCapacity:t.capacity}),new yt(i,t,e),n,void 0,s,!1)},xt=class extends L.EventFactoryBase{evalEventClient(t,e,n,s,r,a){let{trackEvents:o,debugEventsUntilDate:c,trackReason:u,flagVersion:h,version:d,variation:f}=s;return super.evalEvent({addExperimentData:u,context:r,debugEventsUntilDate:c,defaultVal:n,flagKey:t,reason:a,trackEvents:!!o,value:e,variation:f,version:h!=null?h:d})}},Y=class i{constructor(){this.container={index:new Array}}static fromJson(t){let e=new i;try{e.container=JSON.parse(t)}catch(n){}return e}toJson(){return JSON.stringify(this.container)}notice(t,e){let n=this.container.index.find(s=>s.id===t);n===void 0?this.container.index.push({id:t,timestamp:e}):n.timestamp=e}prune(t){let e=Math.max(t,0);return this.container.index.length>e?(this.container.index.sort((n,s)=>n.timestamp-s.timestamp),this.container.index.splice(0,this.container.index.length-e)):[]}},ge=class{constructor(t,e,n,s,r,a,o=()=>Date.now()){this.r=t,this.Dt=e,this.Qe=n,this.l=s,this.b=r,this.t=a,this.st=o,this.ie=cn(this.Dt)}async init(t,e){this.b.init(t,e),await this.ne(t)}async upsert(t,e,n){return this.b.upsert(t,e,n)?(await this.ne(t),!0):!1}async loadCached(t){var s,r,a,o;let e=await We(this.r.crypto,this.Dt,t),n=await((s=this.r.storage)==null?void 0:s.get(e));if(n==null){if(n=await((r=this.r.storage)==null?void 0:r.get(t.canonicalKey)),n==null)return!1;await((a=this.r.storage)==null?void 0:a.set(e,n)),await((o=this.r.storage)==null?void 0:o.clear(t.canonicalKey))}try{let c=JSON.parse(n),u=Object.entries(c).reduce((h,[d,f])=>(h[d]={version:f.version,flag:f},h),{});return this.b.initCached(t,u),this.t.debug("Loaded cached flag evaluations from persistent storage"),!0}catch(c){return this.t.warn(`Could not load cached flag evaluations from persistent storage: ${c.message}`),!1}}async ti(){var e;if(this.C!==void 0)return this.C;let t=await((e=this.r.storage)==null?void 0:e.get(await this.ie));if(!t)return this.C=new Y,this.C;try{this.C=Y.fromJson(t),this.t.debug("Loaded context index from persistent storage")}catch(n){this.t.warn(`Could not load index from persistent storage: ${n.message}`),this.C=new Y}return this.C}async ne(t){var c,u;let e=await this.ti(),n=await We(this.r.crypto,this.Dt,t);e.notice(n,this.st());let s=e.prune(this.Qe);await Promise.all(s.map(async h=>{var d;return(d=this.r.storage)==null?void 0:d.clear(h.id)})),await((c=this.r.storage)==null?void 0:c.set(await this.ie,e.toJson()));let r=this.l.getAll(),a=Object.entries(r).reduce((h,[d,f])=>(f.flag!==null&&f.flag!==void 0&&(h[d]=f.flag),h),{}),o=JSON.stringify(a);await((u=this.r.storage)==null?void 0:u.set(n,o))}},pe=class{constructor(){this.B={}}init(t){this.B=Object.entries(t).reduce((e,[n,s])=>(e[n]=s,e),{})}insertOrUpdate(t,e){this.B[t]=e}get(t){if(Object.prototype.hasOwnProperty.call(this.B,t))return this.B[t]}getAll(){return this.B}};function xn(i,t){let e=[];return Object.entries(i).forEach(([n,s])=>{let r=t[n];(!r||!_(s,r))&&e.push(n)}),Object.keys(t).forEach(n=>{i[n]||e.push(n)}),e}var me=class{constructor(t,e){this.H=new Array,this.l=t,this.t=e}init(t,e){this.se=t.canonicalKey;let n=this.l.getAll();this.l.init(e);let s=xn(n,e);s.length>0&&this.H.forEach(r=>{try{r(t,s,"init")}catch(a){}})}initCached(t,e){this.se!==t.canonicalKey&&this.init(t,e)}upsert(t,e,n){if(this.se!==t.canonicalKey)return this.t.warn("Received an update for an inactive context."),!1;let s=this.l.get(e);return s!==void 0&&s.version>=n.version?!1:(this.l.insertOrUpdate(e,n),this.H.forEach(r=>{try{r(t,[e],"patch")}catch(a){}}),!0)}on(t){this.H.push(t)}off(t){let e=this.H.indexOf(t);e>-1&&this.H.splice(e,1)}},ye=class{constructor(t,e,n,s,r=()=>Date.now()){this.l=new pe,this.b=new me(this.l,s),this.kt=this.ei(t,e,n,s,r)}async ei(t,e,n,s,r=()=>Date.now()){let a=await rn(t.crypto,e);return new ge(t,a,n,this.l,this.b,s,r)}get(t){return this.l.get(t)}getAll(){return this.l.getAll()}setBootstrap(t,e){this.b.init(t,e)}async init(t,e){return(await this.kt).init(t,e)}async upsert(t,e,n){return(await this.kt).upsert(t,e,n)}async loadCached(t){return(await this.kt).loadCached(t)}on(t){this.b.on(t)}off(t){this.b.off(t)}},Xe="unknown hook",si="beforeEvaluation",ri="afterEvaluation";function At(i,t,e,n,s){try{return n()}catch(r){return i==null||i.error(`An error was encountered in "${t}" of the "${e}" hook: ${r}`),s}}function Ct(i,t){try{return t.getMetadata().name||Xe}catch(e){return i.error("Exception thrown getting metadata for hook. Unable to get hook name."),Xe}}function Sn(i,t,e){return t.map(n=>At(i,si,Ct(i,n),()=>{var s,r;return(r=(s=n==null?void 0:n.beforeEvaluation)==null?void 0:s.call(n,e,{}))!=null?r:{}},{}))}function Ln(i,t,e,n,s){for(let r=t.length-1;r>=0;r-=1){let a=t[r],o=n[r];At(i,ri,Ct(i,a),()=>{var c,u;return(u=(c=a==null?void 0:a.afterEvaluation)==null?void 0:c.call(a,e,o,s))!=null?u:{}},{})}}function An(i,t,e){return t.map(n=>At(i,si,Ct(i,n),()=>{var s,r;return(r=(s=n==null?void 0:n.beforeIdentify)==null?void 0:s.call(n,e,{}))!=null?r:{}},{}))}function Cn(i,t,e,n,s){for(let r=t.length-1;r>=0;r-=1){let a=t[r],o=n[r];At(i,ri,Ct(i,a),()=>{var c,u;return(u=(c=a==null?void 0:a.afterIdentify)==null?void 0:c.call(a,e,o,s))!=null?u:{}},{})}}var ve=class{constructor(t,e){this.t=t,this.V=[],this.V.push(...e)}withEvaluation(t,e,n,s){if(this.V.length===0)return s();let r=[...this.V],a={flagKey:t,context:e,defaultValue:n},o=Sn(this.t,r,a),c=s();return Ln(this.t,r,a,o,c),c}identify(t,e){let n=[...this.V],s={context:t,timeout:e},r=An(this.t,n,s);return a=>{Cn(this.t,n,s,r,a)}}addHook(t){this.V.push(t)}};function On(i){return{getMetadata(){return{name:"LaunchDarkly-Inspector-Adapter"}},afterEvaluation:(t,e,n)=>(i.onFlagUsed(t.flagKey,n,t.context),e),afterIdentify(t,e,n){return i.onIdentityChanged(t.context),e}}}function $n(i,t){return`an inspector: "${t}" of an invalid type (${i}) was configured`}function Tn(i,t){return`an inspector: "${t}" of type: "${i}" generated an exception`}function Rn(i,t){let e=!1,n={method:(...s)=>{try{i.method(...s)}catch(r){e||(e=!0,t.warn(Tn(n.type,n.name)))}},type:i.type,name:i.name,synchronous:i.synchronous};return n}var ai="flag-used",oi="flag-details-changed",ci="flag-detail-changed",ui="client-identity-changed",In=[ai,oi,ci,ui];function Nn(i,t){let e=In.includes(i.type)&&i.method&&typeof i.method=="function";return e||t.warn($n(i.type,i.name)),e}var we=class{constructor(t,e){this.$=[];let n=t.filter(s=>Nn(s,e));this.$=n.map(s=>Rn(s,e))}hasInspectors(){return this.$.length!==0}onFlagUsed(t,e,n){this.$.forEach(s=>{s.type===ai&&s.method(t,e,n)})}onFlagsChanged(t){this.$.forEach(e=>{e.type===oi&&e.method(t)})}onFlagChanged(t,e){this.$.forEach(n=>{n.type===ci&&n.method(t,e)})}onIdentityChanged(t){this.$.forEach(e=>{e.type===ui&&e.method(t)})}},Ee=class{constructor(t){this.t=t,this.e=new Map}on(t,e){var n;this.e.has(t)?(n=this.e.get(t))==null||n.push(e):this.e.set(t,[e])}off(t,e){let n=this.e.get(t);if(n){if(e){let s=n.filter(r=>r!==e);s.length===0?this.e.delete(t):this.e.set(t,s);return}this.e.delete(t)}}ii(t,e,...n){var s;try{t(...n)}catch(r){(s=this.t)==null||s.error(`Encountered error invoking handler for "${e}", detail: "${r}"`)}}emit(t,...e){let n=this.e.get(t);n==null||n.forEach(s=>this.ii(s,t,...e))}eventNames(){return[...this.e.keys()]}listenerCount(t){var e,n;return(n=(e=this.e.get(t))==null?void 0:e.length)!=null?n:0}},{ClientMessages:le,ErrorKinds:he}=L,Mn=5,St=class{constructor(t,e,n,s,r,a){if(this.sdkKey=t,this.autoEnvAttributes=e,this.platform=n,this.xt=15,this.D=new xt(!1),this.rt=new xt(!0),this.St=!1,!t)throw new Error("You must configure the client with a client-side SDK key");if(!n.encoding)throw new Error("Platform must implement Encoding because btoa is required.");this.n=new fe(s,a),this.logger=this.n.logger,this.re=Ge(this.sdkKey,this.platform.info,this.n.tags,this.n.serviceEndpoints.includeAuthorizationHeader,this.n.userAgentHeaderName),this.y=new ye(this.platform,t,this.n.maxCachedContexts,this.n.logger),this.m=Dn(t,this.n,n),this.h=kn(t,this.n,n,this.re,this.m),this.emitter=new Ee,this.emitter.on("error",(o,c)=>{this.logger.error(`error: ${c}, context: ${JSON.stringify(o)}`)}),this.y.on((o,c,u)=>{this.ni(c,u);let h=k.toLDContext(o);this.emitter.emit("change",h,c),c.forEach(d=>{this.emitter.emit(`change:${d}`,h)})}),this.dataManager=r(this.y,this.n,this.re,this.emitter,this.m),this.T=new ve(this.logger,this.n.hooks),this._=new we(this.n.inspectors,this.logger),this._.hasInspectors()&&this.T.addHook(On(this._))}allFlags(){return Object.entries(this.y.getAll()).reduce((e,[n,s])=>(s.flag!==null&&s.flag!==void 0&&!s.flag.deleted&&(e[n]=s.flag.value),e),{})}async close(){var t;await this.flush(),(t=this.h)==null||t.close(),this.dataManager.close(),this.logger.debug("Closed event processor and data source.")}async flush(){var t;try{await((t=this.h)==null?void 0:t.flush()),this.logger.debug("Successfully flushed event processor.")}catch(e){return this.logger.error(`Error flushing event processor: ${e}.`),{error:e,result:!1}}return{result:!0}}getContext(){return this.v?ae(this.v):void 0}getInternalContext(){return this.R}si(t,e){let n,s,r=new Promise((c,u)=>{n=c,s=u});if(e)return{identifyPromise:r,identifyResolve:n,identifyReject:s};let a=Je(t,"identify");return{identifyPromise:Promise.race([a,r]).catch(c=>{throw c.message.includes("timed out")&&this.logger.error(`identify error: ${c}`),c}),identifyResolve:n,identifyReject:s}}async identify(t,e){var d,f;let n=(d=e==null?void 0:e.timeout)!=null?d:Mn,s=(e==null?void 0:e.timeout)===void 0&&(e==null?void 0:e.noTimeout)===!0;n>this.xt&&this.logger.warn(`The identify function was called with a timeout greater than ${this.xt} seconds. We recommend a timeout of less than ${this.xt} seconds.`);let r=await En(t,this.platform);this.autoEnvAttributes===j.Enabled&&(r=await fn(r,this.platform,this.n));let a=k.fromLDContext(r);if(!a.valid){let p=new Error("Context was unspecified or had no key");return this.emitter.emit("error",r,p),Promise.reject(p)}this.v=r,this.R=a,(f=this.h)==null||f.sendEvent(this.D.identifyEvent(this.R));let{identifyPromise:o,identifyResolve:c,identifyReject:u}=this.si(n,s);this.logger.debug(`Identifying ${JSON.stringify(this.R)}`);let h=this.T.identify(r,e==null?void 0:e.timeout);return await this.dataManager.identify(c,u,a,e),o.then(p=>(h({status:"completed"}),p),p=>{throw h({status:"error"}),p})}on(t,e){this.emitter.on(t,e)}off(t,e){this.emitter.off(t,e)}track(t,e,n){var s,r;if(!this.R||!this.R.valid){this.logger.warn(le.MissingContextKeyNoEvent);return}n!==void 0&&!l.Number.is(n)&&((s=this.logger)==null||s.warn(le.invalidMetricValue(typeof n))),(r=this.h)==null||r.sendEvent(this.n.trackEventModifier(this.D.customEvent(t,this.R,e,n)))}at(t,e,n,s){var f,p,m;if(!this.v)return this.logger.debug(le.MissingContextKeyNoEvent),ue(he.UserNotSpecified,e);let r=k.fromLDContext(this.v),a=this.y.get(t);if(a===void 0||a.flag.deleted){let y=e!=null?e:null,S=new J(`Unknown feature flag "${t}"; returning default value ${y}.`);return this.emitter.emit("error",this.v,S),(f=this.h)==null||f.sendEvent(this.D.unknownFlagEvent(t,y,r)),ue(he.FlagNotFound,e)}let{reason:o,value:c,variation:u,prerequisites:h}=a.flag;if(s){let[y,S]=s(c);if(!y){(p=this.h)==null||p.sendEvent(n.evalEventClient(t,e,e,a.flag,r,o));let P=new J(`Wrong type "${S}" for feature flag "${t}"; returning default value`);return this.emitter.emit("error",this.v,P),ue(he.WrongType,e)}}let d=Ye(c,u,o);return c==null&&(this.logger.debug("Result value is null. Providing default value."),d.value=e),h==null||h.forEach(y=>{this.at(y,void 0,this.D)}),(m=this.h)==null||m.sendEvent(n.evalEventClient(t,c,e,a.flag,r,o)),d}variation(t,e){let{value:n}=this.T.withEvaluation(t,this.v,e,()=>this.at(t,e,this.D));return n}variationDetail(t,e){return this.T.withEvaluation(t,this.v,e,()=>this.at(t,e,this.rt))}I(t,e,n,s){return this.T.withEvaluation(t,this.v,e,()=>this.at(t,e,n,s))}boolVariation(t,e){return this.I(t,e,this.D,n=>[l.Boolean.is(n),l.Boolean.getType()]).value}jsonVariation(t,e){return this.variation(t,e)}numberVariation(t,e){return this.I(t,e,this.D,n=>[l.Number.is(n),l.Number.getType()]).value}stringVariation(t,e){return this.I(t,e,this.D,n=>[l.String.is(n),l.String.getType()]).value}boolVariationDetail(t,e){return this.I(t,e,this.rt,n=>[l.Boolean.is(n),l.Boolean.getType()])}numberVariationDetail(t,e){return this.I(t,e,this.rt,n=>[l.Number.is(n),l.Number.getType()])}stringVariationDetail(t,e){return this.I(t,e,this.rt,n=>[l.String.is(n),l.String.getType()])}jsonVariationDetail(t,e){return this.variationDetail(t,e)}addHook(t){this.T.addHook(t)}setEventSendingEnabled(t,e){var n,s,r,a;this.St!==t&&(this.St=t,t?(this.logger.debug("Starting event processor"),(n=this.h)==null||n.start()):e?((s=this.logger)==null||s.debug("Flushing event processor before disabling."),this.flush().then(()=>{var o,c;this.St||((o=this.logger)==null||o.debug("Stopping event processor."),(c=this.h)==null||c.close())})):((r=this.logger)==null||r.debug("Stopping event processor."),(a=this.h)==null||a.close()))}sendEvent(t){var e;(e=this.h)==null||e.sendEvent(t)}ni(t,e){if(!this._.hasInspectors())return;let n={};t.forEach(s=>{let r=this.y.get(s);if(r!=null&&r.flag&&!r.flag.deleted){let{reason:a,value:o,variation:c}=r.flag;n[s]=Ye(o,c,a)}else n[s]={value:void 0,reason:null,variationIndex:null}}),e==="init"?this._.onFlagsChanged(n):e==="patch"&&Object.entries(n).forEach(([s,r])=>{this._.onFlagChanged(s,r)})}},be=class{constructor(t,e,n){this.y=t,this.Lt=e,this.t=n}async handlePut(t,e){this.t.debug(`Got PUT: ${Object.keys(e)}`);let n=Object.entries(e).reduce((s,[r,a])=>(s[r]={version:a.version,flag:a},s),{});await this.y.init(t,n),this.Lt.requestStateUpdate(E.Valid)}async handlePatch(t,e){this.t.debug(`Got PATCH ${JSON.stringify(e,null,2)}`),this.y.upsert(t,e.key,{version:e.version,flag:e})}async handleDelete(t,e){this.t.debug(`Got DELETE ${JSON.stringify(e,null,2)}`),this.y.upsert(t,e.key,{version:e.version,flag:b(g({},e),{deleted:!0,flagVersion:0,value:void 0,variation:0,trackEvents:!1})})}handleStreamingError(t){this.Lt.reportError(t.kind,t.message,t.code,t.recoverable)}handlePollingError(t){this.Lt.reportError(t.kind,t.message,t.status,t.recoverable)}},De=class{constructor(t,e=()=>Date.now()){this.ri=t,this.ot=E.Closed,this.ae=e(),this.st=e}get status(){return{state:this.ot,stateSince:this.ae,lastError:this.ai}}oe(t,e=!1){let n=t===E.Interrupted&&this.ot===E.Initializing?E.Initializing:t,s=this.ot!==n;s&&(this.ot=n,this.ae=this.st()),(s||e)&&this.ri.emit("dataSourceStatus",this.status)}requestStateUpdate(t){this.oe(t)}reportError(t,e,n,s=!1){let r={kind:t,message:e,statusCode:n,time:this.st()};this.ai=r,this.oe(s?E.Interrupted:E.Closed,!0)}},ke=class{constructor(t,e,n,s,r){this.oi=t,this.ci=e,this.ui=n,this.u=s,this.t=r,this.ce=!1}async ue(){var r,a,o,c,u,h,d;if(this.ce)return;let t=f=>{var p,m,y;(p=this.t)==null||p.error("Polling received invalid data"),(m=this.t)==null||m.debug(`Invalid JSON follows: ${f}`),(y=this.u)==null||y.call(this,new I(w.InvalidData,"Malformed JSON data in polling response"))};(r=this.t)==null||r.debug("Polling LaunchDarkly for feature flag updates");let e=Date.now();try{let f=await this.oi.requestPayload();try{let p=JSON.parse(f);try{(a=this.ui)==null||a.call(this,p)}catch(m){(o=this.t)==null||o.error(`Exception from data handler: ${m}`)}}catch(p){t(f)}}catch(f){let p=f;if(p.status!==void 0&&!z(p.status)){(c=this.t)==null||c.error(H(f,"polling request")),(u=this.u)==null||u.call(this,new I(w.ErrorResponse,p.message,p.status));return}(h=this.t)==null||h.error(H(f,"polling request","will retry"))}let n=Date.now()-e,s=Math.max(this.ci*1e3-n,0);(d=this.t)==null||d.debug("Elapsed: %d ms, sleeping for %d ms",n,s),this.At=setTimeout(()=>{this.ue()},s)}start(){this.ue()}stop(){this.At&&(clearTimeout(this.At),this.At=void 0),this.ce=!0}close(){this.stop()}},Pn=(i,t,e,n)=>{e==null||e.error(`Stream received invalid data in "${i}" message`),e==null||e.debug(`Invalid JSON follows: ${t}`),n==null||n(new F(w.InvalidData,"Malformed JSON data in event stream"))},xe=class{constructor(t,e,n,s,r,a,o,c,u){var f;this.li=t,this.Ct=e,this.e=n,this.E=s,this.hi=a,this.m=o,this.u=c,this.t=u;let h;e.useReport&&!s.getEventSourceCapabilities().customMethod?h=e.paths.pathPing(r,t):h=e.useReport?e.paths.pathReport(r,t):e.paths.pathGet(r,t);let d=[...(f=e.queryParameters)!=null?f:[]];this.Ct.withReasons&&d.push({key:"withReasons",value:"true"}),this.E=s,this.nt=g({},e.baseHeaders),this.t=u,this.di=_e(e.serviceEndpoints,h,d)}le(){this.ct=Date.now()}Ot(t){this.ct&&this.m&&this.m.recordStreamInit(this.ct,!t,Date.now()-this.ct),this.ct=void 0}fi(t){var e,n,s;return qe(t)?((s=this.t)==null||s.warn(H(t,"streaming request","will retry")),this.Ot(!1),this.le(),!0):(this.Ot(!1),(e=this.u)==null||e.call(this,new F(w.ErrorResponse,t.message,t.status,!1)),(n=this.t)==null||n.error(H(t,"streaming request")),!1)}start(){this.le();let t;this.Ct.useReport?(this.nt["content-type"]="application/json",t={method:"REPORT",body:this.li}):t={};let e=this.E.createEventSource(this.di,b(g({headers:this.nt},t),{errorFilter:n=>this.fi(n),initialRetryDelayMillis:this.Ct.initialRetryDelayMillis,readTimeoutMillis:5*60*1e3,retryResetIntervalMillis:60*1e3}));this.he=e,e.onclose=()=>{var n;(n=this.t)==null||n.info("Closed LaunchDarkly stream connection")},e.onerror=()=>{},e.onopen=()=>{var n;(n=this.t)==null||n.info("Opened LaunchDarkly stream connection")},e.onretrying=n=>{var s;(s=this.t)==null||s.info(`Will retry stream connection in ${n.delayMillis} milliseconds`)},this.e.forEach(({deserializeData:n,processJson:s},r)=>{e.addEventListener(r,a=>{var o,c;if((o=this.t)==null||o.debug(`Received ${r} event`),a!=null&&a.data){this.Ot(!0);let{data:u}=a,h=n(u);if(!h){Pn(r,u,this.t,this.u);return}s(h)}else(c=this.u)==null||c.call(this,new F(w.InvalidData,"Unexpected payload from event stream"))})}),e.addEventListener("ping",async()=>{var n,s,r,a,o,c,u;(n=this.t)==null||n.debug("Got PING, going to poll LaunchDarkly for feature flag updates");try{let h=await this.hi.requestPayload();try{let d=JSON.parse(h);try{(s=this.e.get("put"))==null||s.processJson(d)}catch(f){(r=this.t)==null||r.error(`Exception from data handler: ${f}`)}}catch(d){(a=this.t)==null||a.error("Polling after ping received invalid data"),(o=this.t)==null||o.debug(`Invalid JSON follows: ${h}`),(c=this.u)==null||c.call(this,new I(w.InvalidData,"Malformed JSON data in ping polling response"))}}catch(h){let d=h;(u=this.u)==null||u.call(this,new I(w.ErrorResponse,d.message,d.status))}})}stop(){var t;(t=this.he)==null||t.close(),this.he=void 0}close(){this.stop()}},Lt=class{constructor(t,e,n,s,r,a,o,c,u){this.platform=t,this.flagManager=e,this.credential=n,this.config=s,this.getPollingPaths=r,this.getStreamingPaths=a,this.baseHeaders=o,this.emitter=c,this.diagnosticsManager=u,this.closed=!1,this.logger=s.logger,this.dataSourceStatusManager=new De(c),this.N=new be(e,this.dataSourceStatusManager,this.config.logger)}setConnectionParams(t){this.gi=t}createPollingProcessor(t,e,n,s,r){let a=new ke(n,this.config.pollInterval,async o=>{await this.N.handlePut(e,o),s==null||s()},o=>{this.emitter.emit("error",t,o),this.N.handlePollingError(o),r==null||r(o)},this.logger);this.updateProcessor=this.de(a,this.dataSourceStatusManager)}createStreamingProcessor(t,e,n,s,r){var o;let a=new xe(JSON.stringify(t),{credential:this.credential,serviceEndpoints:this.config.serviceEndpoints,paths:this.getStreamingPaths(),baseHeaders:this.baseHeaders,initialRetryDelayMillis:this.config.streamInitialReconnectDelay*1e3,withReasons:this.config.withReasons,useReport:this.config.useReport,queryParameters:(o=this.gi)==null?void 0:o.queryParameters},this.createStreamListeners(e,s),this.platform.requests,this.platform.encoding,n,this.diagnosticsManager,c=>{this.emitter.emit("error",t,c),this.N.handleStreamingError(c),r==null||r(c)},this.logger);this.updateProcessor=this.de(a,this.dataSourceStatusManager)}createStreamListeners(t,e){let n=new Map;return n.set("put",{deserializeData:JSON.parse,processJson:async s=>{await this.N.handlePut(t,s),e==null||e()}}),n.set("patch",{deserializeData:JSON.parse,processJson:async s=>{this.N.handlePatch(t,s)}}),n.set("delete",{deserializeData:JSON.parse,processJson:async s=>{this.N.handleDelete(t,s)}}),n}de(t,e){return{start:()=>{e.requestStateUpdate(E.Initializing),t.start()},stop:()=>{t.stop(),e.requestStateUpdate(E.Closed)},close:()=>{t.close(),e.requestStateUpdate(E.Closed)}}}close(){var t;(t=this.updateProcessor)==null||t.close(),this.closed=!0}};function Ot(){return typeof document!==void 0}function Ae(){return typeof window!==void 0}function $t(i,t,e){return Ot()?(document.addEventListener(i,t,e),()=>{document.removeEventListener(i,t,e)}):()=>{}}function Tt(i,t,e){return Ot()?(window.addEventListener(i,t,e),()=>{window.removeEventListener(i,t,e)}):()=>{}}function A(){return Ae()?window.location.href:""}function li(){return Ae()?window.location.search:""}function hi(){return Ae()?window.location.hash:""}function di(){if(typeof crypto!==void 0)return crypto;throw Error("Access to a web crypto API is required")}function fi(){return Ot()?document.visibilityState:"visibile"}function gi(i){if(Ot())return document.querySelectorAll(i)}function pi(i,t){let e=Object.keys(t),n="$flagsState",s="$valid",r=t[n];!r&&e.length&&i.warn("LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."),t[s]===!1&&i.warn("LaunchDarkly bootstrap data is not available because the back end could not read the flags.");let a={};return e.forEach(o=>{if(o!==n&&o!==s){let c;r&&r[o]?c=g({value:t[o]},r[o]):c={value:t[o],version:0},a[o]={version:c.version,flag:c}}}),a}var Un="[BrowserDataManager]",Z=class extends Lt{constructor(e,n,s,r,a,o,c,u,h,d){super(e,n,s,r,o,c,u,h,d);this.Oi=a;this.K=void 0;this.$t=!1;this.K=a.streaming}k(e,...n){this.logger.debug(`${Un} ${e}`,...n)}async identify(e,n,s,r){if(this.closed){this.k("Identify called after data manager was closed.");return}this.context=s;let a=r;a!=null&&a.hash?this.setConnectionParams({queryParameters:[{key:"h",value:a.hash}]}):this.setConnectionParams(),this.Tt=a==null?void 0:a.hash,a!=null&&a.bootstrap?this.pi(s,a.bootstrap,e):(await this.flagManager.loadCached(s)&&this.k("Identify - Flags loaded from cache. Continuing to initialize via a poll."),await this.mi(s,e,n)),this.Rt()}async mi(e,n,s){var r,a;try{this.dataSourceStatusManager.requestStateUpdate(E.Initializing);let o=JSON.stringify(k.toLDContext(e)),u=await Se(o,this.config.serviceEndpoints,this.getPollingPaths(),this.platform.requests,this.platform.encoding,this.baseHeaders,[],this.config.withReasons,this.config.useReport,this.Tt).requestPayload();try{let d=this.createStreamListeners(e,n).get("put");d.processJson(d.deserializeData(u))}catch(h){this.dataSourceStatusManager.reportError(w.InvalidData,(r=h.message)!=null?r:"Could not parse poll response")}}catch(o){this.dataSourceStatusManager.reportError(w.NetworkError,(a=o.message)!=null?a:"unexpected network error",o.status),s(o)}}pi(e,n,s){this.flagManager.setBootstrap(e,pi(this.logger,n)),this.k("Identify - Initialization completed from bootstrap"),s()}setForcedStreaming(e){this.K=e,this.Rt()}setAutomaticStreamingState(e){this.$t=e,this.Rt()}Rt(){let e=this.K||this.$t&&this.K===void 0;this.k(`Updating streaming state. forced(${this.K}) automatic(${this.$t})`),e?this.yi():this.vi()}vi(){var e;this.updateProcessor&&this.k("Stopping update processor."),(e=this.updateProcessor)==null||e.close(),this.updateProcessor=void 0}yi(){if(this.updateProcessor){this.k("Update processor already active. Not changing state.");return}if(!this.context){this.k("Context not set, not starting update processor.");return}this.k("Starting update processor."),this.wi(this.context)}wi(e,n,s){var c;let r=k.toLDContext(e);(c=this.updateProcessor)==null||c.close();let a=JSON.stringify(k.toLDContext(e)),o=Se(a,this.config.serviceEndpoints,this.getPollingPaths(),this.platform.requests,this.platform.encoding,this.baseHeaders,[],this.config.withReasons,this.config.useReport,this.Tt);this.createStreamingProcessor(r,e,o,n,s),this.updateProcessor.start()}};function mi(i){let e=$t("visibilitychange",()=>{fi()==="hidden"&&i()}),n=Tt("pagehide",i);return()=>{e(),n()}}function Q(i){if(typeof i!="string")throw new TypeError("Expected a string");return i.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function Fn(i,t,e,n){let r=((i.kind==="substring"||i.kind==="regex")&&n.includes("/")?t:t.replace(n,"")).replace(e,"");switch(i.kind){case"exact":return new RegExp(`^${Q(i.url)}/?$`).test(t);case"canonical":return new RegExp(`^${Q(i.url)}/?$`).test(r);case"substring":return new RegExp(`.*${Q(i.substring)}.*$`).test(r);case"regex":return new RegExp(i.pattern).test(r);default:return!1}}function jn(i,t){let e=[];return t.forEach(n=>{let s=i.target,{selector:r}=n,a=gi(r);for(;s&&(a!=null&&a.length);){for(let o=0;o<a.length;o+=1)if(s===a[o]){e.push(n);break}s=s.parentNode}}),e}var tt=class{constructor(t,e){let n=t.filter(a=>{var o;return(o=a.urls)==null?void 0:o.some(c=>Fn(c,A(),li(),hi()))}),s=n.filter(a=>a.kind==="pageview"),r=n.filter(a=>a.kind==="click");if(s.forEach(a=>e(a)),r.length){let a=o=>{jn(o,r).forEach(c=>{e(c)})};this.fe=$t("click",a)}}close(){var t;(t=this.fe)==null||t.call(this)}};var Bn=300,Rt=class{constructor(t){this.It=A();let e=()=>{let s=A();s!==this.It&&(this.It=s,t())};this.Nt=setInterval(e,Bn);let n=Tt("popstate",e);this.ge=()=>{n()}}close(){var t;this.Nt&&clearInterval(this.Nt),(t=this.ge)==null||t.call(this)}};var et=class{constructor(t,e,n,s,r,a=o=>new Rt(o)){this.E=e;this.Di=s;this.bi=r;this.ut=[];this.me=!1;this.lt=`${n}/sdk/goals/${t}`,this.pe=a(()=>{this.Pt()})}async initialize(){await this.Ei(),this.Pt()}startTracking(){this.me=!0,this.Pt()}Pt(){var t;this.me&&((t=this.Mt)==null||t.close(),this.ut&&this.ut.length&&(this.Mt=new tt(this.ut,e=>{this.bi(A(),e)})))}async Ei(){try{let t=await this.E.fetch(this.lt);this.ut=await t.json()}catch(t){this.Di(new q(`Encountered error fetching goals: ${t}`))}}close(){var t,e;(t=this.pe)==null||t.close(),(e=this.Mt)==null||e.close()}};function yi(i){return i.kind==="click"}var Hn=2,vi={fetchGoals:!0,eventUrlTransformer:i=>i,streaming:void 0},Vn={fetchGoals:l.Boolean,eventUrlTransformer:l.Function,streaming:l.Boolean};function _n(i){var e;let t=g({},i);return(e=t.flushInterval)!=null||(t.flushInterval=Hn),t}function wi(i){let t=_n(i);return Object.keys(vi).forEach(e=>{delete t[e]}),t}function Ce(i,t){let e=g({},vi);return Object.entries(Vn).forEach(n=>{let[s,r]=n,a=i[s];a!==void 0&&(r.is(a)?e[s]=a:t.warn(D.wrongOptionType(s,r.getType(),typeof a)))}),e}var it=class{constructor(t,e){this.ki=t;this.ye=[];switch(e){case"sha1":this.Ut="SHA-1";break;case"sha256":this.Ut="SHA-256";break;default:throw new Error(`Algorithm is not supported ${e}`)}}async asyncDigest(t){let e=this.ye.join(""),n=new TextEncoder().encode(e),s=await this.ki.subtle.digest(this.Ut,n);switch(t){case"base64":return btoa(String.fromCharCode(...new Uint8Array(s)));case"hex":return[...new Uint8Array(s)].map(r=>r.toString(16).padStart(2,"0")).join("");default:throw new Error(`Encoding is not supported ${t}`)}}update(t){return this.ye.push(t),this}};var Kn={start:0,end:3},Gn={start:4,end:5},Oe={start:6,end:7},$e={start:8,end:8},qn={start:9,end:9},Jn={start:10,end:15};function Wn(){if(crypto&&crypto.getRandomValues){let t=new Uint8Array(16);return crypto.getRandomValues(t),[...t.values()]}let i=[];for(let t=0;t<16;t+=1)i.push(Math.floor(Math.random()*256));return i}function V(i,t){let e="";for(let n=t.start;n<=t.end;n+=1)e+=i[n].toString(16).padStart(2,"0");return e}function zn(i){return i[$e.start]=(i[$e.start]|128)&191,i[Oe.start]=i[Oe.start]&15|64,`${V(i,Kn)}-${V(i,Gn)}-${V(i,Oe)}-${V(i,$e)}${V(i,qn)}-${V(i,Jn)}`}function Yn(){let i=Wn();return zn(i)}function Te(){return typeof crypto!==void 0&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Yn()}var nt=class{createHash(t){return new it(di(),t)}randomUUID(){return Te()}};function Xn(i){let t=Array.from(i,e=>String.fromCodePoint(e)).join("");return btoa(t)}var st=class{btoa(t){return Xn(new TextEncoder().encode(t))}};var rt=class{platformData(){return{name:"JS"}}sdkData(){return{name:"@launchdarkly/js-client-sdk",version:"0.0.0",userAgentBase:"JSClient"}}};var at=class{constructor(t,e,n=Math.random){this.Li=e;this.Si=n;this.Ft=0;this.jt=Math.max(1,t),this.ve=Math.ceil(Math.log2(3e4/this.jt))}G(){let t=Math.min(this.Ft,this.ve),e=this.jt*2**t;return Math.min(e,3e4)}xi(t){return t-Math.trunc(this.Si()*.5*t)}success(t=Date.now()){this.ht=t}fail(t=Date.now()){this.ht!==void 0&&t-this.ht>this.Li&&(this.Ft=0),this.ht=void 0;let e=this.xi(this.G());return this.Ft+=1,e}};var ot=class{constructor(t,e){this.lt=t;this.e={};this.G=new at(e.initialRetryDelayMillis,e.retryResetIntervalMillis),this.we=e.errorFilter,this.Ee()}Ee(){this.M=new EventSource(this.lt),this.M.onopen=()=>{var t;this.G.success(),(t=this.onopen)==null||t.call(this)},this.M.onerror=t=>{var e;this.Ai(t),(e=this.onerror)==null||e.call(this,t)},Object.entries(this.e).forEach(([t,e])=>{e.forEach(n=>{var s;(s=this.M)==null||s.addEventListener(t,n)})})}addEventListener(t,e){var n,s,r;(s=(n=this.e)[t])!=null||(n[t]=[]),this.e[t].push(e),(r=this.M)==null||r.addEventListener(t,e)}close(){var t,e;clearTimeout(this.Bt),this.Bt=void 0,(t=this.M)==null||t.close(),(e=this.onclose)==null||e.call(this)}Ci(t){var e;(e=this.onretrying)==null||e.call(this,{delayMillis:t}),this.Bt=setTimeout(()=>{this.Ee()},t)}Ai(t){this.close(),!(t.status&&typeof t.status=="number"&&!this.we(t))&&this.Ci(this.G.fail())}};var ct=class{fetch(t,e){return fetch(t,e)}createEventSource(t,e){return new ot(t,e)}getEventSourceCapabilities(){return{customMethod:!1,readTimeout:!1,headers:!1}}};function Ei(){return typeof localStorage!="undefined"}var ut=class{constructor(t){this.t=t}async clear(t){var e;try{localStorage.removeItem(t)}catch(n){(e=this.t)==null||e.error(`Error clearing key from localStorage: ${t}, reason: ${n}`)}}async get(t){var e;try{let n=localStorage.getItem(t);return n!=null?n:null}catch(n){return(e=this.t)==null||e.error(`Error getting key from localStorage: ${t}, reason: ${n}`),null}}async set(t,e){var n;try{localStorage.setItem(t,e)}catch(s){(n=this.t)==null||n.error(`Error setting key in localStorage: ${t}, reason: ${s}`)}}};var lt=class{constructor(t){this.encoding=new st;this.info=new rt;this.crypto=new nt;this.requests=new ct;Ei()&&(this.storage=new ut(t))}};var It=class extends St{constructor(t,e,n={},s){var p;let{logger:r,debug:a}=n,o=r!=null?r:new N({destination:{debug:console.debug,info:console.info,warn:console.warn,error:console.error},level:a?"debug":"info"}),c=(p=n.baseUri)!=null?p:"https://clientsdk.launchdarkly.com",u=s!=null?s:new lt(o),h=Ce(n,o),d=wi(b(g({},n),{logger:o})),{eventUrlTransformer:f}=h;super(t,e,u,d,(m,y,S,P,bi)=>new Z(u,m,t,y,h,()=>({pathGet($,T){return`/sdk/evalx/${t}/contexts/${oe(T,$)}`},pathReport($,T){return`/sdk/evalx/${t}/context`},pathPing($,T){throw new Error("Ping for polling unsupported.")}}),()=>({pathGet($,T){return`/eval/${t}/${oe(T,$)}`},pathReport($,T){return`/eval/${t}`},pathPing($,T){return`/ping/${t}`}}),S,P,bi),{analyticsEventPath:`/events/bulk/${t}`,diagnosticEventPath:`/events/diagnostic/${t}`,includeAuthorizationHeader:!1,highTimeoutThreshold:5,userAgentHeaderName:"x-launchdarkly-user-agent",trackEventModifier:m=>new L.InputCustomEvent(m.context,m.key,m.data,m.metricValue,m.samplingRatio,f(A()))}),this.setEventSendingEnabled(!0,!1),h.fetchGoals&&(this.Ht=new et(t,u.requests,c,m=>{o.error(m.message)},(m,y)=>{let S=this.getInternalContext();if(!S)return;let P=f(m);yi(y)?this.sendEvent({kind:"click",url:P,samplingRatio:1,key:y.key,creationDate:Date.now(),context:S,selector:y.selector}):this.sendEvent({kind:"pageview",url:P,samplingRatio:1,key:y.key,creationDate:Date.now(),context:S})}),this.Ht.initialize(),h.automaticBackgroundHandling&&mi(()=>this.flush()))}async identify(t,e){var n;await super.identify(t,e),(n=this.Ht)==null||n.startTracking()}setStreaming(t){this.dataManager.setForcedStreaming(t)}be(){this.dataManager.setAutomaticStreamingState(!!this.emitter.listenerCount("change"))}on(t,e){super.on(t,e),this.be()}off(t,e){super.off(t,e),this.be()}};function Tr(i){return new N(i)}function Pr(i,t){return new It(i,j.Disabled,t)}export{Tr as basicLogger,Pr as initialize};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|