@launchdarkly/js-client-sdk 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.12.0](https://github.com/launchdarkly/js-core/compare/js-client-sdk-v0.11.0...js-client-sdk-v0.12.0) (2026-01-06)
4
+
5
+
6
+ ### Features
7
+
8
+ * add legacy storage key cleanup functionality ([#1043](https://github.com/launchdarkly/js-core/issues/1043)) ([fe4725e](https://github.com/launchdarkly/js-core/commit/fe4725e24917fe795cee448383b4fe8fa8b4b56f))
9
+ * add waitForInitialization to RN SDK ([#1048](https://github.com/launchdarkly/js-core/issues/1048)) ([13ce456](https://github.com/launchdarkly/js-core/commit/13ce456d9e3a5bcf043734f757415d4856034257))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @launchdarkly/js-client-sdk-common bumped from 1.16.0 to 1.17.0
17
+
3
18
  ## [0.11.0](https://github.com/launchdarkly/js-core/compare/js-client-sdk-v0.10.0...js-client-sdk-v0.11.0) (2025-12-18)
4
19
 
5
20
 
@@ -1,4 +1,4 @@
1
- import { LDIdentifyOptions, LDClient as LDClient$1, LDContext, LDIdentifyResult, LDPluginBase, Hook, LDOptions, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common';
1
+ import { LDIdentifyOptions, LDClient as LDClient$1, LDContext, LDIdentifyResult, LDWaitForInitializationOptions, LDWaitForInitializationResult, LDPluginBase, Hook, LDOptions, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common';
2
2
 
3
3
  /**
4
4
  * @property sheddable - If true, the identify operation will be sheddable. This means that if multiple identify operations are done, without
@@ -29,55 +29,6 @@ interface BrowserIdentifyOptions extends Omit<LDIdentifyOptions, 'waitForNetwork
29
29
  bootstrap?: unknown;
30
30
  }
31
31
 
32
- /**
33
- * @ignore
34
- * Currently these options and the waitForInitialization method signiture will mirror the one
35
- * that is defined in the server common. We will be consolidating this mehod so that it will
36
- * be common to all sdks in the future.
37
- */
38
- /**
39
- * Options for the waitForInitialization method.
40
- */
41
- interface LDWaitForInitializationOptions {
42
- /**
43
- * The timeout duration in seconds to wait for initialization before resolving the promise.
44
- * If exceeded, the promise will resolve to a {@link LDWaitForInitializationTimeout} object.
45
- *
46
- * If no options are specified on the `waitForInitialization`, the default timeout of 5 seconds will be used.
47
- *
48
- * Using a high timeout, or no timeout, is not recommended because it could result in a long
49
- * delay when conditions prevent successful initialization.
50
- *
51
- * A value of 0 will cause the promise to resolve without waiting. In that scenario it would be
52
- * more effective to not call `waitForInitialization`.
53
- *
54
- * @default 5 seconds
55
- */
56
- timeout?: number;
57
- }
58
- /**
59
- * The waitForInitialization operation failed.
60
- */
61
- interface LDWaitForInitializationFailed {
62
- status: 'failed';
63
- error: Error;
64
- }
65
- /**
66
- * The waitForInitialization operation timed out.
67
- */
68
- interface LDWaitForInitializationTimeout {
69
- status: 'timeout';
70
- }
71
- /**
72
- * The waitForInitialization operation completed successfully.
73
- */
74
- interface LDWaitForInitializationComplete {
75
- status: 'complete';
76
- }
77
- /**
78
- * The result of the waitForInitialization operation.
79
- */
80
- type LDWaitForInitializationResult = LDWaitForInitializationFailed | LDWaitForInitializationTimeout | LDWaitForInitializationComplete;
81
32
  interface LDStartOptions extends LDWaitForInitializationOptions {
82
33
  /**
83
34
  * Optional bootstrap data to use for the identify operation. If {@link LDIdentifyOptions.bootstrap} is provided, it will be ignored.
@@ -1,4 +1,4 @@
1
- import { LDIdentifyOptions, LDClient as LDClient$1, LDContext, LDIdentifyResult, LDPluginBase, Hook, LDOptions, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common';
1
+ import { LDIdentifyOptions, LDClient as LDClient$1, LDContext, LDIdentifyResult, LDWaitForInitializationOptions, LDWaitForInitializationResult, LDPluginBase, Hook, LDOptions, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common';
2
2
 
3
3
  /**
4
4
  * @property sheddable - If true, the identify operation will be sheddable. This means that if multiple identify operations are done, without
@@ -29,55 +29,6 @@ interface BrowserIdentifyOptions extends Omit<LDIdentifyOptions, 'waitForNetwork
29
29
  bootstrap?: unknown;
30
30
  }
31
31
 
32
- /**
33
- * @ignore
34
- * Currently these options and the waitForInitialization method signiture will mirror the one
35
- * that is defined in the server common. We will be consolidating this mehod so that it will
36
- * be common to all sdks in the future.
37
- */
38
- /**
39
- * Options for the waitForInitialization method.
40
- */
41
- interface LDWaitForInitializationOptions {
42
- /**
43
- * The timeout duration in seconds to wait for initialization before resolving the promise.
44
- * If exceeded, the promise will resolve to a {@link LDWaitForInitializationTimeout} object.
45
- *
46
- * If no options are specified on the `waitForInitialization`, the default timeout of 5 seconds will be used.
47
- *
48
- * Using a high timeout, or no timeout, is not recommended because it could result in a long
49
- * delay when conditions prevent successful initialization.
50
- *
51
- * A value of 0 will cause the promise to resolve without waiting. In that scenario it would be
52
- * more effective to not call `waitForInitialization`.
53
- *
54
- * @default 5 seconds
55
- */
56
- timeout?: number;
57
- }
58
- /**
59
- * The waitForInitialization operation failed.
60
- */
61
- interface LDWaitForInitializationFailed {
62
- status: 'failed';
63
- error: Error;
64
- }
65
- /**
66
- * The waitForInitialization operation timed out.
67
- */
68
- interface LDWaitForInitializationTimeout {
69
- status: 'timeout';
70
- }
71
- /**
72
- * The waitForInitialization operation completed successfully.
73
- */
74
- interface LDWaitForInitializationComplete {
75
- status: 'complete';
76
- }
77
- /**
78
- * The result of the waitForInitialization operation.
79
- */
80
- type LDWaitForInitializationResult = LDWaitForInitializationFailed | LDWaitForInitializationTimeout | LDWaitForInitializationComplete;
81
32
  interface LDStartOptions extends LDWaitForInitializationOptions {
82
33
  /**
83
34
  * Optional bootstrap data to use for the identify operation. If {@link LDIdentifyOptions.bootstrap} is provided, it will be ignored.
package/dist/compat.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var yt=Object.defineProperty,Hi=Object.defineProperties,zi=Object.getOwnPropertyDescriptor,Bi=Object.getOwnPropertyDescriptors,Gi=Object.getOwnPropertyNames,mt=Object.getOwnPropertySymbols;var _t=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable;var Be=(i,t,e)=>t in i?yt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,p=(i,t)=>{for(var e in t||(t={}))_t.call(t,e)&&Be(i,e,t[e]);if(mt)for(var e of mt(t))Ge.call(t,e)&&Be(i,e,t[e]);return i},D=(i,t)=>Hi(i,Bi(t));var Jt=(i,t)=>{var e={};for(var n in i)_t.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&mt)for(var n of mt(i))t.indexOf(n)<0&&Ge.call(i,n)&&(e[n]=i[n]);return e};var Ki=(i,t)=>{for(var e in t)yt(i,e,{get:t[e],enumerable:!0})},Wi=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Gi(t))!_t.call(i,r)&&r!==e&&yt(i,r,{get:()=>t[r],enumerable:!(n=zi(t,r))||n.enumerable});return i};var _i=i=>Wi(yt({},"__esModule",{value:!0}),i);var $r={};Ki($r,{basicLogger:()=>Ar,initialize:()=>Nr});module.exports=_i($r);function Ji(i){return`/${i.replace(/~/g,"~0").replace(/\//g,"~1")}`}function Qe(i){return i.indexOf("~")?i.replace(/~1/g,"/").replace(/~0/g,"~"):i}function qi(i){return(i.startsWith("/")?i.substring(1):i).split("/").map(e=>Qe(e))}function Yi(i){return!i.startsWith("/")}function Zi(i){return!i.match(/\/\/|(^\/.*~[^0|^1])|~$/)}var O=class{constructor(t,e=!1){if(e){let n=t;this.v=[n],this.isValid=n!=="",this.redactionName=n.startsWith("/")?Ji(n):n}else{if(this.redactionName=t,t===""||t==="/"||!Zi(t)){this.isValid=!1,this.v=[];return}Yi(t)?this.v=[t]:t.indexOf("/",1)<0?this.v=[Qe(t.slice(1))]:this.v=qi(t),this.v[0]==="_meta"?this.isValid=!1:this.isValid=!0}}get(t){let{v:e,isValid:n}=this;if(!n)return;let r=t;for(let s=0;s<e.length;s+=1){let a=e[s];if(r!=null&&Object.prototype.hasOwnProperty.call(r,a)&&typeof r=="object"&&!Array.isArray(r))r=r[a];else return}return r}getComponent(t){return this.v[t]}get depth(){return this.v.length}get isKind(){return this.v.length===1&&this.v[0]==="kind"}compare(t){return this.depth===t.depth&&this.v.every((e,n)=>e===t.getComponent(n))}get components(){return[...this.v]}};O.InvalidReference=new O("");var Zt=class{is(t){if(Array.isArray(t))return!1;let n=typeof t;return n==="function"||n==="object"}getType(){return"factory method or object"}},A=class{constructor(t,e){this.It=t,this.typeOf=typeof e}is(t){return Array.isArray(t)?!1:typeof t===this.typeOf}getType(){return this.It}},Et=class{constructor(t,e){this.It=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.It}},W=class extends A{constructor(t){super(`number with minimum value of ${t}`,0),this.min=t}is(t){return typeof t===this.typeOf&&t>=this.min}},Dt=class extends A{constructor(t){super(`string matching ${t}`,""),this.expression=t}is(t){return typeof t=="string"&&!!t.match(this.expression)}},Xt=class{is(t){return typeof t=="function"}getType(){return"function"}},Qt=class{is(t){return typeof t=="boolean"||typeof t=="undefined"||t===null}getType(){return"boolean | undefined | null"}},Xi=/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d\d*)?(Z|[-+]\d\d(:\d\d)?)/,te=class{is(t){return typeof t=="number"||typeof t=="string"&&Xi.test(t)}getType(){return"date"}},ee=class extends Dt{constructor(){super(/^(\w|\.|-)+$/)}is(t){return super.is(t)&&t!=="kind"}},u=class{static createTypeArray(t,e){return new Et(t,e)}static numberWithMin(t){return new W(t)}static stringMatchingRegex(t){return new Dt(t)}};u.String=new A("string","");u.Number=new A("number",0);u.ObjectOrFactory=new Zt;u.Object=new A("object",{});u.StringArray=new Et("string[]","");u.Boolean=new A("boolean",!0);u.Function=new Xt;u.Date=new te;u.Kind=new ee;u.NullableBoolean=new Qt;function ti(i){return"kind"in i?u.String.is(i.kind)&&i.kind!=="multi":!1}function ei(i){return"kind"in i?u.String.is(i.kind)&&i.kind==="multi":!1}function ii(i){return!("kind"in i)||i.kind===null||i.kind===void 0}function bt(i,t=[]){if(i===null||typeof i!="object")return JSON.stringify(i);if(t.includes(i))throw new Error("Cycle detected");return Array.isArray(i)?`[${i.map(r=>bt(r,[...t,i])).map(r=>r===void 0?"null":r).join(",")}]`:`{${Object.keys(i).sort().map(n=>{let r=bt(i[n],[...t,i]);if(r!==void 0)return`${JSON.stringify(n)}:${r}`}).filter(n=>n!==void 0).join(",")}}`}var ie="user";function Ke(i){return i.includes("%")||i.includes(":")?i.replace(/%/g,"%25").replace(/:/g,"%3A"):i}function Qi(i){return i&&u.Object.is(i)}function We(i){return u.Kind.is(i)}function _e(i){return u.String.is(i)&&i!==""}function qt(i,t=!1){return i?i.map(e=>new O(e,t)):[]}function tn(i){return i!=null}function en(i){let t=D(p({},i.custom||[]),{kind:"user",key:String(i.key)});if(tn(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 S=class i{constructor(t,e,n){this.A=!1,this.lt=!1,this.fe=!1,this.V={},this.kind=e,this.valid=t,this.message=n}static S(t,e){return new i(!1,t,e)}static Qe(t,e){if(!(!e||!t.isValid))return t.depth===1&&t.getComponent(0)==="anonymous"?!!(e!=null&&e.anonymous):t.get(e)}pe(t){if(this.A)return this.V[t];if(this.kind===t)return this.E}static ti(t){let e=Object.keys(t).filter(c=>c!=="kind"),n=e.every(We);if(!e.length)return i.S("multi","A multi-kind context must contain at least one kind");if(!n)return i.S("multi","Context contains invalid kinds");let r={},s=!0,a=e.reduce((c,l)=>{var d;let h=t[l];return Qi(h)?(c[l]=h,r[l]=qt((d=h._meta)==null?void 0:d.privateAttributes)):s=!1,c},{});if(!s)return i.S("multi","Context contained contexts that were not objects");if(!Object.values(a).every(c=>_e(c.key)))return i.S("multi","Context contained invalid keys");if(e.length===1){let c=e[0],l=new i(!0,c);return l.E=D(p({},a[c]),{kind:c}),l.ht=r,l.lt=c==="user",l}let o=new i(!0,t.kind);return o.V=a,o.ht=r,o.A=!0,o}static ei(t){var c;let{key:e,kind:n}=t,r=We(n),s=_e(e);if(!r)return i.S(n!=null?n:"unknown","The kind was not valid for the context");if(!s)return i.S(n,"The key for the context was not valid");let a=qt((c=t._meta)==null?void 0:c.privateAttributes),o=new i(!0,n);return o.lt=n==="user",o.E=t,o.ht={[n]:a},o}static ii(t){if(!(t.key!==void 0&&t.key!==null))return i.S("user","The key for the context was not valid");let n=new i(!0,"user");return n.lt=!0,n.fe=!0,n.E=en(t),n.ht={user:qt(t.privateAttributeNames,!0)},n}static fromLDContext(t){return t?ti(t)?i.ei(t):ei(t)?i.ti(t):ii(t)?i.ii(t):i.S("unknown","Context was not of a valid kind"):i.S("unknown","No context specified. Returning default value")}static toLDContext(t){if(!t.valid)return;let e=t.getContexts();if(!t.A)return e[0][1];let n={kind:"multi"};return e.forEach(r=>{let s=r[0],a=r[1];n[s]=a}),n}valueForKind(t,e=ie){return t.isKind?this.kinds:i.Qe(t,this.pe(e))}key(t=ie){var e;return(e=this.pe(t))==null?void 0:e.key}get isMultiKind(){return this.A}get canonicalKey(){return this.lt?this.E.key:this.A?Object.keys(this.V).sort().map(t=>`${t}:${Ke(this.V[t].key)}`).join(":"):`${this.kind}:${Ke(this.E.key)}`}get kinds(){return this.A?Object.keys(this.V):[this.kind]}get kindsAndKeys(){return this.A?Object.entries(this.V).reduce((t,[e,n])=>(t[e]=n.key,t),{}):{[this.kind]:this.E.key}}privateAttributes(t){var e;return((e=this.ht)==null?void 0:e[t])||[]}getContexts(){return this.A?Object.entries(this.V):[[this.kind,this.E]]}get legacy(){return this.fe}canonicalUnfilteredJson(){if(this.valid){if(this.Pt)return this.Pt;try{this.Pt=bt(i.toLDContext(this))}catch(t){}return this.Pt}}};S.UserKind=ie;var nn=["key","kind","_meta","anonymous"].map(i=>new O(i,!0)),rn=["name","ip","firstName","lastName","email","avatar","country"];function sn(i,t){return i.depth===t.length&&t.every((e,n)=>e===i.getComponent(n))}function an(i,t){let e=[],n={},r=[];for(e.push(...Object.keys(i).map(s=>({key:s,ptr:[s],source:i,parent:n,visited:[i]})));e.length;){let s=e.pop(),a=t.find(o=>sn(o,s.ptr));if(a)r.push(a.redactionName);else{let o=s.source[s.key];o===null?s.parent[s.key]=o:Array.isArray(o)?s.parent[s.key]=[...o]:typeof o=="object"?s.visited.includes(o)||(s.parent[s.key]={},e.push(...Object.keys(o).map(c=>({key:c,ptr:[...s.ptr,c],source:o,parent:s.parent[s.key],visited:[...s.visited,o]})))):s.parent[s.key]=o}}return{cloned:n,excluded:r.sort()}}var ne=class{constructor(t,e){this.ni=t,this.ri=e}filter(t,e=!1){let n=t.getContexts();if(n.length===1)return this.ge(t,n[0][1],n[0][0],e);let r={kind:"multi"};return n.forEach(([s,a])=>{r[s]=this.ge(t,a,s,e)}),r}si(t,e,n,r){return(r?Object.keys(e).map(s=>new O(s,!0)):[...this.ri,...t.privateAttributes(n)]).filter(s=>!nn.some(a=>a.compare(s)))}ge(t,e,n,r){let s=this.ni||r&&e.anonymous===!0,{cloned:a,excluded:o}=an(e,this.si(t,e,n,s));return t.legacy&&rn.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}},Je=30*1e3,on=.5,kt=class{constructor(t,e,n=Math.random){this.ai=e,this.oi=n,this.Tt=0,this.me=Math.max(1,t),this.ci=Math.ceil(Math.log2(Je/this.me))}N(){let t=Math.min(this.Tt,this.ci),e=this.me*2**t;return Math.min(e,Je)}li(t){return t-Math.trunc(this.oi()*on*t)}success(t=Date.now()){this.Ot=t}fail(t=Date.now()){this.Ot!==void 0&&t-this.Ot>this.ai&&(this.Tt=0),this.Ot=void 0;let e=this.li(this.N());return this.Tt+=1,e}};var qe;(function(i){i[i.Valid=0]="Valid",i[i.Initializing=1]="Initializing",i[i.Interrupted=2]="Interrupted",i[i.Closed=3]="Closed"})(qe||(qe={}));var M=class extends Error{constructor(t,e,n,r=!0){super(e),this.kind=t,this.status=n,this.name="LaunchDarklyPollingError",this.recoverable=r}},j=class extends Error{constructor(t,e,n,r=!0){super(e),this.kind=t,this.code=n,this.name="LaunchDarklyStreamingError",this.recoverable=r}};var Mr=120*1e3,Rr=300*1e3;var w;(function(i){i.Unknown="UNKNOWN",i.NetworkError="NETWORK_ERROR",i.ErrorResponse="ERROR_RESPONSE",i.InvalidData="INVALID_DATA"})(w||(w={}));var H;(function(i){i[i.Disabled=0]="Disabled",i[i.Enabled=1]="Enabled"})(H||(H={}));var z;(function(i){i[i.AnalyticsEvents=0]="AnalyticsEvents",i[i.DiagnosticEvent=1]="DiagnosticEvent"})(z||(z={}));var F;(function(i){i[i.Succeeded=0]="Succeeded",i[i.Failed=1]="Failed",i[i.FailedAndMustShutDown=2]="FailedAndMustShutDown"})(F||(F={}));function V(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 cn(i){return typeof i=="symbol"?"NaN":typeof i=="bigint"?`${i}n`:String(Number(i))}function ln(i){return typeof i=="symbol"?"NaN":typeof i=="bigint"?`${i}n`:String(parseInt(i,10))}function hn(i){return typeof i=="symbol"?"NaN":String(parseFloat(i))}var vt={s:i=>V(i),d:i=>cn(i),i:i=>ln(i),f:i=>hn(i),j:i=>V(i),o:i=>V(i),O:i=>V(i),c:()=>""};function re(...i){var e;let t=i.shift();if(u.String.is(t)){let n="",r=0;for(;r<t.length;){let s=t.charAt(r);if(s==="%"){if(r+1<t.length){let o=t.charAt(r+1);if(o in vt&&i.length){let c=i.shift();n+=(e=vt[o])==null?void 0:e.call(vt,c)}else o==="%"?n+="%":n+=`%${o}`;r+=2}}else n+=s,r+=1}return i.length&&(n.length&&(n+=" "),n+=i.map(V).join(" ")),n}return i.map(V).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 un=["debug","info","warn","error","none"],R=class i{static get(){return new i({})}constructor(t){var e,n,r;if(this.yi=(n=v[(e=t.level)!=null?e:"info"])!=null?n:v.info,this.vi=(r=t.name)!=null?r:"LaunchDarkly",this.De=t.formatter,typeof t.destination=="object")this.be={[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:s}=t;this.be={[v.debug]:s,[v.info]:s,[v.warn]:s,[v.error]:s}}}wi(...t){var e;try{return this.De?(e=this.De)==null?void 0:e.call(this,...t):re(...t)}catch(n){return re(...t)}}Ei(t,e){try{t(e)}catch(n){console.error(e)}}C(t,e){var n;if(t>=this.yi){let r=`${un[t]}: [${this.vi}]`;try{let s=(n=this.be)==null?void 0:n[t];s?this.Ei(s,`${r} ${this.wi(...e)}`):console.error(...e)}catch(s){console.error(...e)}}}error(...t){this.C(v.error,t)}warn(...t){this.C(v.warn,t)}info(...t){this.C(v.info,t)}debug(...t){this.C(v.debug,t)}},dn={error:u.Function,warn:u.Function,info:u.Function,debug:u.Function},_=class{constructor(t,e){Object.entries(dn).forEach(([n,r])=>{if(!r.is(t[n]))throw new Error(`Provided logger instance must support logger.${n}(...) method`)}),this.t=t,this.Di=e}C(t,e){try{this.t[t](...e)}catch(n){this.Di[t](...e)}}error(...t){this.C("error",t)}warn(...t){this.C("warn",t)}info(...t){this.C("info",t)}debug(...t){this.C("debug",t)}},ge=i=>{let t=new R({level:"info",destination:console.error,formatter:re});return i?new _(i,t):t},b=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`}},fn=/^(\w|\.|-)+$/,pn=u.stringMatchingRegex(fn),gn={is:(i,t)=>pn.is(i)?i.length>64?{valid:!1,message:b.tagValueTooLong(t)}:{valid:!0}:{valid:!1,message:b.invalidTagValue(t)}},xt=class{constructor(t){let e={},n=t==null?void 0:t.application,r=t==null?void 0:t.logger;n&&Object.entries(n).forEach(([a,o])=>{if(o!=null){let{valid:c,message:l}=gn.is(o,`application.${a}`);c?a==="versionName"?e["application-version-name"]=[o]:e[`application-${a}`]=[o]:r==null||r.warn(l)}});let s=Object.keys(e);s.length&&(this.value=s.sort().flatMap(a=>e[a].sort().map(o=>`${a}/${o}`)).join(" "))}},Lt=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 Yt(i){return i.replace(/\/+$/,"")}function me(i){return i.replace(/^\/+/,"").replace(/\?$/,"")}var U=class i{constructor(t,e,n=i.DEFAULT_EVENTS,r="/bulk",s="/diagnostic",a=!0,o){this.streaming=Yt(t),this.polling=Yt(e),this.events=Yt(n),this.analyticsEventPath=r,this.diagnosticEventPath=s,this.includeAuthorizationHeader=a,this.payloadFilterKey=o}};U.DEFAULT_EVENTS="https://events.launchdarkly.com";function ye(i,t=[]){if(t.length===0)return i;let e=t.map(({key:n,value:r})=>`${n}=${r}`);return`${i}?${e.join("&")}`}function ni(i,t,e){let n=me(t),r=[...e];return i.payloadFilterKey&&r.push({key:"filter",value:i.payloadFilterKey}),ye(`${i.streaming}/${n}`,r)}function ri(i,t,e=[]){let n=me(t),r=[...e];return i.payloadFilterKey&&r.push({key:"filter",value:i.payloadFilterKey}),ye(`${i.polling}/${n}`,r)}function Ye(i,t,e=[]){let n=me(t);return ye(`${i.events}/${n}`,e)}var J=class extends Error{constructor(t){super(t),this.name="LaunchDarklyUnexpectedResponseError"}},q=class extends Error{constructor(t){super(t),this.name="LaunchDarklyClientError"}},P=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 mn(i){return i===413?!0:Z(i)}function Nt(i,t){let e,n;return{promise:new Promise((s,a)=>{n=s,e=setTimeout(()=>{let o=`${t} timed out after ${i} seconds.`;a(new P(o))},i*1e3)}),cancel:()=>{n(),clearTimeout(e)}}}function ve(i){return i==null?i:JSON.parse(JSON.stringify(i))}function $t(i){return Math.trunc(i*1e3)}var yn=i=>JSON.stringify(i)==="{}",Ft=(i,t)=>i&&Object.entries(i).reduce((e,[n,r])=>(r&&!yn(r)&&!(t!=null&&t.includes(n))&&(e[n]=typeof r=="object"?Ft(r,t):r),e),{});function K(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,r;if(Array.isArray(i)){if(e=i.length,e!=t.length)return!1;for(n=e;n--!==0;)if(!K(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(!K(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(r=Object.keys(i),e=r.length,e!==Object.keys(t).length)return!1;for(n=e;n--!==0;)if(!Object.prototype.hasOwnProperty.call(t,r[n]))return!1;for(n=e;n--!==0;){var s=r[n];if(!K(i[s],t[s]))return!1}return!0}return i!==i&&t!==t}function si(i,t,e,n=!0,r="user-agent"){let{userAgentBase:s,version:a,wrapperName:o,wrapperVersion:c}=t.sdkData(),l={[r]:`${s!=null?s:"NodeJSClient"}/${a}`};return n&&(l.authorization=i),o&&(l["x-launchdarkly-wrapper"]=c?`${o}/${c}`:o),e!=null&&e.value&&(l["x-launchdarkly-tags"]=e.value),l}function N(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 r=e!=null?e:"giving up permanently";return`Received ${n} for ${t} - ${r}`}function Mt({status:i}){return i?Z(i):!0}var we=(i,t)=>t.btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");var Ee=async(i=1e3)=>new Promise(t=>{setTimeout(t,i)});var se=class{constructor(t,e,n){this.m=e,this.bi=n,this.$t=[],this.ke=Date.now(),this.xe=this.ke,this.Le={diagnosticId:e.crypto.randomUUID(),sdkKeySuffix:t.length>6?t.substring(t.length-6):t}}createInitEvent(){var n,r,s;let t=this.m.info.sdkData(),e=this.m.info.platformData();return{kind:"diagnostic-init",id:this.Le,creationDate:this.ke,sdk:t,configuration:this.bi,platform:p({name:e.name,osArch:(n=e.os)==null?void 0:n.arch,osName:(r=e.os)==null?void 0:r.name,osVersion:(s=e.os)==null?void 0:s.version},e.additional||{})}}recordStreamInit(t,e,n){let r={timestamp:t,failed:e,durationMillis:n};this.$t.push(r)}createStatsEventAndReset(t,e,n){let r=Date.now(),s={kind:"diagnostic",id:this.Le,creationDate:r,dataSinceDate:this.xe,droppedEvents:t,deduplicatedUsers:e,eventsInLastBatch:n,streamInits:this.$t};return this.$t=[],this.xe=r,s}},ae;(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"})(ae||(ae={}));var vn=ae,St=class{static invalidMetricValue(t){return`The track function was called with a non-numeric "metricValue" (${t}), only numeric metric values are supported.`}};St.MissingContextKeyNoEvent="Context was unspecified or had no key; event will not be sent";var oe=class{constructor(t,e){let{basicConfiguration:n,platform:r}=t,{serviceEndpoints:{analyticsEventPath:s,diagnosticEventPath:a}}=n,{crypto:o,requests:c}=r;this.ki=p({},e),this.Se=Ye(n.serviceEndpoints,s,[]),this.xi=Ye(n.serviceEndpoints,a,[]),this.F=c,this.Li=o}async ut(t,e,n,r){let s={status:F.Succeeded},a=D(p({},this.ki),{"content-type":"application/json"});n&&(a["x-launchdarkly-payload-id"]=n,a["x-launchDarkly-event-schema"]="4");let o;try{let{status:c,headers:l}=await this.F.fetch(e,{headers:a,body:JSON.stringify(t),compressBodyIfPossible:!0,method:"POST",keepalive:!0}),h=Date.parse(l.get("date")||"");if(h&&(s.serverTime=h),c<=204)return s;if(o=new J(N({status:c,message:"some events were dropped"},"event posting")),!Z(c))return mn(c)?s.status=F.Failed:s.status=F.FailedAndMustShutDown,s.error=o,s}catch(c){o=c}return o&&!r?(s.status=F.Failed,s.error=o,s):(await Ee(),this.ut(t,this.Se,n,!1))}async sendEventData(t,e){let n=t===z.AnalyticsEvents?this.Li.randomUUID():void 0,r=t===z.AnalyticsEvents?this.Se:this.xi;return this.ut(e,r,n,!0)}};function Ct(i){return i.kind==="feature"}function wn(i){return i.kind==="identify"}function En(i){return i.kind==="migration_op"}var ce=class{constructor(t,e,n,r,s,a){this.count=t,this.key=e,this.value=n,this.version=s,this.variation=a,this.default=r}increment(){this.count+=1}};function Dn(i){return`${i.key}:${i.variation!==null&&i.variation!==void 0?i.variation:""}:${i.version!==null&&i.version!==void 0?i.version:""}`}var It=class{constructor(t=!1,e){this.Si=t,this.I=e,this.it=0,this.dt=0,this.ft={},this.pt={}}summarizeEvent(t){if(Ct(t)&&!t.excludeFromSummaries){this.E||(this.E=t.context);let e=Dn(t),n=this.ft[e],r=this.pt[t.key];r||(r=new Set,this.pt[t.key]=r),t.context.kinds.forEach(s=>r.add(s)),n?n.increment():this.ft[e]=new ce(1,t.key,t.value,t.default,t.version,t.variation),(this.it===0||t.creationDate<this.it)&&(this.it=t.creationDate),t.creationDate>this.dt&&(this.dt=t.creationDate)}}getSummary(){var n;let t=Object.values(this.ft).reduce((r,s)=>{let a=r[s.key];a||(a={default:s.default,counters:[],contextKinds:[...this.pt[s.key]]},r[s.key]=a);let o={value:s.value,count:s.count};return s.variation!==void 0&&s.variation!==null&&(o.variation=s.variation),s.version!==void 0&&s.version!==null?o.version=s.version:o.unknown=!0,a.counters.push(o),r},{}),e={startDate:this.it,endDate:this.dt,features:t,kind:"summary",context:this.E!==void 0&&this.Si?(n=this.I)==null?void 0:n.filter(this.E):void 0};return this.Ci(),e}Ci(){this.it=0,this.dt=0,this.ft={},this.pt={}}},le=class extends Error{constructor(t){super(t),this.name="LaunchDarklyInvalidSDKKeyError"}},he=class{constructor(t,e){this.I=t,this.t=e,this.nt={}}summarizeEvent(t){var e;if(Ct(t)){let n=t.context.canonicalUnfilteredJson();if(!n){t.context.valid&&((e=this.t)==null||e.error("Unable to serialize context, likely the context contains a cycle."));return}let r=this.nt[n];r||(this.nt[n]=new It(!0,this.I),r=this.nt[n]),r.summarizeEvent(t)}}getSummaries(){let t=this.nt;return this.nt={},Object.values(t).map(e=>e.getSummary())}};function wt(i){let t=Math.trunc(i);return t===1?!0:t===0?!1:Math.floor(Math.random()*t)===0}function bn(i){return i.getSummaries!==void 0}var ue=class{constructor(t,e,n,r,s,a=!0,o=!1){this.r=t,this.gt=r,this.P=s,this.mt=[],this.Ce=0,this.Ft=0,this.Mt=0,this.Rt=!1,this.Ie=0,this.Ut=!1,this.Vt=null,this.Ii=t.eventsCapacity,this.t=e.basicConfiguration.logger,this.Pe=new oe(e,n),this.I=new ne(t.allAttributesPrivate,t.privateAttributes.map(c=>new O(c))),o?this.rt=new he(this.I,this.t):this.rt=new It,a&&this.start()}start(){var t,e;if(((t=this.gt)==null?void 0:t.flushInterval)!==void 0&&(this.Vt=setInterval(()=>{var n;(n=this.gt)==null||n.flush()},this.gt.flushInterval*1e3)),this.Pi=setInterval(async()=>{var n;try{await this.flush()}catch(r){(n=this.t)==null||n.debug(`Flush failed: ${r}`)}},this.r.flushInterval*1e3),this.P){let n=this.P.createInitEvent();this.Te(n),this.Oe=setInterval(()=>{let r=this.P.createStatsEventAndReset(this.Ft,this.Mt,this.Ie);this.Ft=0,this.Mt=0,this.Te(r)},this.r.diagnosticRecordingInterval*1e3)}(e=this.t)==null||e.debug("Started EventProcessor.")}Te(t){this.Pe.sendEventData(z.DiagnosticEvent,t)}close(){clearInterval(this.Pi),this.Vt&&clearInterval(this.Vt),this.Oe&&clearInterval(this.Oe)}async flush(){var e;if(this.Ut)throw new le("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.mt;if(this.mt=[],bn(this.rt))this.rt.getSummaries().forEach(r=>{Object.keys(r.features).length&&t.push(r)});else{let n=this.rt.getSummary();Object.keys(n.features).length&&t.push(n)}t.length&&(this.Ie=t.length,(e=this.t)==null||e.debug("Flushing %d events",t.length),await this.ut(t))}sendEvent(t){var c;if(this.Ut)return;if(En(t)){if(wt(t.samplingRatio)){let l=D(p({},t),{context:t.context?this.I.filter(t.context):void 0});l.samplingRatio===1&&delete l.samplingRatio,this.yt(l)}return}this.rt.summarizeEvent(t);let e=Ct(t),n=e&&t.trackEvents||!e,r=this.Ti(t),s=wn(t),a=(c=this.gt)==null?void 0:c.processContext(t.context);a||s||(this.Mt+=1),a&&!s&&this.yt(this.jt({kind:"index",creationDate:t.creationDate,context:t.context,samplingRatio:1},!1)),n&&wt(t.samplingRatio)&&this.yt(this.jt(t,!1)),r&&wt(t.samplingRatio)&&this.yt(this.jt(t,!0))}jt(t,e){switch(t.kind){case"feature":{let n={kind:e?"debug":"feature",creationDate:t.creationDate,context:this.I.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.I.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.I.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}}yt(t){var e;this.mt.length<this.Ii?(this.mt.push(t),this.Rt=!1):(this.Rt||(this.Rt=!0,(e=this.t)==null||e.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),this.Ft+=1)}Ti(t){return Ct(t)&&t.debugEventsUntilDate&&t.debugEventsUntilDate>this.Ce&&t.debugEventsUntilDate>Date.now()}async ut(t){let e=await this.Pe.sendEventData(z.AnalyticsEvents,t);if(e.status===F.FailedAndMustShutDown&&(this.Ut=!0),e.serverTime&&(this.Ce=e.serverTime),e.error)throw e.error}},Pt=class{constructor(t,e,n,r,s=1,a){this.context=t,this.key=e,this.data=n,this.metricValue=r,this.samplingRatio=s,this.url=a,this.kind="custom",this.creationDate=Date.now(),this.context=t}},Y=class{constructor(t,e,n,r,s,a,o,c,l,h,d,f,m=1){this.withReasons=t,this.context=e,this.key=n,this.samplingRatio=m,this.kind="feature",this.creationDate=Date.now(),this.value=r,this.default=s,a!==void 0&&(this.version=a),o!==void 0&&(this.variation=o),c!==void 0&&(this.trackEvents=c),l!==void 0&&(this.prereqOf=l),h!==void 0&&(this.reason=h),d!==void 0&&(this.debugEventsUntilDate=d),f!==void 0&&(this.excludeFromSummaries=f)}},Tt=class{constructor(t,e=1){this.context=t,this.samplingRatio=e,this.kind="identify",this.creationDate=Date.now()}},de=class{close(){}async flush(){}sendEvent(){}},fe=class{constructor(t){this.Ht=t}evalEvent(t){var e;return new Y(this.Ht,t.context,t.flagKey,t.value,t.defaultVal,t.version,(e=t.variation)!=null?e:void 0,t.trackEvents||t.addExperimentData,t.prereqOfFlagKey,this.Ht||t.addExperimentData?t.reason:void 0,t.debugEventsUntilDate,t.excludeFromSummaries,t.samplingRatio)}unknownFlagEvent(t,e,n){return new Y(this.Ht,n,t,e,e,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0)}identifyEvent(t){return new Tt(t,1)}customEvent(t,e,n,r,s=1){return new Pt(e,t,n!=null?n:void 0,r!=null?r:void 0,s)}},Ze="FDv1Fallback";function kn(i){return{Oi:i,Ae:"",useSelector(t){return this.Ae=t,this},processFullTransfer(t){let e=[{event:"server-intent",data:{payloads:[{id:Ze,target:1,intentCode:"xfer-full",reason:"payload-missing"}]}}];Object.entries((t==null?void 0:t.flags)||[]).forEach(([n,r])=>{e.push({event:"put-object",data:{kind:"flag",key:n,version:r.version||1,object:r}})}),Object.entries((t==null?void 0:t.segments)||[]).forEach(([n,r])=>{e.push({event:"put-object",data:{kind:"segment",key:n,version:r.version||1,object:r}})}),e.push({event:"payload-transferred",data:{state:this.Ae,version:1,id:Ze}}),this.Oi.processEvents(e)}}}var Ot=class{constructor(t,e,n){this.Ai=t,this.w=e,this.t=n,this.e=[],this.H=void 0,this._=!1,this.J=[],this.Ni=r=>{var a;if(this.zt(),!r.payloads.length)return;let s=r.payloads[0];switch(s==null?void 0:s.intentCode){case"xfer-full":this._=!0;break;case"xfer-changes":this._=!1;break;case"none":this._=!1,this.$i(s);break;default:(a=this.t)==null||a.warn(`Unable to process intent code '${s==null?void 0:s.intentCode}'.`);return}this.H=s==null?void 0:s.id},this.Fi=r=>{var a;if(!this.H||!r.kind||!r.key||!r.version||!r.object)return;let s=this.Mi(r.kind,r.object);if(!s){(a=this.t)==null||a.warn(`Unable to process object for kind: '${r.kind}'`);return}this.J.push({kind:r.kind,key:r.key,version:r.version,object:s})},this.Ri=r=>{!this.H||!r.kind||!r.key||!r.version||this.J.push({kind:r.kind,key:r.key,version:r.version,deleted:!0})},this.$i=r=>{if(!r.id||!r.target)return;let s={id:r.id,version:r.target,basis:!1,updates:[]};this.e.forEach(a=>a(s)),this.Ne()},this.Ui=r=>{if(!this.H||r.state===null||r.state===void 0||!r.version){this.zt();return}let s={id:this.H,version:r.version,state:r.state,basis:this._,updates:this.J};this.e.forEach(a=>a(s)),this.Ne()},this.Vi=r=>{var s;(s=this.t)==null||s.info(`Goodbye was received from the LaunchDarkly connection with reason: ${r.reason}.`),this.zt()},this.ji=r=>{var s;(s=this.t)==null||s.info(`An issue was encountered receiving updates for payload ${this.H} with reason: ${r.reason}.`),this.Hi()}}addPayloadListener(t){this.e.push(t)}removePayloadListener(t){let e=this.e.indexOf(t,0);e>-1&&this.e.splice(e,1)}processEvents(t){t.forEach(e=>{switch(e.event){case"server-intent":{this.Ni(e.data);break}case"put-object":{this.Fi(e.data);break}case"delete-object":{this.Ri(e.data);break}case"payload-transferred":{this.Ui(e.data);break}case"goodbye":{this.Vi(e.data);break}case"error":{this.ji(e.data);break}}})}Mi(t,e){var n,r;return(r=(n=this.Ai)[t])==null?void 0:r.call(n,e)}Ne(){this._=!1,this.J=[]}Hi(){this.J=[]}zt(){this.H=void 0,this._=!1,this.J=[]}},pe=class{constructor(t,e,n,r){this.w=n,this.t=r,this.q(t,"server-intent"),this.q(t,"put-object"),this.q(t,"delete-object"),this.q(t,"payload-transferred"),this.q(t,"goodbye"),this.q(t,"error"),this.Bt=new Ot(e,n,r)}addPayloadListener(t){this.Bt.addPayloadListener(t)}removePayloadListener(t){this.Bt.removePayloadListener(t)}q(t,e){t.addEventListener(e,async n=>{var r,s,a,o,c;if(n!=null&&n.data){(r=this.t)==null||r.debug(`Received ${e} event. Data is ${n.data}`);try{this.Bt.processEvents([{event:e,data:JSON.parse(n.data)}])}catch(l){(s=this.t)==null||s.error(`Stream received data that was unable to be processed in "${e}" message`),(a=this.t)==null||a.debug(`Data follows: ${n.data}`),(o=this.w)==null||o.call(this,w.InvalidData,"Malformed data in EventStream.")}}else(c=this.w)==null||c.call(this,w.Unknown,"Event from EventStream missing data.")})}};function xn(i){if(i){let t=Object.keys(i).find(e=>e.toLowerCase()==="x-ld-envid");if(t)return{environmentId:i[t]}}}var Xe="unknown plugin";function At(i,t){try{return t.getMetadata().name||Xe}catch(e){return i.error("Exception thrown getting metadata for plugin. Unable to get plugin name."),Xe}}function Ln(i,t,e){let n=[];return e.forEach(r=>{var s;try{let a=(s=r.getHooks)==null?void 0:s.call(r,t);a===void 0?i.error(`Plugin ${At(i,r)} returned undefined from getHooks.`):a&&a.length>0&&n.push(...a)}catch(a){i.error(`Exception thrown getting hooks for plugin ${At(i,r)}. Unable to get hooks.`)}}),n}function Sn(i,t,e,n){n.forEach(r=>{try{r.register(e,t)}catch(s){i.error(`Exception thrown registering plugin ${At(i,r)}.`)}})}var k=Object.freeze({__proto__:null,ClientMessages:St,DiagnosticsManager:se,ErrorKinds:vn,EventFactoryBase:fe,EventProcessor:ue,FDv1PayloadAdaptor:kn,InputCustomEvent:Pt,InputEvalEvent:Y,InputIdentifyEvent:Tt,NullEventProcessor:de,PayloadProcessor:Ot,PayloadStreamReader:pe,canonicalize:bt,initMetadataFromHeaders:xn,isLegacyUser:ii,isMultiKind:ei,isSingleKind:ti,safeGetHooks:Ln,safeGetName:At,safeRegisterPlugins:Sn,shouldSample:wt});var E;(function(i){i.Initializing="INITIALIZING",i.Valid="VALID",i.Interrupted="INTERRUPTED",i.SetOffline="SET_OFFLINE",i.Closed="CLOSED"})(E||(E={}));function In(i){return i>=200&&i<=299}var Rt=class extends Error{constructor(t,e){super(t),this.status=e,this.name="LaunchDarklyRequestError"}},be=class{constructor(t,e,n,r,s){this.F=t,this.zi=e,this.vt=n,this.Bi=r,this.Gi=s}async requestPayload(){let t;try{let e=await this.F.fetch(this.zi,{method:this.Bi,headers:this.vt,body:this.Gi});if(In(e.status))return await e.text();t=e.status}catch(e){throw new Rt(e==null?void 0:e.message)}throw new Rt(`Unexpected status code: ${t}`,t)}};function Fe(i,t,e,n,r,s,a,o,c,l){let h,d="GET",f=p({},s);c&&(d="REPORT",f["content-type"]="application/json",h=i);let m=c?e.pathReport(r,i):e.pathGet(r,i),g=[...a!=null?a:[]];o&&g.push({key:"withReasons",value:"true"}),l&&g.push({key:"h",value:l});let y=ri(t,m,g);return new be(n,y,f,d,h)}var ai=new Error("Task has already been executed or shed. This is likely an implementation error. The task will not be executed again.");function Pn(i,t,e=!1){let n,r=new Promise(o=>{n=(c,l)=>{var h;try{(h=i.after)==null||h.call(i,c,l)}catch(d){t==null||t.error(`Error in after callback: ${d}`)}o(c)}}),s=i.before?i.before():Promise.resolve(void 0),a=!1;return{execute:()=>{a&&(t==null||t.error(ai)),a=!0,s.then(o=>{i.execute(o).then(c=>n({status:"complete",result:c},o)).catch(c=>n({status:"error",error:c},o))}).catch(o=>{t==null||t.error(o),n({status:"error",error:o},void 0)})},shed:()=>{a&&(t==null||t.error(ai)),a=!0,s.then(o=>{n({status:"shed"},o)})},promise:r,sheddable:e}}function Tn(i){let t,e=[];function n(){if(!t&&e.length>0){let r=e.shift();t=r.promise.finally(()=>{t=void 0,n()}),r.execute()}}return{execute(r,s=!1){var o,c;let a=Pn(r,i,s);return t?((o=e[e.length-1])!=null&&o.sheddable&&((c=e.pop())==null||c.shed()),e.push(a)):(t=a.promise.finally(()=>{t=void 0,n()}),a.execute()),a.promise},pendingCount(){return e.length}}}var On={logger:u.Object,maxCachedContexts:u.numberWithMin(0),baseUri:u.String,streamUri:u.String,eventsUri:u.String,capacity:u.numberWithMin(1),diagnosticRecordingInterval:u.numberWithMin(2),flushInterval:u.numberWithMin(2),streamInitialReconnectDelay:u.numberWithMin(0),allAttributesPrivate:u.Boolean,debug:u.Boolean,diagnosticOptOut:u.Boolean,withReasons:u.Boolean,sendEvents:u.Boolean,pollInterval:u.numberWithMin(30),useReport:u.Boolean,privateAttributes:u.StringArray,applicationInfo:u.Object,wrapperName:u.String,wrapperVersion:u.String,payloadFilterKey:u.stringMatchingRegex(/^[a-zA-Z0-9](\w|\.|-)*$/),hooks:u.createTypeArray("Hook[]",{}),inspectors:u.createTypeArray("LDInspection",{})},An=300,mi="https://clientsdk.launchdarkly.com",yi="https://clientstream.launchdarkly.com";function Nn(i){return i instanceof _?i:ge(i)}var ke=class{constructor(t={},e={getImplementationHooks:()=>[],credentialType:"mobileKey"}){var r,s,a;this.logger=ge(),this.baseUri=mi,this.eventsUri=U.DEFAULT_EVENTS,this.streamUri=yi,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=An,this.hooks=[],this.inspectors=[],this.logger=Nn(t.logger),this.Ki(t).forEach(o=>this.logger.warn(o)),this.serviceEndpoints=new U(this.streamUri,this.baseUri,this.eventsUri,e.analyticsEventPath,e.diagnosticEventPath,e.includeAuthorizationHeader,t.payloadFilterKey),this.useReport=(r=t.useReport)!=null?r:!1,this.tags=new xt({application:this.applicationInfo,logger:this.logger}),this.userAgentHeaderName=(s=e.userAgentHeaderName)!=null?s:"user-agent",this.trackEventModifier=(a=e.trackEventModifier)!=null?a:(o=>o),this.credentialType=e.credentialType,this.getImplementationHooks=e.getImplementationHooks}Ki(t){let e=[];return Object.entries(t).forEach(([n,r])=>{let s=On[n];if(s)if(s.is(r))n==="logger"||(this[n]=r!=null?r:void 0);else{let a=s.getType();if(a==="boolean")e.push(b.wrongOptionTypeBoolean(n,typeof r)),this[n]=!!r;else if(a==="boolean | undefined | null")e.push(b.wrongOptionTypeBoolean(n,typeof r)),typeof r!="boolean"&&typeof r!="undefined"&&r!==null&&(this[n]=!!r);else if(s instanceof W&&u.Number.is(r)){let{min:o}=s;e.push(b.optionBelowMinimum(n,r,o)),this[n]=o}else e.push(b.wrongOptionType(n,s.getType(),typeof r))}else e.push(b.unknownOption(n))}),e}};async function vi(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 wi=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 Ei(i){return async t=>vi(i.createHash("sha256").update(t),"base64")}var C=async i=>i;async function Q(i){return(await Promise.all(i.map(e=>e.transform(e.value)))).join("_")}async function $n(i,t){return Q([{value:"LaunchDarkly",transform:C},{value:t,transform:Ei(i)}])}async function Fn(i){return Q([{value:"LaunchDarkly",transform:C},{value:"AnonymousKeys",transform:C},{value:i,transform:C}])}async function Mn(i){return Q([{value:"LaunchDarkly",transform:C},{value:"ContextKeys",transform:C},{value:i,transform:C}])}async function Rn(i){return Q([{value:i,transform:C},{value:"ContextIndex",transform:C}])}async function oi(i,t,e){return Q([{value:t,transform:C},{value:e.canonicalKey,transform:Ei(i)}])}var{isLegacyUser:Un,isSingleKind:De,isMultiKind:ci}=k,Di="1.0",Vn=i=>{let n=i,{kind:t}=n,e=Jt(n,["kind"]);return{kind:"multi",[t]:e}},jn=async({crypto:i,info:t},{applicationInfo:e})=>{var a;let{ld_application:n}=t.platformData(),r=(a=Ft(n))!=null?a:{},s=(e==null?void 0:e.id)||(r==null?void 0:r.id);if(s){let o=(e==null?void 0:e.version)||(r==null?void 0:r.version),c=(e==null?void 0:e.name)||(r==null?void 0:r.name),l=(e==null?void 0:e.versionName)||(r==null?void 0:r.versionName);return r=p(p(p(D(p({},r),{id:s}),o?{version:o}:{}),c?{name:c}:{}),l?{versionName:l}:{}),r.key=await vi(i.createHash("sha256").update(s),"base64"),r.envAttributesVersion=r.envAttributesVersion||Di,r}},Hn=async i=>{var o,c,l,h;let{ld_device:t,os:e}=i.info.platformData(),n=(o=Ft(t))!=null?o:{},r=(e==null?void 0:e.name)||((c=n.os)==null?void 0:c.name),s=(e==null?void 0:e.version)||((l=n.os)==null?void 0:l.version),a=(h=n.os)==null?void 0:h.family;if((r||s||a)&&(n.os=p(p(p({},r?{name:r}:{}),s?{version:s}:{}),a?{family:a}:{})),Object.keys(n).filter(d=>d!=="key"&&d!=="envAttributesVersion").length){let d=await Mn("ld_device");return n.key=await wi(d,i),n.envAttributesVersion=n.envAttributesVersion||Di,n}},zn=async(i,t,e)=>{if(Un(i))return i;let n,r;if(De(i)&&i.kind!=="ld_application"||ci(i)&&!i.ld_application?n=await jn(t,e):e.logger.warn("Not adding ld_application environment attributes because it already exists."),De(i)&&i.kind!=="ld_device"||ci(i)&&!i.ld_device?r=await Hn(t):e.logger.warn("Not adding ld_device environment attributes because it already exists."),n||r){let s=De(i)?Vn(i):i;return p(p(p({},s),n?{ld_application:n}:{}),r?{ld_device:r}:{})}return i};function Bn(){let i,t;return{set(e,n){i=e,t=n},getContext(){return t},getUnwrappedContext(){return i},newIdentificationPromise(){let e,n;return{identifyPromise:new Promise((s,a)=>{e=s,n=a}),identifyResolve:e,identifyReject:n}},hasContext(){return t!==void 0},hasValidContext(){return this.hasContext()&&t.valid}}}var{isLegacyUser:Gn,isMultiKind:Kn,isSingleKind:Wn}=k,Me=async(i,t,e)=>{let{anonymous:n,key:r}=t;if(n&&!r){let s=await Fn(i);t.key=await wi(s,e)}},_n=async(i,t)=>{await Me(i.kind,i,t)},Jn=async(i,t)=>{let r=i,{kind:e}=r,n=Jt(r,["kind"]);return Promise.all(Object.entries(n).map(([s,a])=>Me(s,a,t)))},qn=async(i,t)=>{await Me("user",i,t)},Yn=async(i,t)=>{let e=ve(i);return Wn(e)&&await _n(e,t),Kn(e)&&await Jn(e,t),Gn(e)&&await qn(e,t),e},Zn=i=>({customBaseURI:i.serviceEndpoints.polling!==mi,customStreamURI:i.serviceEndpoints.streaming!==yi,customEventsURI:i.serviceEndpoints.events!==U.DEFAULT_EVENTS,eventsCapacity:i.capacity,eventsFlushIntervalMillis:$t(i.flushInterval),reconnectTimeMillis:$t(i.streamInitialReconnectDelay),diagnosticRecordingIntervalMillis:$t(i.diagnosticRecordingInterval),allAttributesPrivate:i.allAttributesPrivate,usingSecureMode:!1,bootstrapMode:!1}),Xn=(i,t,e)=>{if(t.sendEvents&&!t.diagnosticOptOut)return new k.DiagnosticsManager(i,e,Zn(t))};function li(i,t){return{value:t!=null?t:null,variationIndex:null,reason:{kind:"ERROR",errorKind:i}}}function hi(i,t,e){return{value:i,variationIndex:t!=null?t:null,reason:e!=null?e:null}}var Qn=(i,t,e,n,r)=>{if(t.sendEvents)return new k.EventProcessor(D(p({},t),{eventsCapacity:t.capacity}),new Lt(i,t,e),n,void 0,r,!1,!0)},Ut=class extends k.EventFactoryBase{evalEventClient(t,e,n,r,s,a){let{trackEvents:o,debugEventsUntilDate:c,trackReason:l,flagVersion:h,version:d,variation:f}=r;return super.evalEvent({addExperimentData:l,context:s,debugEventsUntilDate:c,defaultVal:n,flagKey:t,reason:a,trackEvents:!!o,value:e,variation:f,version:h!=null?h:d})}},X=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(r=>r.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,r)=>n.timestamp-r.timestamp),this.container.index.splice(0,this.container.index.length-e)):[]}},xe=class{constructor(t,e,n,r,s,a,o=()=>Date.now()){this.m=t,this.Gt=e,this.Wi=n,this.y=r,this.b=s,this.t=a,this.wt=o,this.$e=Rn(this.Gt)}async init(t,e){this.b.init(t,e),await this.Fe(t)}async upsert(t,e,n){return this.b.upsert(t,e,n)?(await this.Fe(t),!0):!1}async loadCached(t){var r,s,a,o;let e=await oi(this.m.crypto,this.Gt,t),n=await((r=this.m.storage)==null?void 0:r.get(e));if(n==null){if(n=await((s=this.m.storage)==null?void 0:s.get(t.canonicalKey)),n==null)return!1;await((a=this.m.storage)==null?void 0:a.set(e,n)),await((o=this.m.storage)==null?void 0:o.clear(t.canonicalKey))}try{let c=JSON.parse(n),l=Object.entries(c).reduce((h,[d,f])=>(h[d]={version:f.version,flag:f},h),{});return this.b.initCached(t,l),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 _i(){var e;if(this.Y!==void 0)return this.Y;let t=await((e=this.m.storage)==null?void 0:e.get(await this.$e));if(!t)return this.Y=new X,this.Y;try{this.Y=X.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.Y=new X}return this.Y}async Fe(t){var c,l;let e=await this._i(),n=await oi(this.m.crypto,this.Gt,t);e.notice(n,this.wt());let r=e.prune(this.Wi);await Promise.all(r.map(async h=>{var d;return(d=this.m.storage)==null?void 0:d.clear(h.id)})),await((c=this.m.storage)==null?void 0:c.set(await this.$e,e.toJson()));let s=this.y.getAll(),a=Object.entries(s).reduce((h,[d,f])=>(f.flag!==null&&f.flag!==void 0&&(h[d]=f.flag),h),{}),o=JSON.stringify(a);await((l=this.m.storage)==null?void 0:l.set(n,o))}},Le=class{constructor(){this.st={}}init(t){this.st=Object.entries(t).reduce((e,[n,r])=>(e[n]=r,e),{})}insertOrUpdate(t,e){this.st[t]=e}get(t){if(Object.prototype.hasOwnProperty.call(this.st,t))return this.st[t]}getAll(){return this.st}};function tr(i,t){let e=[];return Object.entries(i).forEach(([n,r])=>{let s=t[n];(!s||!K(r,s))&&e.push(n)}),Object.keys(t).forEach(n=>{i[n]||e.push(n)}),e}var Se=class{constructor(t,e){this.Et=new Array,this.y=t,this.t=e}handleFlagChanges(t,e){this.Dt?this.Et.forEach(n=>{try{n(this.Dt,t,e)}catch(r){}}):this.t.warn("Received a change event without an active context. Changes will not be propagated.")}init(t,e){this.Dt=t;let n=this.y.getAll();this.y.init(e);let r=tr(n,e);r.length>0&&this.handleFlagChanges(r,"init")}initCached(t,e){var n;((n=this.Dt)==null?void 0:n.canonicalKey)!==t.canonicalKey&&this.init(t,e)}upsert(t,e,n){var s;if(((s=this.Dt)==null?void 0:s.canonicalKey)!==t.canonicalKey)return this.t.warn("Received an update for an inactive context."),!1;let r=this.y.get(e);return r!==void 0&&r.version>=n.version?!1:(this.y.insertOrUpdate(e,n),this.handleFlagChanges([e],"patch"),!0)}on(t){this.Et.push(t)}off(t){let e=this.Et.indexOf(t);e>-1&&this.Et.splice(e,1)}},Ce=class{constructor(t,e,n,r,s=()=>Date.now()){this.y=new Le,this.b=new Se(this.y,r),this.Kt=this.Ji(t,e,n,r,s)}async Ji(t,e,n,r,s=()=>Date.now()){let a=await $n(t.crypto,e);return new xe(t,a,n,this.y,this.b,r,s)}get(t){return this.a&&Object.prototype.hasOwnProperty.call(this.a,t)?this.Wt(this.a[t]):this.y.get(t)}getAll(){return this.a?p(p({},this.y.getAll()),Object.entries(this.a).reduce((t,[e,n])=>(t[e]=this.Wt(n),t),{})):this.y.getAll()}presetFlags(t){this.y.init(t)}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)}Wt(t){return{flag:{value:t,version:0},version:0}}setOverride(t,e){this.a||(this.a={}),this.a[t]=e,this.b.handleFlagChanges([t],"override")}removeOverride(t){!this.a||!Object.prototype.hasOwnProperty.call(this.a,t)||(delete this.a[t],Object.keys(this.a).length===0&&(this.a=void 0),this.b.handleFlagChanges([t],"override"))}clearAllOverrides(){if(this.a){let t=p({},this.a);this.a=void 0,this.b.handleFlagChanges(Object.keys(t),"override")}}getAllOverrides(){if(!this.a)return{};let t={};return Object.entries(this.a).forEach(([e,n])=>{t[e]=this.Wt(n)}),t}getDebugOverride(){return{setOverride:this.setOverride.bind(this),removeOverride:this.removeOverride.bind(this),clearAllOverrides:this.clearAllOverrides.bind(this),getAllOverrides:this.getAllOverrides.bind(this)}}},ui="unknown hook",bi="beforeEvaluation",ki="afterEvaluation",er="afterTrack";function tt(i,t,e,n,r){try{return n()}catch(s){return i==null||i.error(`An error was encountered in "${t}" of the "${e}" hook: ${s}`),r}}function et(i,t){try{return t.getMetadata().name||ui}catch(e){return i.error("Exception thrown getting metadata for hook. Unable to get hook name."),ui}}function ir(i,t,e){return t.map(n=>tt(i,bi,et(i,n),()=>{var r,s;return(s=(r=n==null?void 0:n.beforeEvaluation)==null?void 0:r.call(n,e,{}))!=null?s:{}},{}))}function nr(i,t,e,n,r){for(let s=t.length-1;s>=0;s-=1){let a=t[s],o=n[s];tt(i,ki,et(i,a),()=>{var c,l;return(l=(c=a==null?void 0:a.afterEvaluation)==null?void 0:c.call(a,e,o,r))!=null?l:{}},{})}}function rr(i,t,e){return t.map(n=>tt(i,bi,et(i,n),()=>{var r,s;return(s=(r=n==null?void 0:n.beforeIdentify)==null?void 0:r.call(n,e,{}))!=null?s:{}},{}))}function sr(i,t,e,n,r){for(let s=t.length-1;s>=0;s-=1){let a=t[s],o=n[s];tt(i,ki,et(i,a),()=>{var c,l;return(l=(c=a==null?void 0:a.afterIdentify)==null?void 0:c.call(a,e,o,r))!=null?l:{}},{})}}function ar(i,t,e){for(let n=t.length-1;n>=0;n-=1){let r=t[n];tt(i,er,et(i,r),()=>{var s;return(s=r==null?void 0:r.afterTrack)==null?void 0:s.call(r,e)},void 0)}}var Ie=class{constructor(t,e){this.t=t,this.z=[],this.z.push(...e)}withEvaluation(t,e,n,r){if(this.z.length===0)return r();let s=[...this.z],a={flagKey:t,context:e,defaultValue:n},o=ir(this.t,s,a),c=r();return nr(this.t,s,a,o,c),c}identify(t,e){let n=[...this.z],r={context:t,timeout:e},s=rr(this.t,n,r);return a=>{sr(this.t,n,r,s,a)}}addHook(t){this.z.push(t)}afterTrack(t){if(this.z.length===0)return;let e=[...this.z];ar(this.t,e,t)}};function or(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 cr(i,t){return`an inspector: "${t}" of an invalid type (${i}) was configured`}function lr(i,t){return`an inspector: "${t}" of type: "${i}" generated an exception`}function hr(i,t){let e=!1,n={method:(...r)=>{try{i.method(...r)}catch(s){e||(e=!0,t.warn(lr(n.type,n.name)))}},type:i.type,name:i.name,synchronous:i.synchronous};return n}var xi="flag-used",Li="flag-details-changed",Si="flag-detail-changed",Ci="client-identity-changed",ur=[xi,Li,Si,Ci];function dr(i,t){let e=ur.includes(i.type)&&i.method&&typeof i.method=="function";return e||t.warn(cr(i.type,i.name)),e}var Pe=class{constructor(t,e){this.Z=[];let n=t.filter(r=>dr(r,e));this.Z=n.map(r=>hr(r,e))}hasInspectors(){return this.Z.length!==0}onFlagUsed(t,e,n){this.Z.forEach(r=>{r.type===xi&&r.method(t,e,n)})}onFlagsChanged(t){this.Z.forEach(e=>{e.type===Li&&e.method(t)})}onFlagChanged(t,e){this.Z.forEach(n=>{n.type===Si&&n.method(t,e)})}onIdentityChanged(t){this.Z.forEach(e=>{e.type===Ci&&e.method(t)})}},Te=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 r=n.filter(s=>s!==e);r.length===0?this.e.delete(t):this.e.set(t,r);return}this.e.delete(t)}}_t(t,e,...n){var r;try{t(...n)}catch(s){(r=this.t)==null||r.error(`Encountered error invoking handler for "${e}", detail: "${s}"`)}}emit(t,...e){let n=this.e.get(t);n==null||n.forEach(r=>this._t(r,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}};function fr(i,t,e){let n=t.info.sdkData(),r;e.applicationInfo&&(e.applicationInfo.id&&(r=r!=null?r:{},r.id=e.applicationInfo.id),e.applicationInfo.version&&(r=r!=null?r:{},r.version=e.applicationInfo.version),e.applicationInfo.name&&(r=r!=null?r:{},r.name=e.applicationInfo.name),e.applicationInfo.versionName&&(r=r!=null?r:{},r.versionName=e.applicationInfo.versionName));let s={name:n.userAgentBase,version:n.version};n.wrapperName&&(s.wrapperName=n.wrapperName),n.wrapperVersion&&(s.wrapperVersion=n.wrapperVersion);let a={sdk:s,[e.credentialType]:i};return r&&(a.application=r),a}var{ClientMessages:di,ErrorKinds:fi}=k,pr=5,Vt=class{constructor(t,e,n,r,s,a){if(this.sdkKey=t,this.autoEnvAttributes=e,this.platform=n,this.l=Bn(),this.Jt=15,this.M=new Ut(!1),this.bt=new Ut(!0),this.qt=!1,this.qi=Tn(),!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.r=new ke(r,a),this.logger=this.r.logger,this.Me=si(this.sdkKey,this.platform.info,this.r.tags,this.r.serviceEndpoints.includeAuthorizationHeader,this.r.userAgentHeaderName),this.k=new Ce(this.platform,t,this.r.maxCachedContexts,this.r.logger),this.P=Xn(t,this.r,n),this.x=Qn(t,this.r,n,this.Me,this.P),this.emitter=new Te,this.emitter.on("error",(c,l)=>{this.logger.error(`error: ${l}, context: ${JSON.stringify(c)}`)}),this.k.on((c,l,h)=>{this.Yi(l,h);let d=S.toLDContext(c);this.emitter.emit("change",d,l),l.forEach(f=>{this.emitter.emit(`change:${f}`,d)})}),this.dataManager=s(this.k,this.r,this.Me,this.emitter,this.P);let o=[...this.r.hooks];this.environmentMetadata=fr(this.sdkKey,this.platform,this.r),this.r.getImplementationHooks(this.environmentMetadata).forEach(c=>{o.push(c)}),this.B=new Ie(this.logger,o),this.at=new Pe(this.r.inspectors,this.logger),this.at.hasInspectors()&&this.B.addHook(or(this.at))}allFlags(){return Object.entries(this.k.getAll()).reduce((e,[n,r])=>(r.flag!==null&&r.flag!==void 0&&!r.flag.deleted&&(e[n]=r.flag.value),e),{})}async close(){var t;await this.flush(),(t=this.x)==null||t.close(),this.dataManager.close(),this.logger.debug("Closed event processor and data source.")}async flush(){var t;try{await((t=this.x)==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.l.hasContext()?ve(this.l.getUnwrappedContext()):void 0}getInternalContext(){return this.l.getContext()}presetFlags(t){this.k.presetFlags(t)}async identify(t,e){let n=await this.identifyResult(t,e);if(n.status==="error")throw n.error;if(n.status==="timeout"){let r=new P(`identify timed out after ${n.timeout} seconds.`);throw this.logger.error(r.message),r}}async identifyResult(t,e){var o,c;let n=(o=e==null?void 0:e.timeout)!=null?o:pr,r=(e==null?void 0:e.timeout)===void 0&&(e==null?void 0:e.noTimeout)===!0;n>this.Jt&&this.logger.warn(`The identify function was called with a timeout greater than ${this.Jt} seconds. We recommend a timeout of less than ${this.Jt} seconds.`);let s=this.qi.execute({before:async()=>{let l=await Yn(t,this.platform);this.autoEnvAttributes===H.Enabled&&(l=await zn(l,this.platform,this.r));let h=S.fromLDContext(l);if(h.valid){let d=this.B.identify(l,e==null?void 0:e.timeout);return{context:l,checkedContext:h,afterIdentify:d}}return{context:l,checkedContext:h}},execute:async l=>{var y;let{context:h,checkedContext:d}=l;if(!d.valid){let x=new Error("Context was unspecified or had no key");return this.emitter.emit("error",h,x),Promise.reject(x)}this.l.set(h,d),(y=this.x)==null||y.sendEvent(this.M.identifyEvent(d));let{identifyPromise:f,identifyResolve:m,identifyReject:g}=this.l.newIdentificationPromise();return this.logger.debug(`Identifying ${JSON.stringify(d)}`),await this.dataManager.identify(m,g,d,e),f},after:async(l,h)=>{var d,f,m;l.status==="complete"?(d=h==null?void 0:h.afterIdentify)==null||d.call(h,{status:"completed"}):l.status==="shed"?(f=h==null?void 0:h.afterIdentify)==null||f.call(h,{status:"shed"}):l.status==="error"&&((m=h==null?void 0:h.afterIdentify)==null||m.call(h,{status:"error"}))}},(c=e==null?void 0:e.sheddable)!=null?c:!1).then(l=>l.status==="error"?{status:"error",error:l.error}:l.status==="shed"?{status:"shed"}:(this.emitter.emit("initialized"),{status:"completed"}));if(r)return s;let a=new Promise(l=>{setTimeout(()=>{l({status:"timeout",timeout:n})},n*1e3)});return Promise.race([s,a])}on(t,e){this.emitter.on(t,e)}off(t,e){this.emitter.off(t,e)}track(t,e,n){var r,s;if(!this.l.hasValidContext()){this.logger.warn(di.MissingContextKeyNoEvent);return}n!==void 0&&!u.Number.is(n)&&((r=this.logger)==null||r.warn(di.invalidMetricValue(typeof n))),(s=this.x)==null||s.sendEvent(this.r.trackEventModifier(this.M.customEvent(t,this.l.getContext(),e,n))),this.B.afterTrack({key:t,context:this.l.getUnwrappedContext(),data:e,metricValue:n})}kt(t,e,n,r){var m,g,y,x;let s=this.l.hasContext();s||(m=this.logger)==null||m.warn("Flag evaluation called before client is fully initialized, data from this evaulation could be stale.");let a=this.l.getContext(),o=this.k.get(t);if(o===void 0||o.flag.deleted){let L=e!=null?e:null,G=new q(`Unknown feature flag "${t}"; returning default value ${L}.`);return this.emitter.emit("error",this.l.getUnwrappedContext(),G),s&&((g=this.x)==null||g.sendEvent(this.M.unknownFlagEvent(t,L,a))),li(fi.FlagNotFound,e)}let{reason:c,value:l,variation:h,prerequisites:d}=o.flag;if(r){let[L,G]=r(l);if(!L){s&&((y=this.x)==null||y.sendEvent(n.evalEventClient(t,e,e,o.flag,a,c)));let I=new q(`Wrong type "${G}" for feature flag "${t}"; returning default value`);return this.emitter.emit("error",this.l.getUnwrappedContext(),I),li(fi.WrongType,e)}}let f=hi(l,h,c);return l==null&&(this.logger.debug("Result value is null. Providing default value."),f.value=e),d==null||d.forEach(L=>{this.kt(L,void 0,this.M)}),s&&((x=this.x)==null||x.sendEvent(n.evalEventClient(t,l,e,o.flag,a,c))),f}variation(t,e){let{value:n}=this.B.withEvaluation(t,this.l.getUnwrappedContext(),e,()=>this.kt(t,e,this.M));return n}variationDetail(t,e){return this.B.withEvaluation(t,this.l.getUnwrappedContext(),e,()=>this.kt(t,e,this.bt))}X(t,e,n,r){return this.B.withEvaluation(t,this.l.getUnwrappedContext(),e,()=>this.kt(t,e,n,r))}boolVariation(t,e){return this.X(t,e,this.M,n=>[u.Boolean.is(n),u.Boolean.getType()]).value}jsonVariation(t,e){return this.variation(t,e)}numberVariation(t,e){return this.X(t,e,this.M,n=>[u.Number.is(n),u.Number.getType()]).value}stringVariation(t,e){return this.X(t,e,this.M,n=>[u.String.is(n),u.String.getType()]).value}boolVariationDetail(t,e){return this.X(t,e,this.bt,n=>[u.Boolean.is(n),u.Boolean.getType()])}numberVariationDetail(t,e){return this.X(t,e,this.bt,n=>[u.Number.is(n),u.Number.getType()])}stringVariationDetail(t,e){return this.X(t,e,this.bt,n=>[u.String.is(n),u.String.getType()])}jsonVariationDetail(t,e){return this.variationDetail(t,e)}addHook(t){this.B.addHook(t)}setEventSendingEnabled(t,e){var n,r,s,a;this.qt!==t&&(this.qt=t,t?(this.logger.debug("Starting event processor"),(n=this.x)==null||n.start()):e?((r=this.logger)==null||r.debug("Flushing event processor before disabling."),this.flush().then(()=>{var o,c;this.qt||((o=this.logger)==null||o.debug("Stopping event processor."),(c=this.x)==null||c.close())})):((s=this.logger)==null||s.debug("Stopping event processor."),(a=this.x)==null||a.close()))}sendEvent(t){var e;(e=this.x)==null||e.sendEvent(t)}getDebugOverrides(){var t,e;return(e=(t=this.k).getDebugOverride)==null?void 0:e.call(t)}Yi(t,e){if(!this.at.hasInspectors())return;let n={};t.forEach(r=>{let s=this.k.get(r);if(s!=null&&s.flag&&!s.flag.deleted){let{reason:a,value:o,variation:c}=s.flag;n[r]=hi(o,c,a)}else n[r]={value:void 0,reason:null,variationIndex:null}}),e==="init"?this.at.onFlagsChanged(n):e==="patch"&&Object.entries(n).forEach(([r,s])=>{this.at.onFlagChanged(r,s)})}};function Ii(i,t,e){e.forEach(n=>{var r;try{(r=n.registerDebug)==null||r.call(n,t)}catch(s){i.error(`Exception thrown registering plugin ${k.safeGetName(i,n)}.`)}})}var Oe=class{constructor(t,e,n){this.k=t,this.Yt=e,this.t=n}async handlePut(t,e){this.t.debug(`Got PUT: ${Object.keys(e)}`);let n=Object.entries(e).reduce((r,[s,a])=>(r[s]={version:a.version,flag:a},r),{});await this.k.init(t,n),this.Yt.requestStateUpdate(E.Valid)}async handlePatch(t,e){this.t.debug(`Got PATCH ${JSON.stringify(e,null,2)}`),this.k.upsert(t,e.key,{version:e.version,flag:e})}async handleDelete(t,e){this.t.debug(`Got DELETE ${JSON.stringify(e,null,2)}`),this.k.upsert(t,e.key,{version:e.version,flag:D(p({},e),{deleted:!0,flagVersion:0,value:void 0,variation:0,trackEvents:!1})})}handleStreamingError(t){this.Yt.reportError(t.kind,t.message,t.code,t.recoverable)}handlePollingError(t){this.Yt.reportError(t.kind,t.message,t.status,t.recoverable)}},Ae=class{constructor(t,e=()=>Date.now()){this.R=t,this.xt=E.Closed,this.Re=e(),this.wt=e}get status(){return{state:this.xt,stateSince:this.Re,lastError:this.Zi}}Ue(t,e=!1){let n=t===E.Interrupted&&this.xt===E.Initializing?E.Initializing:t,r=this.xt!==n;r&&(this.xt=n,this.Re=this.wt()),(r||e)&&this.R.emit("dataSourceStatus",this.status)}requestStateUpdate(t){this.Ue(t)}reportError(t,e,n,r=!1){let s={kind:t,message:e,statusCode:n,time:this.wt()};this.Zi=s,this.Ue(r?E.Interrupted:E.Closed,!0)}};function pi(i){i==null||i.debug("Poll completed after the processor was closed. Skipping processing.")}var Ne=class{constructor(t,e,n,r,s){this.Xi=t,this.Qi=e,this.tn=n,this.w=r,this.t=s,this.p=!1}async Ve(){var s,a,o,c,l,h,d;if(this.p)return;let t=f=>{var m,g,y;(m=this.t)==null||m.error("Polling received invalid data"),(g=this.t)==null||g.debug(`Invalid JSON follows: ${f}`),(y=this.w)==null||y.call(this,new M(w.InvalidData,"Malformed JSON data in polling response"))};(s=this.t)==null||s.debug("Polling LaunchDarkly for feature flag updates");let e=Date.now();try{let f=await this.Xi.requestPayload();try{if(this.p){pi(this.t);return}let m=JSON.parse(f);try{(a=this.tn)==null||a.call(this,m)}catch(g){(o=this.t)==null||o.error(`Exception from data handler: ${g}`)}}catch(m){t(f)}}catch(f){if(this.p){pi(this.t);return}let m=f;if(m.status!==void 0&&!Z(m.status)){(c=this.t)==null||c.error(N(f,"polling request")),(l=this.w)==null||l.call(this,new M(w.ErrorResponse,m.message,m.status));return}(h=this.t)==null||h.error(N(f,"polling request","will retry"))}let n=Date.now()-e,r=Math.max(this.Qi*1e3-n,0);(d=this.t)==null||d.debug("Elapsed: %d ms, sleeping for %d ms",n,r),this.Zt=setTimeout(()=>{this.Ve()},r)}start(){this.Ve()}stop(){this.Zt&&(clearTimeout(this.Zt),this.Zt=void 0),this.p=!0}close(){this.stop()}},gr=(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 j(w.InvalidData,"Malformed JSON data in event stream"))};function mr(i,t){t==null||t.debug(`Received ${i} event after processor was closed. Skipping processing.`)}function gi(i){i==null||i.debug("Ping completed after processor was closed. Skipping processing.")}var $e=class{constructor(t,e,n,r,s,a,o,c,l){var f;this.en=t,this.Xt=e,this.e=n,this.F=r,this.nn=a,this.P=o,this.w=c,this.t=l,this.p=!1;let h;e.useReport&&!r.getEventSourceCapabilities().customMethod?h=e.paths.pathPing(s,t):h=e.useReport?e.paths.pathReport(s,t):e.paths.pathGet(s,t);let d=[...(f=e.queryParameters)!=null?f:[]];this.Xt.withReasons&&d.push({key:"withReasons",value:"true"}),this.F=r,this.vt=p({},e.baseHeaders),this.t=l,this.rn=ni(e.serviceEndpoints,h,d)}je(){this.Lt=Date.now()}Qt(t){this.Lt&&this.P&&this.P.recordStreamInit(this.Lt,!t,Date.now()-this.Lt),this.Lt=void 0}sn(t){var e,n,r;return Mt(t)?((r=this.t)==null||r.warn(N(t,"streaming request","will retry")),this.Qt(!1),this.je(),!0):(this.Qt(!1),(e=this.w)==null||e.call(this,new j(w.ErrorResponse,t.message,t.status,!1)),(n=this.t)==null||n.error(N(t,"streaming request")),!1)}start(){this.je();let t;this.Xt.useReport?(this.vt["content-type"]="application/json",t={method:"REPORT",body:this.en}):t={};let e=this.F.createEventSource(this.rn,D(p({headers:this.vt},t),{errorFilter:n=>this.sn(n),initialRetryDelayMillis:this.Xt.initialRetryDelayMillis,readTimeoutMillis:300*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 r;(r=this.t)==null||r.info(`Will retry stream connection in ${n.delayMillis} milliseconds`)},this.e.forEach(({deserializeData:n,processJson:r},s)=>{e.addEventListener(s,a=>{var o,c;if(this.p){mr(s,this.t);return}if((o=this.t)==null||o.debug(`Received ${s} event`),a!=null&&a.data){this.Qt(!0);let{data:l}=a,h=n(l);if(!h){gr(s,l,this.t,this.w);return}r(h)}else(c=this.w)==null||c.call(this,new j(w.InvalidData,"Unexpected payload from event stream"))})}),e.addEventListener("ping",async()=>{var n,r,s,a,o,c,l;(n=this.t)==null||n.debug("Got PING, going to poll LaunchDarkly for feature flag updates");try{let h=await this.nn.requestPayload();try{if(this.p){gi(this.t);return}let d=JSON.parse(h);try{(r=this.e.get("put"))==null||r.processJson(d)}catch(f){(s=this.t)==null||s.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.w)==null||c.call(this,new M(w.InvalidData,"Malformed JSON data in ping polling response"))}}catch(h){if(this.p){gi(this.t);return}let d=h;(l=this.w)==null||l.call(this,new M(w.ErrorResponse,d.message,d.status))}})}stop(){var t;(t=this.He)==null||t.close(),this.He=void 0,this.p=!0}close(){this.stop()}},jt=class{constructor(t,e,n,r,s,a,o,c,l){this.platform=t,this.flagManager=e,this.credential=n,this.config=r,this.getPollingPaths=s,this.getStreamingPaths=a,this.baseHeaders=o,this.emitter=c,this.diagnosticsManager=l,this.closed=!1,this.logger=r.logger,this.dataSourceStatusManager=new Ae(c),this.Q=new Oe(e,this.dataSourceStatusManager,this.config.logger)}setConnectionParams(t){this.an=t}createPollingProcessor(t,e,n,r,s){let a=new Ne(n,this.config.pollInterval,async o=>{await this.Q.handlePut(e,o),r==null||r()},o=>{this.emitter.emit("error",t,o),this.Q.handlePollingError(o),s==null||s(o)},this.logger);this.updateProcessor=this.ze(a,this.dataSourceStatusManager)}createStreamingProcessor(t,e,n,r,s){var o;let a=new $e(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.an)==null?void 0:o.queryParameters},this.createStreamListeners(e,r),this.platform.requests,this.platform.encoding,n,this.diagnosticsManager,c=>{this.emitter.emit("error",t,c),this.Q.handleStreamingError(c),s==null||s(c)},this.logger);this.updateProcessor=this.ze(a,this.dataSourceStatusManager)}createStreamListeners(t,e){let n=new Map;return n.set("put",{deserializeData:JSON.parse,processJson:async r=>{await this.Q.handlePut(t,r),e==null||e()}}),n.set("patch",{deserializeData:JSON.parse,processJson:async r=>{this.Q.handlePatch(t,r)}}),n.set("delete",{deserializeData:JSON.parse,processJson:async r=>{this.Q.handleDelete(t,r)}}),n}ze(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 Ht(i,t){let e=Object.keys(t),n="$flagsState",r="$valid",s=t[n];!s&&e.length&&i.warn("LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."),t[r]===!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!==r){let c;s&&s[o]?c=p({value:t[o]},s[o]):c={value:t[o],version:0},a[o]={version:c.version,flag:c}}}),a}function zt(){return typeof document!==void 0}function Re(){return typeof window!==void 0}function Bt(i,t,e){return zt()?(document.addEventListener(i,t,e),()=>{document.removeEventListener(i,t,e)}):()=>{}}function Gt(i,t,e){return zt()?(window.addEventListener(i,t,e),()=>{window.removeEventListener(i,t,e)}):()=>{}}function T(){return Re()?window.location.href:""}function Pi(){return Re()?window.location.search:""}function Ti(){return Re()?window.location.hash:""}function Oi(){if(typeof crypto!==void 0)return crypto;throw Error("Access to a web crypto API is required")}function Ai(){return zt()?document.visibilityState:"visibile"}function Ni(i){if(zt())return document.querySelectorAll(i)}var yr="[BrowserDataManager]",it=class extends jt{constructor(e,n,r,s,a,o,c,l,h,d){super(e,n,r,s,o,c,l,h,d);this.Dn=a;this.ot=void 0;this.te=!1;this.ot=a.streaming}T(e,...n){this.logger.debug(`${yr} ${e}`,...n)}async identify(e,n,r,s){if(this.closed){this.T("Identify called after data manager was closed.");return}this.context=r;let a=s;a!=null&&a.hash?this.setConnectionParams({queryParameters:[{key:"h",value:a.hash}]}):this.setConnectionParams(),this.ee=a==null?void 0:a.hash,a!=null&&a.bootstrap?this.cn(r,a.bootstrap,e):(await this.flagManager.loadCached(r)&&this.T("Identify - Flags loaded from cache. Continuing to initialize via a poll."),await this.ln(r,e,n)),this.ie()}async hn(e){let n=JSON.stringify(S.toLDContext(e)),r=Fe(n,this.config.serviceEndpoints,this.getPollingPaths(),this.platform.requests,this.platform.encoding,this.baseHeaders,[],this.config.withReasons,this.config.useReport,this.ee),s=3,a;for(let o=0;o<=s;o+=1)try{return await r.requestPayload()}catch(c){if(!Mt(c))throw c;a=c,o<s&&(this.T(N(c,"initial poll request","will retry")),await Ee(1e3))}throw a}async ln(e,n,r){var s,a;try{this.dataSourceStatusManager.requestStateUpdate(E.Initializing);let o=await this.hn(e);try{let l=this.createStreamListeners(e,n).get("put");l.processJson(l.deserializeData(o))}catch(c){this.dataSourceStatusManager.reportError(w.InvalidData,(s=c.message)!=null?s:"Could not parse poll response")}}catch(o){this.dataSourceStatusManager.reportError(w.NetworkError,(a=o.message)!=null?a:"unexpected network error",o.status),r(o)}}cn(e,n,r){this.flagManager.setBootstrap(e,Ht(this.logger,n)),this.T("Identify - Initialization completed from bootstrap"),r()}setForcedStreaming(e){this.ot=e,this.ie()}setAutomaticStreamingState(e){this.te=e,this.ie()}ie(){let e=this.ot||this.te&&this.ot===void 0;this.T(`Updating streaming state. forced(${this.ot}) automatic(${this.te})`),e?this.un():this.dn()}dn(){var e;this.updateProcessor&&this.T("Stopping update processor."),(e=this.updateProcessor)==null||e.close(),this.updateProcessor=void 0}un(){if(this.updateProcessor){this.T("Update processor already active. Not changing state.");return}if(!this.context){this.T("Context not set, not starting update processor.");return}this.T("Starting update processor."),this.fn(this.context)}fn(e,n,r){var c;let s=S.toLDContext(e);(c=this.updateProcessor)==null||c.close();let a=JSON.stringify(S.toLDContext(e)),o=Fe(a,this.config.serviceEndpoints,this.getPollingPaths(),this.platform.requests,this.platform.encoding,this.baseHeaders,[],this.config.withReasons,this.config.useReport,this.ee);this.createStreamingProcessor(s,e,o,n,r),this.updateProcessor.start()}};function $i(i){let e=Bt("visibilitychange",()=>{Ai()==="hidden"&&i()}),n=Gt("pagehide",i);return()=>{e(),n()}}function nt(i){if(typeof i!="string")throw new TypeError("Expected a string");return i.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function vr(i,t,e,n){let s=((i.kind==="substring"||i.kind==="regex")&&n.includes("/")?t:t.replace(n,"")).replace(e,"");switch(i.kind){case"exact":return new RegExp(`^${nt(i.url)}/?$`).test(t);case"canonical":return new RegExp(`^${nt(i.url)}/?$`).test(s);case"substring":return new RegExp(`.*${nt(i.substring)}.*$`).test(s);case"regex":return new RegExp(i.pattern).test(s);default:return!1}}function wr(i,t){let e=[];return t.forEach(n=>{let r=i.target,{selector:s}=n,a=Ni(s);for(;r&&(a!=null&&a.length);){for(let o=0;o<a.length;o+=1)if(r===a[o]){e.push(n);break}r=r.parentNode}}),e}var rt=class{constructor(t,e){let n=t.filter(a=>{var o;return(o=a.urls)==null?void 0:o.some(c=>vr(c,T(),Pi(),Ti()))}),r=n.filter(a=>a.kind==="pageview"),s=n.filter(a=>a.kind==="click");if(r.forEach(a=>e(a)),s.length){let a=o=>{wr(o,s).forEach(c=>{e(c)})};this.Be=Bt("click",a)}}close(){var t;(t=this.Be)==null||t.call(this)}};var Er=300,Kt=class{constructor(t){this.ne=T();let e=()=>{let r=T();r!==this.ne&&(this.ne=r,t())};this.re=setInterval(e,Er);let n=Gt("popstate",e);this.Ge=()=>{n()}}close(){var t;this.re&&clearInterval(this.re),(t=this.Ge)==null||t.call(this)}};var st=class{constructor(t,e,n,r,s,a=o=>new Kt(o)){this.F=e;this.mn=r;this.gn=s;this.St=[];this.We=!1;this.Ct=`${n}/sdk/goals/${t}`,this.Ke=a(()=>{this.ae()})}async initialize(){await this.pn(),this.ae()}startTracking(){this.We=!0,this.ae()}ae(){var t;this.We&&((t=this.se)==null||t.close(),this.St&&this.St.length&&(this.se=new rt(this.St,e=>{this.gn(T(),e)})))}async pn(){try{let t=await this.F.fetch(this.Ct);this.St=await t.json()}catch(t){this.mn(new J(`Encountered error fetching goals: ${t}`))}}close(){var t,e;(t=this.Ke)==null||t.close(),(e=this.se)==null||e.close()}};function Fi(i){return i.kind==="click"}var Dr=2,Mi={fetchGoals:!0,eventUrlTransformer:i=>i,streaming:void 0,plugins:[]},br={fetchGoals:u.Boolean,eventUrlTransformer:u.Function,streaming:u.Boolean,plugins:u.createTypeArray("LDPlugin",{})};function kr(i){var e;let t=p({},i);return(e=t.flushInterval)!=null||(t.flushInterval=Dr),t}function Ri(i){let t=kr(i);return Object.keys(Mi).forEach(e=>{delete t[e]}),t}function Ue(i,t){let e=p({},Mi);return Object.entries(br).forEach(n=>{let[r,s]=n,a=i[r];a!==void 0&&(s.is(a)?e[r]=a:t.warn(b.wrongOptionType(r,s.getType(),typeof a)))}),e}var at=class{constructor(t,e){this.yn=t;this._e=[];switch(e){case"sha1":this.oe="SHA-1";break;case"sha256":this.oe="SHA-256";break;default:throw new Error(`Algorithm is not supported ${e}`)}}async asyncDigest(t){let e=this._e.join(""),n=new TextEncoder().encode(e),r=await this.yn.subtle.digest(this.oe,n);switch(t){case"base64":return btoa(String.fromCharCode(...new Uint8Array(r)));case"hex":return[...new Uint8Array(r)].map(s=>s.toString(16).padStart(2,"0")).join("");default:throw new Error(`Encoding is not supported ${t}`)}}update(t){return this._e.push(t),this}};var xr={start:0,end:3},Lr={start:4,end:5},Ve={start:6,end:7},je={start:8,end:8},Sr={start:9,end:9},Cr={start:10,end:15};function Ir(){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 B(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 Pr(i){return i[je.start]=(i[je.start]|128)&191,i[Ve.start]=i[Ve.start]&15|64,`${B(i,xr)}-${B(i,Lr)}-${B(i,Ve)}-${B(i,je)}${B(i,Sr)}-${B(i,Cr)}`}function Tr(){let i=Ir();return Pr(i)}function He(){return typeof crypto!==void 0&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Tr()}var ot=class{createHash(t){return new at(Oi(),t)}randomUUID(){return He()}};function Or(i){let t=Array.from(i,e=>String.fromCodePoint(e)).join("");return btoa(t)}var ct=class{btoa(t){return Or(new TextEncoder().encode(t))}};var lt=class{constructor(t){this.r=t}platformData(){return{name:"JS"}}sdkData(){let t={name:"@launchdarkly/js-client-sdk",version:"0.11.0",userAgentBase:"JSClient"};return this.r.wrapperName&&(t.wrapperName=this.r.wrapperName),this.r.wrapperVersion&&(t.wrapperVersion=this.r.wrapperVersion),t}};var ht=class{constructor(t,e){this.Ct=t;this.e={};this.N=new kt(e.initialRetryDelayMillis,e.retryResetIntervalMillis),this.Je=e.errorFilter,this.qe()}qe(){this.tt=new EventSource(this.Ct),this.tt.onopen=()=>{var t;this.N.success(),(t=this.onopen)==null||t.call(this)},this.tt.onerror=t=>{var e;this.vn(t),(e=this.onerror)==null||e.call(this,t)},Object.entries(this.e).forEach(([t,e])=>{e.forEach(n=>{var r;(r=this.tt)==null||r.addEventListener(t,n)})})}addEventListener(t,e){var n,r,s;(r=(n=this.e)[t])!=null||(n[t]=[]),this.e[t].push(e),(s=this.tt)==null||s.addEventListener(t,e)}close(){var t,e;clearTimeout(this.ce),this.ce=void 0,(t=this.tt)==null||t.close(),(e=this.onclose)==null||e.call(this)}wn(t){var e;(e=this.onretrying)==null||e.call(this,{delayMillis:t}),this.ce=setTimeout(()=>{this.qe()},t)}vn(t){this.close(),!(t.status&&typeof t.status=="number"&&!this.Je(t))&&this.wn(this.N.fail())}};var ut=class{fetch(t,e){return fetch(t,e)}createEventSource(t,e){return new ht(t,e)}getEventSourceCapabilities(){return{customMethod:!1,readTimeout:!1,headers:!1}}};function Ui(){return typeof localStorage!="undefined"}var dt=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(r){(n=this.t)==null||n.error(`Error setting key in localStorage: ${t}, reason: ${r}`)}}};var ft=class{constructor(t,e){this.encoding=new ct;this.crypto=new ot;this.requests=new ut;Ui()&&(this.storage=new dt(t)),this.info=new lt(e)}};var ze=class extends Vt{constructor(t,e,n={},r){var m;let{logger:s,debug:a}=n,o=s!=null?s:new R({destination:{debug:console.debug,info:console.info,warn:console.warn,error:console.error},level:a?"debug":"info"}),c=(m=n.baseUri)!=null?m:"https://clientsdk.launchdarkly.com",l=r!=null?r:new ft(o,n),h=Ue(n,o),d=Ri(D(p({},n),{logger:o})),{eventUrlTransformer:f}=h;super(t,e,l,d,(g,y,x,L,G)=>new it(l,g,t,y,h,()=>({pathGet(I,$){return`/sdk/evalx/${t}/contexts/${we($,I)}`},pathReport(I,$){return`/sdk/evalx/${t}/context`},pathPing(I,$){throw new Error("Ping for polling unsupported.")}}),()=>({pathGet(I,$){return`/eval/${t}/${we($,I)}`},pathReport(I,$){return`/eval/${t}`},pathPing(I,$){return`/ping/${t}`}}),x,L,G),{analyticsEventPath:`/events/bulk/${t}`,diagnosticEventPath:`/events/diagnostic/${t}`,includeAuthorizationHeader:!1,highTimeoutThreshold:5,userAgentHeaderName:"x-launchdarkly-user-agent",trackEventModifier:g=>new k.InputCustomEvent(g.context,g.key,g.data,g.metricValue,g.samplingRatio,f(T())),getImplementationHooks:g=>k.safeGetHooks(o,g,h.plugins),credentialType:"clientSideId"}),this.setEventSendingEnabled(!0,!1),this.he=h.plugins,h.fetchGoals&&(this.le=new st(t,l.requests,c,g=>{o.error(g.message)},(g,y)=>{let x=this.getInternalContext();if(!x)return;let L=f(g);Fi(y)?this.sendEvent({kind:"click",url:L,samplingRatio:1,key:y.key,creationDate:Date.now(),context:x,selector:y.selector}):this.sendEvent({kind:"pageview",url:L,samplingRatio:1,key:y.key,creationDate:Date.now(),context:x})}),this.le.initialize(),h.automaticBackgroundHandling&&$i(()=>this.flush()))}registerPlugins(t){k.safeRegisterPlugins(this.logger,this.environmentMetadata,t,this.he||[]);let e=this.getDebugOverrides();e&&Ii(this.logger,e,this.he||[])}setInitialContext(t){this.ue=t}async identify(t,e){return super.identify(t,e)}async identifyResult(t,e){var s,a,o;if(!this.ct)return this.logger.error("Client must be started before it can identify a context, did you forget to call start()?"),{status:"error",error:new Error("Identify called before start")};let n=p({},e);(e==null?void 0:e.sheddable)===void 0&&(n.sheddable=!0);let r=await super.identifyResult(t,n);return r.status==="completed"?(this.U={status:"complete"},(s=this.G)==null||s.call(this,this.U)):r.status==="error"&&(this.U={status:"failed",error:r.error},(a=this.G)==null||a.call(this,this.U)),(o=this.le)==null||o.startTracking(),r}start(t){var n,r;if(this.U)return Promise.resolve(this.U);if(this.ct)return this.ct;if(!this.ue)return this.logger.error("Initial context not set"),Promise.resolve({status:"failed",error:new Error("Initial context not set")});let e=D(p({},(n=t==null?void 0:t.identifyOptions)!=null?n:{}),{sheddable:!1});if(t!=null&&t.bootstrap&&!e.bootstrap&&(e.bootstrap=t.bootstrap),e!=null&&e.bootstrap)try{let s=Ht(this.logger,e.bootstrap);this.presetFlags(s)}catch(s){this.logger.error("Failed to bootstrap data",s)}return this.h||(this.h=new Promise(s=>{this.G=s})),this.ct=this.et(this.h,(r=t==null?void 0:t.timeout)!=null?r:5),this.identifyResult(this.ue,e),this.ct}waitForInitialization(t){var n;let e=(n=t==null?void 0:t.timeout)!=null?n:5;return this.U?Promise.resolve(this.U):this.h?this.et(this.h,e):(this.h||(this.h=new Promise(r=>{this.G=r})),this.et(this.h,e))}et(t,e){let n=Nt(e,"waitForInitialization");return Promise.race([t.then(r=>(n.cancel(),r)),n.promise.then(()=>({status:"complete"})).catch(()=>({status:"timeout"}))]).catch(r=>{var s;return(s=this.logger)==null||s.error(r.message),{status:"failed",error:r}})}setStreaming(t){this.dataManager.setForcedStreaming(t)}Ye(){this.dataManager.setAutomaticStreamingState(!!this.emitter.listenerCount("change"))}on(t,e){super.on(t,e),this.Ye()}off(t,e){super.off(t,e),this.Ye()}};function Vi(i,t,e,n={},r){let s=new ze(i,e,n,r);s.setInitialContext(t);let a={variation:(o,c)=>s.variation(o,c),variationDetail:(o,c)=>s.variationDetail(o,c),boolVariation:(o,c)=>s.boolVariation(o,c),boolVariationDetail:(o,c)=>s.boolVariationDetail(o,c),numberVariation:(o,c)=>s.numberVariation(o,c),numberVariationDetail:(o,c)=>s.numberVariationDetail(o,c),stringVariation:(o,c)=>s.stringVariation(o,c),stringVariationDetail:(o,c)=>s.stringVariationDetail(o,c),jsonVariation:(o,c)=>s.jsonVariation(o,c),jsonVariationDetail:(o,c)=>s.jsonVariationDetail(o,c),track:(o,c,l)=>s.track(o,c,l),on:(o,c)=>s.on(o,c),off:(o,c)=>s.off(o,c),flush:()=>s.flush(),setStreaming:o=>s.setStreaming(o),identify:(o,c)=>s.identifyResult(o,c),getContext:()=>s.getContext(),close:()=>s.close(),allFlags:()=>s.allFlags(),addHook:o=>s.addHook(o),waitForInitialization:o=>s.waitForInitialization(o),logger:s.logger,start:o=>s.start(o)};return s.registerPlugins(a),a}var ji=["ready","failed","initialized"],pt=class{constructor(t){this.n=t;this.e=new Map}on(t,e){var n;ji.includes(t)?this.e.has(t)?(n=this.e.get(t))==null||n.push(e):this.e.set(t,[e]):this.n.on(t,e)}off(t,e){if(ji.includes(t)){let n=this.e.get(t);if(!n)return;if(e){let r=n.filter(s=>s!==e);r.length===0?this.e.delete(t):this.e.set(t,r);return}this.e.delete(t)}else this.n.off(t,e)}_t(t,e,...n){try{t(...n)}catch(r){this.n.logger.error(`Encountered error invoking handler for "${e}", detail: "${r}"`)}}emit(t,...e){let n=this.e.get(t);n==null||n.forEach(r=>this._t(r,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}};function Wt(i,t){let e=i.then(n=>(t&&setTimeout(()=>{t(null,n)},0),n),n=>{if(t)setTimeout(()=>{t(n,null)},0);else return Promise.reject(n)});return t?void 0:e}var gt=class{constructor(t,e,n){this.de="initializing";let r=n==null?void 0:n.bootstrap,s=n==null?void 0:n.hash,a=p({},n);delete a.bootstrap,delete a.hash,this.n=Vi(t,e,H.Disabled,n),this.R=new pt(this.n),this.logger=this.n.logger,this.n.start(),this.En(e,r,s)}async En(t,e,n){var r,s;try{let a=await this.n.identify(t,{noTimeout:!0,bootstrap:e,hash:n,sheddable:!1});if(a.status==="error")throw a.error;if(a.status==="timeout")throw new P("Identify timed out");this.de="success",(r=this.G)==null||r.call(this),this.R.emit("initialized")}catch(a){this.Xe=a,this.de="failure",(s=this.Ze)==null||s.call(this,a),this.R.emit("failed",a)}this.R.emit("ready")}allFlags(){return this.n.allFlags()}boolVariation(t,e){return this.n.boolVariation(t,e)}boolVariationDetail(t,e){return this.n.boolVariationDetail(t,e)}jsonVariation(t,e){return this.n.jsonVariation(t,e)}jsonVariationDetail(t,e){return this.n.jsonVariationDetail(t,e)}numberVariation(t,e){return this.n.numberVariation(t,e)}numberVariationDetail(t,e){return this.n.numberVariationDetail(t,e)}off(t,e){this.R.off(t,e)}on(t,e){this.R.on(t,e)}stringVariation(t,e){return this.n.stringVariation(t,e)}stringVariationDetail(t,e){return this.n.stringVariationDetail(t,e)}track(t,e,n){this.n.track(t,e,n)}variation(t,e){return this.n.variation(t,e)}variationDetail(t,e){return this.n.variationDetail(t,e)}addHook(t){this.n.addHook(t)}setStreaming(t){this.n.setStreaming(t)}identify(t,e,n){return Wt(this.n.identify(t,{hash:e,sheddable:!1}).then(r=>{if(r.status==="error")throw r.error;if(r.status==="timeout")throw new P("Identify timed out");return this.allFlags()}),n)}close(t){return Wt(this.n.close().then(),t)}flush(t){return Wt(this.n.flush().then(()=>{}),t)}getContext(){return this.n.getContext()}waitForInitialization(t){var e;if(this.h)return this.et(this.h,t);switch(this.de){case"success":return Promise.resolve();case"failure":return Promise.reject(this.Xe);case"initializing":break;default:throw new Error("Unexpected initialization state. This represents an implementation error in the SDK.")}return t===void 0&&((e=this.logger)==null||e.warn("The waitForInitialization function was called without a timeout specified. In a future version a default timeout will be applied.")),this.h||(this.h=new Promise((n,r)=>{this.G=n,this.Ze=r})),this.et(this.h,t)}async waitUntilReady(){try{await this.waitForInitialization()}catch(t){}}et(t,e){if(e){let n=Nt(e,"waitForInitialization");return Promise.race([t.then(()=>n.cancel()),n.promise]).catch(r=>{var s;throw r instanceof P&&((s=this.logger)==null||s.error(r.message)),r})}return t}};function Ar(i){return new R(i)}function Nr(i,t,e){return new gt(i,t,e)}0&&(module.exports={basicLogger,initialize});
1
+ "use strict";var yt=Object.defineProperty,ji=Object.defineProperties,zi=Object.getOwnPropertyDescriptor,Hi=Object.getOwnPropertyDescriptors,Bi=Object.getOwnPropertyNames,mt=Object.getOwnPropertySymbols;var _t=Object.prototype.hasOwnProperty,Be=Object.prototype.propertyIsEnumerable;var He=(i,t,e)=>t in i?yt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,g=(i,t)=>{for(var e in t||(t={}))_t.call(t,e)&&He(i,e,t[e]);if(mt)for(var e of mt(t))Be.call(t,e)&&He(i,e,t[e]);return i},D=(i,t)=>ji(i,Hi(t));var Jt=(i,t)=>{var e={};for(var n in i)_t.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&mt)for(var n of mt(i))t.indexOf(n)<0&&Be.call(i,n)&&(e[n]=i[n]);return e};var Ki=(i,t)=>{for(var e in t)yt(i,e,{get:t[e],enumerable:!0})},Gi=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Bi(t))!_t.call(i,r)&&r!==e&&yt(i,r,{get:()=>t[r],enumerable:!(n=zi(t,r))||n.enumerable});return i};var Wi=i=>Gi(yt({},"__esModule",{value:!0}),i);var Fr={};Ki(Fr,{basicLogger:()=>$r,initialize:()=>Nr});module.exports=Wi(Fr);function _i(i){return`/${i.replace(/~/g,"~0").replace(/\//g,"~1")}`}function Xe(i){return i.indexOf("~")?i.replace(/~1/g,"/").replace(/~0/g,"~"):i}function Ji(i){return(i.startsWith("/")?i.substring(1):i).split("/").map(e=>Xe(e))}function qi(i){return!i.startsWith("/")}function Yi(i){return!i.match(/\/\/|(^\/.*~[^0|^1])|~$/)}var A=class{constructor(t,e=!1){if(e){let n=t;this.m=[n],this.isValid=n!=="",this.redactionName=n.startsWith("/")?_i(n):n}else{if(this.redactionName=t,t===""||t==="/"||!Yi(t)){this.isValid=!1,this.m=[];return}qi(t)?this.m=[t]:t.indexOf("/",1)<0?this.m=[Xe(t.slice(1))]:this.m=Ji(t),this.m[0]==="_meta"?this.isValid=!1:this.isValid=!0}}get(t){let{m:e,isValid:n}=this;if(!n)return;let r=t;for(let s=0;s<e.length;s+=1){let a=e[s];if(r!=null&&Object.prototype.hasOwnProperty.call(r,a)&&typeof r=="object"&&!Array.isArray(r))r=r[a];else return}return r}getComponent(t){return this.m[t]}get depth(){return this.m.length}get isKind(){return this.m.length===1&&this.m[0]==="kind"}compare(t){return this.depth===t.depth&&this.m.every((e,n)=>e===t.getComponent(n))}get components(){return[...this.m]}};A.InvalidReference=new A("");var Zt=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.bt=t,this.typeOf=typeof e}is(t){return Array.isArray(t)?!1:typeof t===this.typeOf}getType(){return this.bt}},Et=class{constructor(t,e){this.bt=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.bt}},W=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}},Dt=class extends O{constructor(t){super(`string matching ${t}`,""),this.expression=t}is(t){return typeof t=="string"&&!!t.match(this.expression)}},Xt=class{is(t){return typeof t=="function"}getType(){return"function"}},Qt=class{is(t){return typeof t=="boolean"||typeof t=="undefined"||t===null}getType(){return"boolean | undefined | null"}},Zi=/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d\d*)?(Z|[-+]\d\d(:\d\d)?)/,te=class{is(t){return typeof t=="number"||typeof t=="string"&&Zi.test(t)}getType(){return"date"}},ee=class extends Dt{constructor(){super(/^(\w|\.|-)+$/)}is(t){return super.is(t)&&t!=="kind"}},h=class{static createTypeArray(t,e){return new Et(t,e)}static numberWithMin(t){return new W(t)}static stringMatchingRegex(t){return new Dt(t)}};h.String=new O("string","");h.Number=new O("number",0);h.ObjectOrFactory=new Zt;h.Object=new O("object",{});h.StringArray=new Et("string[]","");h.Boolean=new O("boolean",!0);h.Function=new Xt;h.Date=new te;h.Kind=new ee;h.NullableBoolean=new Qt;function Qe(i){return"kind"in i?h.String.is(i.kind)&&i.kind!=="multi":!1}function ti(i){return"kind"in i?h.String.is(i.kind)&&i.kind==="multi":!1}function ei(i){return!("kind"in i)||i.kind===null||i.kind===void 0}function bt(i,t=[]){if(i===null||typeof i!="object")return JSON.stringify(i);if(t.includes(i))throw new Error("Cycle detected");return Array.isArray(i)?`[${i.map(r=>bt(r,[...t,i])).map(r=>r===void 0?"null":r).join(",")}]`:`{${Object.keys(i).sort().map(n=>{let r=bt(i[n],[...t,i]);if(r!==void 0)return`${JSON.stringify(n)}:${r}`}).filter(n=>n!==void 0).join(",")}}`}var ie="user";function Ke(i){return i.includes("%")||i.includes(":")?i.replace(/%/g,"%25").replace(/:/g,"%3A"):i}function Xi(i){return i&&h.Object.is(i)}function Ge(i){return h.Kind.is(i)}function We(i){return h.String.is(i)&&i!==""}function qt(i,t=!1){return i?i.map(e=>new A(e,t)):[]}function Qi(i){return i!=null}function tn(i){let t=D(g({},i.custom||[]),{kind:"user",key:String(i.key)});if(Qi(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 S=class i{constructor(t,e,n){this.I=!1,this.st=!1,this.oe=!1,this.M={},this.kind=e,this.valid=t,this.message=n}static x(t,e){return new i(!1,t,e)}static qe(t,e){if(!(!e||!t.isValid))return t.depth===1&&t.getComponent(0)==="anonymous"?!!(e!=null&&e.anonymous):t.get(e)}ce(t){if(this.I)return this.M[t];if(this.kind===t)return this.v}static Ye(t){let e=Object.keys(t).filter(c=>c!=="kind"),n=e.every(Ge);if(!e.length)return i.x("multi","A multi-kind context must contain at least one kind");if(!n)return i.x("multi","Context contains invalid kinds");let r={},s=!0,a=e.reduce((c,l)=>{var d;let u=t[l];return Xi(u)?(c[l]=u,r[l]=qt((d=u._meta)==null?void 0:d.privateAttributes)):s=!1,c},{});if(!s)return i.x("multi","Context contained contexts that were not objects");if(!Object.values(a).every(c=>We(c.key)))return i.x("multi","Context contained invalid keys");if(e.length===1){let c=e[0],l=new i(!0,c);return l.v=D(g({},a[c]),{kind:c}),l.at=r,l.st=c==="user",l}let o=new i(!0,t.kind);return o.M=a,o.at=r,o.I=!0,o}static Ze(t){var c;let{key:e,kind:n}=t,r=Ge(n),s=We(e);if(!r)return i.x(n!=null?n:"unknown","The kind was not valid for the context");if(!s)return i.x(n,"The key for the context was not valid");let a=qt((c=t._meta)==null?void 0:c.privateAttributes),o=new i(!0,n);return o.st=n==="user",o.v=t,o.at={[n]:a},o}static Xe(t){if(!(t.key!==void 0&&t.key!==null))return i.x("user","The key for the context was not valid");let n=new i(!0,"user");return n.st=!0,n.oe=!0,n.v=tn(t),n.at={user:qt(t.privateAttributeNames,!0)},n}static fromLDContext(t){return t?Qe(t)?i.Ze(t):ti(t)?i.Ye(t):ei(t)?i.Xe(t):i.x("unknown","Context was not of a valid kind"):i.x("unknown","No context specified. Returning default value")}static toLDContext(t){if(!t.valid)return;let e=t.getContexts();if(!t.I)return e[0][1];let n={kind:"multi"};return e.forEach(r=>{let s=r[0],a=r[1];n[s]=a}),n}valueForKind(t,e=ie){return t.isKind?this.kinds:i.qe(t,this.ce(e))}key(t=ie){var e;return(e=this.ce(t))==null?void 0:e.key}get isMultiKind(){return this.I}get canonicalKey(){return this.st?this.v.key:this.I?Object.keys(this.M).sort().map(t=>`${t}:${Ke(this.M[t].key)}`).join(":"):`${this.kind}:${Ke(this.v.key)}`}get kinds(){return this.I?Object.keys(this.M):[this.kind]}get kindsAndKeys(){return this.I?Object.entries(this.M).reduce((t,[e,n])=>(t[e]=n.key,t),{}):{[this.kind]:this.v.key}}privateAttributes(t){var e;return((e=this.at)==null?void 0:e[t])||[]}getContexts(){return this.I?Object.entries(this.M):[[this.kind,this.v]]}get legacy(){return this.oe}canonicalUnfilteredJson(){if(this.valid){if(this.kt)return this.kt;try{this.kt=bt(i.toLDContext(this))}catch(t){}return this.kt}}};S.UserKind=ie;var en=["key","kind","_meta","anonymous"].map(i=>new A(i,!0)),nn=["name","ip","firstName","lastName","email","avatar","country"];function rn(i,t){return i.depth===t.length&&t.every((e,n)=>e===i.getComponent(n))}function sn(i,t){let e=[],n={},r=[];for(e.push(...Object.keys(i).map(s=>({key:s,ptr:[s],source:i,parent:n,visited:[i]})));e.length;){let s=e.pop(),a=t.find(o=>rn(o,s.ptr));if(a)r.push(a.redactionName);else{let o=s.source[s.key];o===null?s.parent[s.key]=o:Array.isArray(o)?s.parent[s.key]=[...o]:typeof o=="object"?s.visited.includes(o)||(s.parent[s.key]={},e.push(...Object.keys(o).map(c=>({key:c,ptr:[...s.ptr,c],source:o,parent:s.parent[s.key],visited:[...s.visited,o]})))):s.parent[s.key]=o}}return{cloned:n,excluded:r.sort()}}var ne=class{constructor(t,e){this.Qe=t,this.ti=e}filter(t,e=!1){let n=t.getContexts();if(n.length===1)return this.le(t,n[0][1],n[0][0],e);let r={kind:"multi"};return n.forEach(([s,a])=>{r[s]=this.le(t,a,s,e)}),r}ei(t,e,n,r){return(r?Object.keys(e).map(s=>new A(s,!0)):[...this.ti,...t.privateAttributes(n)]).filter(s=>!en.some(a=>a.compare(s)))}le(t,e,n,r){let s=this.Qe||r&&e.anonymous===!0,{cloned:a,excluded:o}=sn(e,this.ei(t,e,n,s));return t.legacy&&nn.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}},_e=30*1e3,an=.5,kt=class{constructor(t,e,n=Math.random){this.ii=e,this.ni=n,this.xt=0,this.ue=Math.max(1,t),this.ri=Math.ceil(Math.log2(_e/this.ue))}T(){let t=Math.min(this.xt,this.ri),e=this.ue*2**t;return Math.min(e,_e)}si(t){return t-Math.trunc(this.ni()*an*t)}success(t=Date.now()){this.Lt=t}fail(t=Date.now()){this.Lt!==void 0&&t-this.Lt>this.ii&&(this.xt=0),this.Lt=void 0;let e=this.si(this.T());return this.xt+=1,e}};var Je;(function(i){i[i.Valid=0]="Valid",i[i.Initializing=1]="Initializing",i[i.Interrupted=2]="Interrupted",i[i.Closed=3]="Closed"})(Je||(Je={}));var R=class extends Error{constructor(t,e,n,r=!0){super(e),this.kind=t,this.status=n,this.name="LaunchDarklyPollingError",this.recoverable=r}},j=class extends Error{constructor(t,e,n,r=!0){super(e),this.kind=t,this.code=n,this.name="LaunchDarklyStreamingError",this.recoverable=r}};var Mr=120*1e3,Ur=300*1e3;var w;(function(i){i.Unknown="UNKNOWN",i.NetworkError="NETWORK_ERROR",i.ErrorResponse="ERROR_RESPONSE",i.InvalidData="INVALID_DATA"})(w||(w={}));var z;(function(i){i[i.Disabled=0]="Disabled",i[i.Enabled=1]="Enabled"})(z||(z={}));var H;(function(i){i[i.AnalyticsEvents=0]="AnalyticsEvents",i[i.DiagnosticEvent=1]="DiagnosticEvent"})(H||(H={}));var F;(function(i){i[i.Succeeded=0]="Succeeded",i[i.Failed=1]="Failed",i[i.FailedAndMustShutDown=2]="FailedAndMustShutDown"})(F||(F={}));function V(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 on(i){return typeof i=="symbol"?"NaN":typeof i=="bigint"?`${i}n`:String(Number(i))}function cn(i){return typeof i=="symbol"?"NaN":typeof i=="bigint"?`${i}n`:String(parseInt(i,10))}function ln(i){return typeof i=="symbol"?"NaN":String(parseFloat(i))}var vt={s:i=>V(i),d:i=>on(i),i:i=>cn(i),f:i=>ln(i),j:i=>V(i),o:i=>V(i),O:i=>V(i),c:()=>""};function re(...i){var e;let t=i.shift();if(h.String.is(t)){let n="",r=0;for(;r<t.length;){let s=t.charAt(r);if(s==="%"){if(r+1<t.length){let o=t.charAt(r+1);if(o in vt&&i.length){let c=i.shift();n+=(e=vt[o])==null?void 0:e.call(vt,c)}else o==="%"?n+="%":n+=`%${o}`;r+=2}}else n+=s,r+=1}return i.length&&(n.length&&(n+=" "),n+=i.map(V).join(" ")),n}return i.map(V).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 un=["debug","info","warn","error","none"],M=class i{static get(){return new i({})}constructor(t){var e,n,r;if(this.fi=(n=v[(e=t.level)!=null?e:"info"])!=null?n:v.info,this.gi=(r=t.name)!=null?r:"LaunchDarkly",this.pe=t.formatter,typeof t.destination=="object")this.me={[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:s}=t;this.me={[v.debug]:s,[v.info]:s,[v.warn]:s,[v.error]:s}}}pi(...t){var e;try{return this.pe?(e=this.pe)==null?void 0:e.call(this,...t):re(...t)}catch(n){return re(...t)}}mi(t,e){try{t(e)}catch(n){console.error(e)}}L(t,e){var n;if(t>=this.fi){let r=`${un[t]}: [${this.gi}]`;try{let s=(n=this.me)==null?void 0:n[t];s?this.mi(s,`${r} ${this.pi(...e)}`):console.error(...e)}catch(s){console.error(...e)}}}error(...t){this.L(v.error,t)}warn(...t){this.L(v.warn,t)}info(...t){this.L(v.info,t)}debug(...t){this.L(v.debug,t)}},hn={error:h.Function,warn:h.Function,info:h.Function,debug:h.Function},_=class{constructor(t,e){Object.entries(hn).forEach(([n,r])=>{if(!r.is(t[n]))throw new Error(`Provided logger instance must support logger.${n}(...) method`)}),this.t=t,this.yi=e}L(t,e){try{this.t[t](...e)}catch(n){this.yi[t](...e)}}error(...t){this.L("error",t)}warn(...t){this.L("warn",t)}info(...t){this.L("info",t)}debug(...t){this.L("debug",t)}},pe=i=>{let t=new M({level:"info",destination:console.error,formatter:re});return i?new _(i,t):t},b=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`}},dn=/^(\w|\.|-)+$/,fn=h.stringMatchingRegex(dn),gn={is:(i,t)=>fn.is(i)?i.length>64?{valid:!1,message:b.tagValueTooLong(t)}:{valid:!0}:{valid:!1,message:b.invalidTagValue(t)}},xt=class{constructor(t){let e={},n=t==null?void 0:t.application,r=t==null?void 0:t.logger;n&&Object.entries(n).forEach(([a,o])=>{if(o!=null){let{valid:c,message:l}=gn.is(o,`application.${a}`);c?a==="versionName"?e["application-version-name"]=[o]:e[`application-${a}`]=[o]:r==null||r.warn(l)}});let s=Object.keys(e);s.length&&(this.value=s.sort().flatMap(a=>e[a].sort().map(o=>`${a}/${o}`)).join(" "))}},Lt=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 Yt(i){return i.replace(/\/+$/,"")}function me(i){return i.replace(/^\/+/,"").replace(/\?$/,"")}var U=class i{constructor(t,e,n=i.DEFAULT_EVENTS,r="/bulk",s="/diagnostic",a=!0,o){this.streaming=Yt(t),this.polling=Yt(e),this.events=Yt(n),this.analyticsEventPath=r,this.diagnosticEventPath=s,this.includeAuthorizationHeader=a,this.payloadFilterKey=o}};U.DEFAULT_EVENTS="https://events.launchdarkly.com";function ye(i,t=[]){if(t.length===0)return i;let e=t.map(({key:n,value:r})=>`${n}=${r}`);return`${i}?${e.join("&")}`}function ii(i,t,e){let n=me(t),r=[...e];return i.payloadFilterKey&&r.push({key:"filter",value:i.payloadFilterKey}),ye(`${i.streaming}/${n}`,r)}function ni(i,t,e=[]){let n=me(t),r=[...e];return i.payloadFilterKey&&r.push({key:"filter",value:i.payloadFilterKey}),ye(`${i.polling}/${n}`,r)}function qe(i,t,e=[]){let n=me(t);return ye(`${i.events}/${n}`,e)}var J=class extends Error{constructor(t){super(t),this.name="LaunchDarklyUnexpectedResponseError"}},q=class extends Error{constructor(t){super(t),this.name="LaunchDarklyClientError"}},I=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 pn(i){return i===413?!0:Z(i)}function $t(i,t){let e,n;return{promise:new Promise((s,a)=>{n=s,e=setTimeout(()=>{let o=`${t} timed out after ${i} seconds.`;a(new I(o))},i*1e3)}),cancel:()=>{n(),clearTimeout(e)}}}function ve(i){return i==null?i:JSON.parse(JSON.stringify(i))}function Nt(i){return Math.trunc(i*1e3)}var mn=i=>JSON.stringify(i)==="{}",Ft=(i,t)=>i&&Object.entries(i).reduce((e,[n,r])=>(r&&!mn(r)&&!(t!=null&&t.includes(n))&&(e[n]=typeof r=="object"?Ft(r,t):r),e),{});function G(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,r;if(Array.isArray(i)){if(e=i.length,e!=t.length)return!1;for(n=e;n--!==0;)if(!G(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(!G(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(r=Object.keys(i),e=r.length,e!==Object.keys(t).length)return!1;for(n=e;n--!==0;)if(!Object.prototype.hasOwnProperty.call(t,r[n]))return!1;for(n=e;n--!==0;){var s=r[n];if(!G(i[s],t[s]))return!1}return!0}return i!==i&&t!==t}function ri(i,t,e,n=!0,r="user-agent"){let{userAgentBase:s,version:a,wrapperName:o,wrapperVersion:c}=t.sdkData(),l={[r]:`${s!=null?s:"NodeJSClient"}/${a}`};return n&&(l.authorization=i),o&&(l["x-launchdarkly-wrapper"]=c?`${o}/${c}`:o),e!=null&&e.value&&(l["x-launchdarkly-tags"]=e.value),l}function $(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 r=e!=null?e:"giving up permanently";return`Received ${n} for ${t} - ${r}`}function Rt({status:i}){return i?Z(i):!0}var we=(i,t)=>t.btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");var Ee=async(i=1e3)=>new Promise(t=>{setTimeout(t,i)});var se=class{constructor(t,e,n){this.p=e,this.vi=n,this.Pt=[],this.ye=Date.now(),this.ve=this.ye,this.we={diagnosticId:e.crypto.randomUUID(),sdkKeySuffix:t.length>6?t.substring(t.length-6):t}}createInitEvent(){var n,r,s;let t=this.p.info.sdkData(),e=this.p.info.platformData();return{kind:"diagnostic-init",id:this.we,creationDate:this.ye,sdk:t,configuration:this.vi,platform:g({name:e.name,osArch:(n=e.os)==null?void 0:n.arch,osName:(r=e.os)==null?void 0:r.name,osVersion:(s=e.os)==null?void 0:s.version},e.additional||{})}}recordStreamInit(t,e,n){let r={timestamp:t,failed:e,durationMillis:n};this.Pt.push(r)}createStatsEventAndReset(t,e,n){let r=Date.now(),s={kind:"diagnostic",id:this.we,creationDate:r,dataSinceDate:this.ve,droppedEvents:t,deduplicatedUsers:e,eventsInLastBatch:n,streamInits:this.Pt};return this.Pt=[],this.ve=r,s}},ae;(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"})(ae||(ae={}));var yn=ae,St=class{static invalidMetricValue(t){return`The track function was called with a non-numeric "metricValue" (${t}), only numeric metric values are supported.`}};St.MissingContextKeyNoEvent="Context was unspecified or had no key; event will not be sent";var oe=class{constructor(t,e){let{basicConfiguration:n,platform:r}=t,{serviceEndpoints:{analyticsEventPath:s,diagnosticEventPath:a}}=n,{crypto:o,requests:c}=r;this.wi=g({},e),this.Ee=qe(n.serviceEndpoints,s,[]),this.Ei=qe(n.serviceEndpoints,a,[]),this.$=c,this.Di=o}async ot(t,e,n,r){let s={status:F.Succeeded},a=D(g({},this.wi),{"content-type":"application/json"});n&&(a["x-launchdarkly-payload-id"]=n,a["x-launchDarkly-event-schema"]="4");let o;try{let{status:c,headers:l}=await this.$.fetch(e,{headers:a,body:JSON.stringify(t),compressBodyIfPossible:!0,method:"POST",keepalive:!0}),u=Date.parse(l.get("date")||"");if(u&&(s.serverTime=u),c<=204)return s;if(o=new J($({status:c,message:"some events were dropped"},"event posting")),!Z(c))return pn(c)?s.status=F.Failed:s.status=F.FailedAndMustShutDown,s.error=o,s}catch(c){o=c}return o&&!r?(s.status=F.Failed,s.error=o,s):(await Ee(),this.ot(t,this.Ee,n,!1))}async sendEventData(t,e){let n=t===H.AnalyticsEvents?this.Di.randomUUID():void 0,r=t===H.AnalyticsEvents?this.Ee:this.Ei;return this.ot(e,r,n,!0)}};function Ct(i){return i.kind==="feature"}function vn(i){return i.kind==="identify"}function wn(i){return i.kind==="migration_op"}var ce=class{constructor(t,e,n,r,s,a){this.count=t,this.key=e,this.value=n,this.version=s,this.variation=a,this.default=r}increment(){this.count+=1}};function En(i){return`${i.key}:${i.variation!==null&&i.variation!==void 0?i.variation:""}:${i.version!==null&&i.version!==void 0?i.version:""}`}var Pt=class{constructor(t=!1,e){this.bi=t,this.S=e,this.X=0,this.ct=0,this.lt={},this.ut={}}summarizeEvent(t){if(Ct(t)&&!t.excludeFromSummaries){this.v||(this.v=t.context);let e=En(t),n=this.lt[e],r=this.ut[t.key];r||(r=new Set,this.ut[t.key]=r),t.context.kinds.forEach(s=>r.add(s)),n?n.increment():this.lt[e]=new ce(1,t.key,t.value,t.default,t.version,t.variation),(this.X===0||t.creationDate<this.X)&&(this.X=t.creationDate),t.creationDate>this.ct&&(this.ct=t.creationDate)}}getSummary(){var n;let t=Object.values(this.lt).reduce((r,s)=>{let a=r[s.key];a||(a={default:s.default,counters:[],contextKinds:[...this.ut[s.key]]},r[s.key]=a);let o={value:s.value,count:s.count};return s.variation!==void 0&&s.variation!==null&&(o.variation=s.variation),s.version!==void 0&&s.version!==null?o.version=s.version:o.unknown=!0,a.counters.push(o),r},{}),e={startDate:this.X,endDate:this.ct,features:t,kind:"summary",context:this.v!==void 0&&this.bi?(n=this.S)==null?void 0:n.filter(this.v):void 0};return this.ki(),e}ki(){this.X=0,this.ct=0,this.lt={},this.ut={}}},le=class extends Error{constructor(t){super(t),this.name="LaunchDarklyInvalidSDKKeyError"}},ue=class{constructor(t,e){this.S=t,this.t=e,this.Q={}}summarizeEvent(t){var e;if(Ct(t)){let n=t.context.canonicalUnfilteredJson();if(!n){t.context.valid&&((e=this.t)==null||e.error("Unable to serialize context, likely the context contains a cycle."));return}let r=this.Q[n];r||(this.Q[n]=new Pt(!0,this.S),r=this.Q[n]),r.summarizeEvent(t)}}getSummaries(){let t=this.Q;return this.Q={},Object.values(t).map(e=>e.getSummary())}};function wt(i){let t=Math.trunc(i);return t===1?!0:t===0?!1:Math.floor(Math.random()*t)===0}function Dn(i){return i.getSummaries!==void 0}var he=class{constructor(t,e,n,r,s,a=!0,o=!1){this.r=t,this.ht=r,this.C=s,this.dt=[],this.De=0,this.It=0,this.Tt=0,this.At=!1,this.be=0,this.Ot=!1,this.$t=null,this.xi=t.eventsCapacity,this.t=e.basicConfiguration.logger,this.ke=new oe(e,n),this.S=new ne(t.allAttributesPrivate,t.privateAttributes.map(c=>new A(c))),o?this.tt=new ue(this.S,this.t):this.tt=new Pt,a&&this.start()}start(){var t,e;if(((t=this.ht)==null?void 0:t.flushInterval)!==void 0&&(this.$t=setInterval(()=>{var n;(n=this.ht)==null||n.flush()},this.ht.flushInterval*1e3)),this.Li=setInterval(async()=>{var n;try{await this.flush()}catch(r){(n=this.t)==null||n.debug(`Flush failed: ${r}`)}},this.r.flushInterval*1e3),this.C){let n=this.C.createInitEvent();this.xe(n),this.Le=setInterval(()=>{let r=this.C.createStatsEventAndReset(this.It,this.Tt,this.be);this.It=0,this.Tt=0,this.xe(r)},this.r.diagnosticRecordingInterval*1e3)}(e=this.t)==null||e.debug("Started EventProcessor.")}xe(t){this.ke.sendEventData(H.DiagnosticEvent,t)}close(){clearInterval(this.Li),this.$t&&clearInterval(this.$t),this.Le&&clearInterval(this.Le)}async flush(){var e;if(this.Ot)throw new le("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.dt;if(this.dt=[],Dn(this.tt))this.tt.getSummaries().forEach(r=>{Object.keys(r.features).length&&t.push(r)});else{let n=this.tt.getSummary();Object.keys(n.features).length&&t.push(n)}t.length&&(this.be=t.length,(e=this.t)==null||e.debug("Flushing %d events",t.length),await this.ot(t))}sendEvent(t){var c;if(this.Ot)return;if(wn(t)){if(wt(t.samplingRatio)){let l=D(g({},t),{context:t.context?this.S.filter(t.context):void 0});l.samplingRatio===1&&delete l.samplingRatio,this.ft(l)}return}this.tt.summarizeEvent(t);let e=Ct(t),n=e&&t.trackEvents||!e,r=this.Si(t),s=vn(t),a=(c=this.ht)==null?void 0:c.processContext(t.context);a||s||(this.Tt+=1),a&&!s&&this.ft(this.Nt({kind:"index",creationDate:t.creationDate,context:t.context,samplingRatio:1},!1)),n&&wt(t.samplingRatio)&&this.ft(this.Nt(t,!1)),r&&wt(t.samplingRatio)&&this.ft(this.Nt(t,!0))}Nt(t,e){switch(t.kind){case"feature":{let n={kind:e?"debug":"feature",creationDate:t.creationDate,context:this.S.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.S.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.S.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}}ft(t){var e;this.dt.length<this.xi?(this.dt.push(t),this.At=!1):(this.At||(this.At=!0,(e=this.t)==null||e.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")),this.It+=1)}Si(t){return Ct(t)&&t.debugEventsUntilDate&&t.debugEventsUntilDate>this.De&&t.debugEventsUntilDate>Date.now()}async ot(t){let e=await this.ke.sendEventData(H.AnalyticsEvents,t);if(e.status===F.FailedAndMustShutDown&&(this.Ot=!0),e.serverTime&&(this.De=e.serverTime),e.error)throw e.error}},It=class{constructor(t,e,n,r,s=1,a){this.context=t,this.key=e,this.data=n,this.metricValue=r,this.samplingRatio=s,this.url=a,this.kind="custom",this.creationDate=Date.now(),this.context=t}},Y=class{constructor(t,e,n,r,s,a,o,c,l,u,d,f,m=1){this.withReasons=t,this.context=e,this.key=n,this.samplingRatio=m,this.kind="feature",this.creationDate=Date.now(),this.value=r,this.default=s,a!==void 0&&(this.version=a),o!==void 0&&(this.variation=o),c!==void 0&&(this.trackEvents=c),l!==void 0&&(this.prereqOf=l),u!==void 0&&(this.reason=u),d!==void 0&&(this.debugEventsUntilDate=d),f!==void 0&&(this.excludeFromSummaries=f)}},Tt=class{constructor(t,e=1){this.context=t,this.samplingRatio=e,this.kind="identify",this.creationDate=Date.now()}},de=class{close(){}async flush(){}sendEvent(){}},fe=class{constructor(t){this.Ft=t}evalEvent(t){var e;return new Y(this.Ft,t.context,t.flagKey,t.value,t.defaultVal,t.version,(e=t.variation)!=null?e:void 0,t.trackEvents||t.addExperimentData,t.prereqOfFlagKey,this.Ft||t.addExperimentData?t.reason:void 0,t.debugEventsUntilDate,t.excludeFromSummaries,t.samplingRatio)}unknownFlagEvent(t,e,n){return new Y(this.Ft,n,t,e,e,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0)}identifyEvent(t){return new Tt(t,1)}customEvent(t,e,n,r,s=1){return new It(e,t,n!=null?n:void 0,r!=null?r:void 0,s)}},Ye="FDv1Fallback";function bn(i){return{Ci:i,Se:"",useSelector(t){return this.Se=t,this},processFullTransfer(t){let e=[{event:"server-intent",data:{payloads:[{id:Ye,target:1,intentCode:"xfer-full",reason:"payload-missing"}]}}];Object.entries((t==null?void 0:t.flags)||[]).forEach(([n,r])=>{e.push({event:"put-object",data:{kind:"flag",key:n,version:r.version||1,object:r}})}),Object.entries((t==null?void 0:t.segments)||[]).forEach(([n,r])=>{e.push({event:"put-object",data:{kind:"segment",key:n,version:r.version||1,object:r}})}),e.push({event:"payload-transferred",data:{state:this.Se,version:1,id:Ye}}),this.Ci.processEvents(e)}}}var At=class{constructor(t,e,n){this.Pi=t,this.y=e,this.t=n,this.e=[],this.U=void 0,this.K=!1,this.G=[],this.Ii=r=>{var a;if(this.Rt(),!r.payloads.length)return;let s=r.payloads[0];switch(s==null?void 0:s.intentCode){case"xfer-full":this.K=!0;break;case"xfer-changes":this.K=!1;break;case"none":this.K=!1,this.Ti(s);break;default:(a=this.t)==null||a.warn(`Unable to process intent code '${s==null?void 0:s.intentCode}'.`);return}this.U=s==null?void 0:s.id},this.Ai=r=>{var a;if(!this.U||!r.kind||!r.key||!r.version||!r.object)return;let s=this.Oi(r.kind,r.object);if(!s){(a=this.t)==null||a.warn(`Unable to process object for kind: '${r.kind}'`);return}this.G.push({kind:r.kind,key:r.key,version:r.version,object:s})},this.$i=r=>{!this.U||!r.kind||!r.key||!r.version||this.G.push({kind:r.kind,key:r.key,version:r.version,deleted:!0})},this.Ti=r=>{if(!r.id||!r.target)return;let s={id:r.id,version:r.target,basis:!1,updates:[]};this.e.forEach(a=>a(s)),this.Ce()},this.Ni=r=>{if(!this.U||r.state===null||r.state===void 0||!r.version){this.Rt();return}let s={id:this.U,version:r.version,state:r.state,basis:this.K,updates:this.G};this.e.forEach(a=>a(s)),this.Ce()},this.Fi=r=>{var s;(s=this.t)==null||s.info(`Goodbye was received from the LaunchDarkly connection with reason: ${r.reason}.`),this.Rt()},this.Ri=r=>{var s;(s=this.t)==null||s.info(`An issue was encountered receiving updates for payload ${this.U} with reason: ${r.reason}.`),this.Mi()}}addPayloadListener(t){this.e.push(t)}removePayloadListener(t){let e=this.e.indexOf(t,0);e>-1&&this.e.splice(e,1)}processEvents(t){t.forEach(e=>{switch(e.event){case"server-intent":{this.Ii(e.data);break}case"put-object":{this.Ai(e.data);break}case"delete-object":{this.$i(e.data);break}case"payload-transferred":{this.Ni(e.data);break}case"goodbye":{this.Fi(e.data);break}case"error":{this.Ri(e.data);break}}})}Oi(t,e){var n,r;return(r=(n=this.Pi)[t])==null?void 0:r.call(n,e)}Ce(){this.K=!1,this.G=[]}Mi(){this.G=[]}Rt(){this.U=void 0,this.K=!1,this.G=[]}},ge=class{constructor(t,e,n,r){this.y=n,this.t=r,this.W(t,"server-intent"),this.W(t,"put-object"),this.W(t,"delete-object"),this.W(t,"payload-transferred"),this.W(t,"goodbye"),this.W(t,"error"),this.Mt=new At(e,n,r)}addPayloadListener(t){this.Mt.addPayloadListener(t)}removePayloadListener(t){this.Mt.removePayloadListener(t)}W(t,e){t.addEventListener(e,async n=>{var r,s,a,o,c;if(n!=null&&n.data){(r=this.t)==null||r.debug(`Received ${e} event. Data is ${n.data}`);try{this.Mt.processEvents([{event:e,data:JSON.parse(n.data)}])}catch(l){(s=this.t)==null||s.error(`Stream received data that was unable to be processed in "${e}" message`),(a=this.t)==null||a.debug(`Data follows: ${n.data}`),(o=this.y)==null||o.call(this,w.InvalidData,"Malformed data in EventStream.")}}else(c=this.y)==null||c.call(this,w.Unknown,"Event from EventStream missing data.")})}};function kn(i){if(i){let t=Object.keys(i).find(e=>e.toLowerCase()==="x-ld-envid");if(t)return{environmentId:i[t]}}}var Ze="unknown plugin";function Ot(i,t){try{return t.getMetadata().name||Ze}catch(e){return i.error("Exception thrown getting metadata for plugin. Unable to get plugin name."),Ze}}function xn(i,t,e){let n=[];return e.forEach(r=>{var s;try{let a=(s=r.getHooks)==null?void 0:s.call(r,t);a===void 0?i.error(`Plugin ${Ot(i,r)} returned undefined from getHooks.`):a&&a.length>0&&n.push(...a)}catch(a){i.error(`Exception thrown getting hooks for plugin ${Ot(i,r)}. Unable to get hooks.`)}}),n}function Ln(i,t,e,n){n.forEach(r=>{try{r.register(e,t)}catch(s){i.error(`Exception thrown registering plugin ${Ot(i,r)}.`)}})}var k=Object.freeze({__proto__:null,ClientMessages:St,DiagnosticsManager:se,ErrorKinds:yn,EventFactoryBase:fe,EventProcessor:he,FDv1PayloadAdaptor:bn,InputCustomEvent:It,InputEvalEvent:Y,InputIdentifyEvent:Tt,NullEventProcessor:de,PayloadProcessor:At,PayloadStreamReader:ge,canonicalize:bt,initMetadataFromHeaders:kn,isLegacyUser:ei,isMultiKind:ti,isSingleKind:Qe,safeGetHooks:xn,safeGetName:Ot,safeRegisterPlugins:Ln,shouldSample:wt});var E;(function(i){i.Initializing="INITIALIZING",i.Valid="VALID",i.Interrupted="INTERRUPTED",i.SetOffline="SET_OFFLINE",i.Closed="CLOSED"})(E||(E={}));function Cn(i){return i>=200&&i<=299}var Mt=class extends Error{constructor(t,e){super(t),this.status=e,this.name="LaunchDarklyRequestError"}},be=class{constructor(t,e,n,r,s){this.$=t,this.Ui=e,this.gt=n,this.Vi=r,this.ji=s}async requestPayload(){let t;try{let e=await this.$.fetch(this.Ui,{method:this.Vi,headers:this.gt,body:this.ji});if(Cn(e.status))return await e.text();t=e.status}catch(e){throw new Mt(e==null?void 0:e.message)}throw new Mt(`Unexpected status code: ${t}`,t)}};function $e(i,t,e,n,r,s,a,o,c,l){let u,d="GET",f=g({},s);c&&(d="REPORT",f["content-type"]="application/json",u=i);let m=c?e.pathReport(r,i):e.pathGet(r,i),p=[...a!=null?a:[]];o&&p.push({key:"withReasons",value:"true"}),l&&p.push({key:"h",value:l});let y=ni(t,m,p);return new be(n,y,f,d,u)}var si=new Error("Task has already been executed or shed. This is likely an implementation error. The task will not be executed again.");function Pn(i,t,e=!1){let n,r=new Promise(o=>{n=(c,l)=>{var u;try{(u=i.after)==null||u.call(i,c,l)}catch(d){t==null||t.error(`Error in after callback: ${d}`)}o(c)}}),s=i.before?i.before():Promise.resolve(void 0),a=!1;return{execute:()=>{a&&(t==null||t.error(si)),a=!0,s.then(o=>{i.execute(o).then(c=>n({status:"complete",result:c},o)).catch(c=>n({status:"error",error:c},o))}).catch(o=>{t==null||t.error(o),n({status:"error",error:o},void 0)})},shed:()=>{a&&(t==null||t.error(si)),a=!0,s.then(o=>{n({status:"shed"},o)})},promise:r,sheddable:e}}function In(i){let t,e=[];function n(){if(!t&&e.length>0){let r=e.shift();t=r.promise.finally(()=>{t=void 0,n()}),r.execute()}}return{execute(r,s=!1){var o,c;let a=Pn(r,i,s);return t?((o=e[e.length-1])!=null&&o.sheddable&&((c=e.pop())==null||c.shed()),e.push(a)):(t=a.promise.finally(()=>{t=void 0,n()}),a.execute()),a.promise},pendingCount(){return e.length}}}var Tn={logger:h.Object,maxCachedContexts:h.numberWithMin(0),baseUri:h.String,streamUri:h.String,eventsUri:h.String,capacity:h.numberWithMin(1),diagnosticRecordingInterval:h.numberWithMin(2),flushInterval:h.numberWithMin(2),streamInitialReconnectDelay:h.numberWithMin(0),allAttributesPrivate:h.Boolean,debug:h.Boolean,diagnosticOptOut:h.Boolean,withReasons:h.Boolean,sendEvents:h.Boolean,pollInterval:h.numberWithMin(30),useReport:h.Boolean,privateAttributes:h.StringArray,applicationInfo:h.Object,wrapperName:h.String,wrapperVersion:h.String,payloadFilterKey:h.stringMatchingRegex(/^[a-zA-Z0-9](\w|\.|-)*$/),hooks:h.createTypeArray("Hook[]",{}),inspectors:h.createTypeArray("LDInspection",{}),cleanOldPersistentData:h.Boolean},An=300,pi="https://clientsdk.launchdarkly.com",mi="https://clientstream.launchdarkly.com";function On(i){return i instanceof _?i:pe(i)}var ke=class{constructor(t={},e={getImplementationHooks:()=>[],credentialType:"mobileKey"}){var r,s,a;this.logger=pe(),this.baseUri=pi,this.eventsUri=U.DEFAULT_EVENTS,this.streamUri=mi,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=An,this.hooks=[],this.inspectors=[],this.logger=On(t.logger),this.zi(t).forEach(o=>this.logger.warn(o)),this.serviceEndpoints=new U(this.streamUri,this.baseUri,this.eventsUri,e.analyticsEventPath,e.diagnosticEventPath,e.includeAuthorizationHeader,t.payloadFilterKey),this.useReport=(r=t.useReport)!=null?r:!1,this.tags=new xt({application:this.applicationInfo,logger:this.logger}),this.userAgentHeaderName=(s=e.userAgentHeaderName)!=null?s:"user-agent",this.trackEventModifier=(a=e.trackEventModifier)!=null?a:(o=>o),this.credentialType=e.credentialType,this.getImplementationHooks=e.getImplementationHooks}zi(t){let e=[];return Object.entries(t).forEach(([n,r])=>{let s=Tn[n];if(s)if(s.is(r))n==="logger"||(this[n]=r!=null?r:void 0);else{let a=s.getType();if(a==="boolean")e.push(b.wrongOptionTypeBoolean(n,typeof r)),this[n]=!!r;else if(a==="boolean | undefined | null")e.push(b.wrongOptionTypeBoolean(n,typeof r)),typeof r!="boolean"&&typeof r!="undefined"&&r!==null&&(this[n]=!!r);else if(s instanceof W&&h.Number.is(r)){let{min:o}=s;e.push(b.optionBelowMinimum(n,r,o)),this[n]=o}else e.push(b.wrongOptionType(n,s.getType(),typeof r))}else e.push(b.unknownOption(n))}),e}};async function yi(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 vi=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 wi(i){return async t=>yi(i.createHash("sha256").update(t),"base64")}var C=async i=>i;async function Q(i){return(await Promise.all(i.map(e=>e.transform(e.value)))).join("_")}async function $n(i,t){return Q([{value:"LaunchDarkly",transform:C},{value:t,transform:wi(i)}])}async function Nn(i){return Q([{value:"LaunchDarkly",transform:C},{value:"AnonymousKeys",transform:C},{value:i,transform:C}])}async function Fn(i){return Q([{value:"LaunchDarkly",transform:C},{value:"ContextKeys",transform:C},{value:i,transform:C}])}async function Rn(i){return Q([{value:i,transform:C},{value:"ContextIndex",transform:C}])}async function ai(i,t,e){return Q([{value:t,transform:C},{value:e.canonicalKey,transform:wi(i)}])}var{isLegacyUser:Mn,isSingleKind:De,isMultiKind:oi}=k,Ei="1.0",Un=i=>{let n=i,{kind:t}=n,e=Jt(n,["kind"]);return{kind:"multi",[t]:e}},Vn=async({crypto:i,info:t},{applicationInfo:e})=>{var a;let{ld_application:n}=t.platformData(),r=(a=Ft(n))!=null?a:{},s=(e==null?void 0:e.id)||(r==null?void 0:r.id);if(s){let o=(e==null?void 0:e.version)||(r==null?void 0:r.version),c=(e==null?void 0:e.name)||(r==null?void 0:r.name),l=(e==null?void 0:e.versionName)||(r==null?void 0:r.versionName);return r=g(g(g(D(g({},r),{id:s}),o?{version:o}:{}),c?{name:c}:{}),l?{versionName:l}:{}),r.key=await yi(i.createHash("sha256").update(s),"base64"),r.envAttributesVersion=r.envAttributesVersion||Ei,r}},jn=async i=>{var o,c,l,u;let{ld_device:t,os:e}=i.info.platformData(),n=(o=Ft(t))!=null?o:{},r=(e==null?void 0:e.name)||((c=n.os)==null?void 0:c.name),s=(e==null?void 0:e.version)||((l=n.os)==null?void 0:l.version),a=(u=n.os)==null?void 0:u.family;if((r||s||a)&&(n.os=g(g(g({},r?{name:r}:{}),s?{version:s}:{}),a?{family:a}:{})),Object.keys(n).filter(d=>d!=="key"&&d!=="envAttributesVersion").length){let d=await Fn("ld_device");return n.key=await vi(d,i),n.envAttributesVersion=n.envAttributesVersion||Ei,n}},zn=async(i,t,e)=>{if(Mn(i))return i;let n,r;if(De(i)&&i.kind!=="ld_application"||oi(i)&&!i.ld_application?n=await Vn(t,e):e.logger.warn("Not adding ld_application environment attributes because it already exists."),De(i)&&i.kind!=="ld_device"||oi(i)&&!i.ld_device?r=await jn(t):e.logger.warn("Not adding ld_device environment attributes because it already exists."),n||r){let s=De(i)?Un(i):i;return g(g(g({},s),n?{ld_application:n}:{}),r?{ld_device:r}:{})}return i};function Hn(){let i,t;return{set(e,n){i=e,t=n},getContext(){return t},getUnwrappedContext(){return i},newIdentificationPromise(){let e,n;return{identifyPromise:new Promise((s,a)=>{e=s,n=a}),identifyResolve:e,identifyReject:n}},hasContext(){return t!==void 0},hasValidContext(){return this.hasContext()&&t.valid}}}var{isLegacyUser:Bn,isMultiKind:Kn,isSingleKind:Gn}=k,Ne=async(i,t,e)=>{let{anonymous:n,key:r}=t;if(n&&!r){let s=await Nn(i);t.key=await vi(s,e)}},Wn=async(i,t)=>{await Ne(i.kind,i,t)},_n=async(i,t)=>{let r=i,{kind:e}=r,n=Jt(r,["kind"]);return Promise.all(Object.entries(n).map(([s,a])=>Ne(s,a,t)))},Jn=async(i,t)=>{await Ne("user",i,t)},qn=async(i,t)=>{let e=ve(i);return Gn(e)&&await Wn(e,t),Kn(e)&&await _n(e,t),Bn(e)&&await Jn(e,t),e},Yn=i=>({customBaseURI:i.serviceEndpoints.polling!==pi,customStreamURI:i.serviceEndpoints.streaming!==mi,customEventsURI:i.serviceEndpoints.events!==U.DEFAULT_EVENTS,eventsCapacity:i.capacity,eventsFlushIntervalMillis:Nt(i.flushInterval),reconnectTimeMillis:Nt(i.streamInitialReconnectDelay),diagnosticRecordingIntervalMillis:Nt(i.diagnosticRecordingInterval),allAttributesPrivate:i.allAttributesPrivate,usingSecureMode:!1,bootstrapMode:!1}),Zn=(i,t,e)=>{if(t.sendEvents&&!t.diagnosticOptOut)return new k.DiagnosticsManager(i,e,Yn(t))};function ci(i,t){return{value:t!=null?t:null,variationIndex:null,reason:{kind:"ERROR",errorKind:i}}}function li(i,t,e){return{value:i,variationIndex:t!=null?t:null,reason:e!=null?e:null}}var Xn=(i,t,e,n,r)=>{if(t.sendEvents)return new k.EventProcessor(D(g({},t),{eventsCapacity:t.capacity}),new Lt(i,t,e),n,void 0,r,!1,!0)},Ut=class extends k.EventFactoryBase{evalEventClient(t,e,n,r,s,a){let{trackEvents:o,debugEventsUntilDate:c,trackReason:l,flagVersion:u,version:d,variation:f}=r;return super.evalEvent({addExperimentData:l,context:s,debugEventsUntilDate:c,defaultVal:n,flagKey:t,reason:a,trackEvents:!!o,value:e,variation:f,version:u!=null?u:d})}},X=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(r=>r.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,r)=>n.timestamp-r.timestamp),this.container.index.splice(0,this.container.index.length-e)):[]}},xe=class{constructor(t,e,n,r,s,a,o=()=>Date.now()){this.p=t,this.Ut=e,this.Hi=n,this.N=r,this.E=s,this.t=a,this.pt=o,this.Pe=Rn(this.Ut)}async init(t,e){this.E.init(t,e),await this.Ie(t)}async upsert(t,e,n){return this.E.upsert(t,e,n)?(await this.Ie(t),!0):!1}async loadCached(t){var r,s,a,o;let e=await ai(this.p.crypto,this.Ut,t),n=await((r=this.p.storage)==null?void 0:r.get(e));if(n==null){if(n=await((s=this.p.storage)==null?void 0:s.get(t.canonicalKey)),n==null)return!1;await((a=this.p.storage)==null?void 0:a.set(e,n)),await((o=this.p.storage)==null?void 0:o.clear(t.canonicalKey))}try{let c=JSON.parse(n),l=Object.entries(c).reduce((u,[d,f])=>(u[d]={version:f.version,flag:f},u),{});return this.E.initCached(t,l),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 Bi(){var e;if(this._!==void 0)return this._;let t=await((e=this.p.storage)==null?void 0:e.get(await this.Pe));if(!t)return this._=new X,this._;try{this._=X.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._=new X}return this._}async Ie(t){var c,l;let e=await this.Bi(),n=await ai(this.p.crypto,this.Ut,t);e.notice(n,this.pt());let r=e.prune(this.Hi);await Promise.all(r.map(async u=>{var d;return(d=this.p.storage)==null?void 0:d.clear(u.id)})),await((c=this.p.storage)==null?void 0:c.set(await this.Pe,e.toJson()));let s=this.N.getAll(),a=Object.entries(s).reduce((u,[d,f])=>(f.flag!==null&&f.flag!==void 0&&(u[d]=f.flag),u),{}),o=JSON.stringify(a);await((l=this.p.storage)==null?void 0:l.set(n,o))}};function Qn(){let i={};return{init(t){i=Object.entries(t).reduce((e,[n,r])=>(e[n]=r,e),{})},insertOrUpdate(t,e){i[t]=e},get(t){if(Object.prototype.hasOwnProperty.call(i,t))return i[t]},getAll(){return i}}}function tr(i,t){let e=[];return Object.entries(i).forEach(([n,r])=>{let s=t[n];(!s||!G(r,s))&&e.push(n)}),Object.keys(t).forEach(n=>{i[n]||e.push(n)}),e}function er(i,t){let e=i,n=t,r,s=new Array;return{handleFlagChanges(a,o){r?s.forEach(c=>{try{c(r,a,o)}catch(l){}}):n.warn("Received a change event without an active context. Changes will not be propagated.")},init(a,o){r=a;let c=e.getAll();e.init(o);let l=tr(c,o);l.length>0&&this.handleFlagChanges(l,"init")},initCached(a,o){(r==null?void 0:r.canonicalKey)!==a.canonicalKey&&this.init(a,o)},upsert(a,o,c){if((r==null?void 0:r.canonicalKey)!==a.canonicalKey)return n.warn("Received an update for an inactive context."),!1;let l=e.get(o);return l!==void 0&&l.version>=c.version?!1:(e.insertOrUpdate(o,c),this.handleFlagChanges([o],"patch"),!0)},on(a){s.push(a)},off(a){let o=s.indexOf(a);o>-1&&s.splice(o,1)}}}var Le=class{constructor(t,e,n,r,s=()=>Date.now()){this.N=Qn(),this.E=er(this.N,r),this.Vt=this.Ki(t,e,n,r,s)}async Ki(t,e,n,r,s=()=>Date.now()){let a=await $n(t.crypto,e);return new xe(t,a,n,this.N,this.E,r,s)}get(t){return this.a&&Object.prototype.hasOwnProperty.call(this.a,t)?this.jt(this.a[t]):this.N.get(t)}getAll(){return this.a?g(g({},this.N.getAll()),Object.entries(this.a).reduce((t,[e,n])=>(t[e]=this.jt(n),t),{})):this.N.getAll()}presetFlags(t){this.N.init(t)}setBootstrap(t,e){this.E.init(t,e)}async init(t,e){return(await this.Vt).init(t,e)}async upsert(t,e,n){return(await this.Vt).upsert(t,e,n)}async loadCached(t){return(await this.Vt).loadCached(t)}on(t){this.E.on(t)}off(t){this.E.off(t)}jt(t){return{flag:{value:t,version:0},version:0}}setOverride(t,e){this.a||(this.a={}),this.a[t]=e,this.E.handleFlagChanges([t],"override")}removeOverride(t){!this.a||!Object.prototype.hasOwnProperty.call(this.a,t)||(delete this.a[t],Object.keys(this.a).length===0&&(this.a=void 0),this.E.handleFlagChanges([t],"override"))}clearAllOverrides(){if(this.a){let t=g({},this.a);this.a=void 0,this.E.handleFlagChanges(Object.keys(t),"override")}}getAllOverrides(){if(!this.a)return{};let t={};return Object.entries(this.a).forEach(([e,n])=>{t[e]=this.jt(n)}),t}getDebugOverride(){return{setOverride:this.setOverride.bind(this),removeOverride:this.removeOverride.bind(this),clearAllOverrides:this.clearAllOverrides.bind(this),getAllOverrides:this.getAllOverrides.bind(this)}}},ui="unknown hook",Di="beforeEvaluation",bi="afterEvaluation",ir="afterTrack";function tt(i,t,e,n,r){try{return n()}catch(s){return i==null||i.error(`An error was encountered in "${t}" of the "${e}" hook: ${s}`),r}}function et(i,t){try{return t.getMetadata().name||ui}catch(e){return i.error("Exception thrown getting metadata for hook. Unable to get hook name."),ui}}function nr(i,t,e){return t.map(n=>tt(i,Di,et(i,n),()=>{var r,s;return(s=(r=n==null?void 0:n.beforeEvaluation)==null?void 0:r.call(n,e,{}))!=null?s:{}},{}))}function rr(i,t,e,n,r){for(let s=t.length-1;s>=0;s-=1){let a=t[s],o=n[s];tt(i,bi,et(i,a),()=>{var c,l;return(l=(c=a==null?void 0:a.afterEvaluation)==null?void 0:c.call(a,e,o,r))!=null?l:{}},{})}}function sr(i,t,e){return t.map(n=>tt(i,Di,et(i,n),()=>{var r,s;return(s=(r=n==null?void 0:n.beforeIdentify)==null?void 0:r.call(n,e,{}))!=null?s:{}},{}))}function ar(i,t,e,n,r){for(let s=t.length-1;s>=0;s-=1){let a=t[s],o=n[s];tt(i,bi,et(i,a),()=>{var c,l;return(l=(c=a==null?void 0:a.afterIdentify)==null?void 0:c.call(a,e,o,r))!=null?l:{}},{})}}function or(i,t,e){for(let n=t.length-1;n>=0;n-=1){let r=t[n];tt(i,ir,et(i,r),()=>{var s;return(s=r==null?void 0:r.afterTrack)==null?void 0:s.call(r,e)},void 0)}}var Se=class{constructor(t,e){this.t=t,this.V=[],this.V.push(...e)}withEvaluation(t,e,n,r){if(this.V.length===0)return r();let s=[...this.V],a={flagKey:t,context:e,defaultValue:n},o=nr(this.t,s,a),c=r();return rr(this.t,s,a,o,c),c}identify(t,e){let n=[...this.V],r={context:t,timeout:e},s=sr(this.t,n,r);return a=>{ar(this.t,n,r,s,a)}}addHook(t){this.V.push(t)}afterTrack(t){if(this.V.length===0)return;let e=[...this.V];or(this.t,e,t)}};function cr(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 lr(i,t){return`an inspector: "${t}" of an invalid type (${i}) was configured`}function ur(i,t){return`an inspector: "${t}" of type: "${i}" generated an exception`}function hr(i,t){let e=!1,n={method:(...r)=>{try{i.method(...r)}catch(s){e||(e=!0,t.warn(ur(n.type,n.name)))}},type:i.type,name:i.name,synchronous:i.synchronous};return n}var ki="flag-used",xi="flag-details-changed",Li="flag-detail-changed",Si="client-identity-changed",dr=[ki,xi,Li,Si];function fr(i,t){let e=dr.includes(i.type)&&i.method&&typeof i.method=="function";return e||t.warn(lr(i.type,i.name)),e}var Ce=class{constructor(t,e){this.J=[];let n=t.filter(r=>fr(r,e));this.J=n.map(r=>hr(r,e))}hasInspectors(){return this.J.length!==0}onFlagUsed(t,e,n){this.J.forEach(r=>{r.type===ki&&r.method(t,e,n)})}onFlagsChanged(t){this.J.forEach(e=>{e.type===xi&&e.method(t)})}onFlagChanged(t,e){this.J.forEach(n=>{n.type===Li&&n.method(t,e)})}onIdentityChanged(t){this.J.forEach(e=>{e.type===Si&&e.method(t)})}},Pe=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 r=n.filter(s=>s!==e);r.length===0?this.e.delete(t):this.e.set(t,r);return}this.e.delete(t)}}zt(t,e,...n){var r;try{t(...n)}catch(s){(r=this.t)==null||r.error(`Encountered error invoking handler for "${e}", detail: "${s}"`)}}emit(t,...e){let n=this.e.get(t);n==null||n.forEach(r=>this.zt(r,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}};function gr(i,t,e){let n=t.info.sdkData(),r;e.applicationInfo&&(e.applicationInfo.id&&(r=r!=null?r:{},r.id=e.applicationInfo.id),e.applicationInfo.version&&(r=r!=null?r:{},r.version=e.applicationInfo.version),e.applicationInfo.name&&(r=r!=null?r:{},r.name=e.applicationInfo.name),e.applicationInfo.versionName&&(r=r!=null?r:{},r.versionName=e.applicationInfo.versionName));let s={name:n.userAgentBase,version:n.version};n.wrapperName&&(s.wrapperName=n.wrapperName),n.wrapperVersion&&(s.wrapperVersion=n.wrapperVersion);let a={sdk:s,[e.credentialType]:i};return r&&(a.application=r),a}var{ClientMessages:hi,ErrorKinds:di}=k,pr=5,Vt=class{constructor(t,e,n,r,s,a){if(this.sdkKey=t,this.autoEnvAttributes=e,this.platform=n,this.l=Hn(),this.Ht=15,this.F=new Ut(!1),this.mt=new Ut(!0),this.Bt=!1,this.Gi=In(),!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.r=new ke(r,a),this.logger=this.r.logger,this.Te=ri(this.sdkKey,this.platform.info,this.r.tags,this.r.serviceEndpoints.includeAuthorizationHeader,this.r.userAgentHeaderName),this.D=new Le(this.platform,t,this.r.maxCachedContexts,this.r.logger),this.C=Zn(t,this.r,n),this.b=Xn(t,this.r,n,this.Te,this.C),this.emitter=new Pe,this.emitter.on("error",(c,l)=>{this.logger.error(`error: ${l}, context: ${JSON.stringify(c)}`)}),this.D.on((c,l,u)=>{this.Wi(l,u);let d=S.toLDContext(c);this.emitter.emit("change",d,l),l.forEach(f=>{this.emitter.emit(`change:${f}`,d)})}),this.dataManager=s(this.D,this.r,this.Te,this.emitter,this.C);let o=[...this.r.hooks];if(this.environmentMetadata=gr(this.sdkKey,this.platform,this.r),this.r.getImplementationHooks(this.environmentMetadata).forEach(c=>{o.push(c)}),this.z=new Se(this.logger,o),this.et=new Ce(this.r.inspectors,this.logger),this.et.hasInspectors()&&this.z.addHook(cr(this.et)),r.cleanOldPersistentData&&(a!=null&&a.getLegacyStorageKeys)&&this.platform.storage)try{this.logger.debug("Cleaning old persistent data."),Promise.all(a.getLegacyStorageKeys().map(c=>{var l;return(l=this.platform.storage)==null?void 0:l.clear(c)})).catch(c=>{this.logger.error(`Error cleaning old persistent data: ${c}`)}).finally(()=>{this.logger.debug("Cleaned old persistent data.")})}catch(c){this.logger.error(`Error cleaning old persistent data: ${c}`)}}allFlags(){return Object.entries(this.D.getAll()).reduce((e,[n,r])=>(r.flag!==null&&r.flag!==void 0&&!r.flag.deleted&&(e[n]=r.flag.value),e),{})}async close(){var t;await this.flush(),(t=this.b)==null||t.close(),this.dataManager.close(),this.logger.debug("Closed event processor and data source.")}async flush(){var t;try{await((t=this.b)==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.l.hasContext()?ve(this.l.getUnwrappedContext()):void 0}getInternalContext(){return this.l.getContext()}presetFlags(t){this.D.presetFlags(t)}async identify(t,e){let n=await this.identifyResult(t,e);if(n.status==="error")throw n.error;if(n.status==="timeout"){let r=new I(`identify timed out after ${n.timeout} seconds.`);throw this.logger.error(r.message),r}}async identifyResult(t,e){var o,c;let n=(o=e==null?void 0:e.timeout)!=null?o:pr,r=(e==null?void 0:e.timeout)===void 0&&(e==null?void 0:e.noTimeout)===!0;n>this.Ht&&this.logger.warn(`The identify function was called with a timeout greater than ${this.Ht} seconds. We recommend a timeout of less than ${this.Ht} seconds.`);let s=this.Gi.execute({before:async()=>{let l=await qn(t,this.platform);this.autoEnvAttributes===z.Enabled&&(l=await zn(l,this.platform,this.r));let u=S.fromLDContext(l);if(u.valid){let d=this.z.identify(l,e==null?void 0:e.timeout);return{context:l,checkedContext:u,afterIdentify:d}}return{context:l,checkedContext:u}},execute:async l=>{var y;let{context:u,checkedContext:d}=l;if(!d.valid){let x=new Error("Context was unspecified or had no key");return this.emitter.emit("error",u,x),Promise.reject(x)}this.l.set(u,d),(y=this.b)==null||y.sendEvent(this.F.identifyEvent(d));let{identifyPromise:f,identifyResolve:m,identifyReject:p}=this.l.newIdentificationPromise();return this.logger.debug(`Identifying ${JSON.stringify(d)}`),await this.dataManager.identify(m,p,d,e),f},after:async(l,u)=>{var d,f,m;l.status==="complete"?(d=u==null?void 0:u.afterIdentify)==null||d.call(u,{status:"completed"}):l.status==="shed"?(f=u==null?void 0:u.afterIdentify)==null||f.call(u,{status:"shed"}):l.status==="error"&&((m=u==null?void 0:u.afterIdentify)==null||m.call(u,{status:"error"}))}},(c=e==null?void 0:e.sheddable)!=null?c:!1).then(l=>{if(l.status==="error"){let d={status:"error",error:l.error};return this.maybeSetInitializationResult({status:"failed",error:l.error}),d}if(l.status==="shed")return{status:"shed"};let u={status:"completed"};return this.maybeSetInitializationResult({status:"complete"}),u});if(r)return s;let a=new Promise(l=>{setTimeout(()=>{l({status:"timeout",timeout:n})},n*1e3)});return Promise.race([s,a])}maybeSetInitializationResult(t){this.initializeResult===void 0&&(this.initializeResult=t,this.emitter.emit("ready"),t.status==="complete"&&this.emitter.emit("initialized"),this.initResolve&&(this.initResolve(t),this.initResolve=void 0))}waitForInitialization(t){var n;let e=(n=t==null?void 0:t.timeout)!=null?n:5;return this.initializeResult?Promise.resolve(this.initializeResult):this.initializedPromise?this.promiseWithTimeout(this.initializedPromise,e):(this.initializedPromise||(this.initializedPromise=new Promise(r=>{this.initResolve=r})),this.promiseWithTimeout(this.initializedPromise,e))}promiseWithTimeout(t,e){let n=$t(e,"waitForInitialization");return Promise.race([t.then(r=>(n.cancel(),r)),n.promise.then(()=>({status:"complete"})).catch(()=>({status:"timeout"}))]).catch(r=>{var s;return(s=this.logger)==null||s.error(r.message),{status:"failed",error:r}})}on(t,e){this.emitter.on(t,e)}off(t,e){this.emitter.off(t,e)}track(t,e,n){var r,s;if(!this.l.hasValidContext()){this.logger.warn(hi.MissingContextKeyNoEvent);return}n!==void 0&&!h.Number.is(n)&&((r=this.logger)==null||r.warn(hi.invalidMetricValue(typeof n))),(s=this.b)==null||s.sendEvent(this.r.trackEventModifier(this.F.customEvent(t,this.l.getContext(),e,n))),this.z.afterTrack({key:t,context:this.l.getUnwrappedContext(),data:e,metricValue:n})}yt(t,e,n,r){var m,p,y,x;let s=this.l.hasContext();s||(m=this.logger)==null||m.warn("Flag evaluation called before client is fully initialized, data from this evaulation could be stale.");let a=this.l.getContext(),o=this.D.get(t);if(o===void 0||o.flag.deleted){let L=e!=null?e:null,K=new q(`Unknown feature flag "${t}"; returning default value ${L}.`);return this.emitter.emit("error",this.l.getUnwrappedContext(),K),s&&((p=this.b)==null||p.sendEvent(this.F.unknownFlagEvent(t,L,a))),ci(di.FlagNotFound,e)}let{reason:c,value:l,variation:u,prerequisites:d}=o.flag;if(r){let[L,K]=r(l);if(!L){s&&((y=this.b)==null||y.sendEvent(n.evalEventClient(t,e,e,o.flag,a,c)));let P=new q(`Wrong type "${K}" for feature flag "${t}"; returning default value`);return this.emitter.emit("error",this.l.getUnwrappedContext(),P),ci(di.WrongType,e)}}let f=li(l,u,c);return l==null&&(this.logger.debug("Result value is null. Providing default value."),f.value=e),d==null||d.forEach(L=>{this.yt(L,void 0,this.F)}),s&&((x=this.b)==null||x.sendEvent(n.evalEventClient(t,l,e,o.flag,a,c))),f}variation(t,e){let{value:n}=this.z.withEvaluation(t,this.l.getUnwrappedContext(),e,()=>this.yt(t,e,this.F));return n}variationDetail(t,e){return this.z.withEvaluation(t,this.l.getUnwrappedContext(),e,()=>this.yt(t,e,this.mt))}q(t,e,n,r){return this.z.withEvaluation(t,this.l.getUnwrappedContext(),e,()=>this.yt(t,e,n,r))}boolVariation(t,e){return this.q(t,e,this.F,n=>[h.Boolean.is(n),h.Boolean.getType()]).value}jsonVariation(t,e){return this.variation(t,e)}numberVariation(t,e){return this.q(t,e,this.F,n=>[h.Number.is(n),h.Number.getType()]).value}stringVariation(t,e){return this.q(t,e,this.F,n=>[h.String.is(n),h.String.getType()]).value}boolVariationDetail(t,e){return this.q(t,e,this.mt,n=>[h.Boolean.is(n),h.Boolean.getType()])}numberVariationDetail(t,e){return this.q(t,e,this.mt,n=>[h.Number.is(n),h.Number.getType()])}stringVariationDetail(t,e){return this.q(t,e,this.mt,n=>[h.String.is(n),h.String.getType()])}jsonVariationDetail(t,e){return this.variationDetail(t,e)}addHook(t){this.z.addHook(t)}setEventSendingEnabled(t,e){var n,r,s,a;this.Bt!==t&&(this.Bt=t,t?(this.logger.debug("Starting event processor"),(n=this.b)==null||n.start()):e?((r=this.logger)==null||r.debug("Flushing event processor before disabling."),this.flush().then(()=>{var o,c;this.Bt||((o=this.logger)==null||o.debug("Stopping event processor."),(c=this.b)==null||c.close())})):((s=this.logger)==null||s.debug("Stopping event processor."),(a=this.b)==null||a.close()))}sendEvent(t){var e;(e=this.b)==null||e.sendEvent(t)}getDebugOverrides(){var t,e;return(e=(t=this.D).getDebugOverride)==null?void 0:e.call(t)}Wi(t,e){if(!this.et.hasInspectors())return;let n={};t.forEach(r=>{let s=this.D.get(r);if(s!=null&&s.flag&&!s.flag.deleted){let{reason:a,value:o,variation:c}=s.flag;n[r]=li(o,c,a)}else n[r]={value:void 0,reason:null,variationIndex:null}}),e==="init"?this.et.onFlagsChanged(n):e==="patch"&&Object.entries(n).forEach(([r,s])=>{this.et.onFlagChanged(r,s)})}};function Ci(i,t,e){e.forEach(n=>{var r;try{(r=n.registerDebug)==null||r.call(n,t)}catch(s){i.error(`Exception thrown registering plugin ${k.safeGetName(i,n)}.`)}})}var Ie=class{constructor(t,e,n){this.D=t,this.Kt=e,this.t=n}async handlePut(t,e){this.t.debug(`Got PUT: ${Object.keys(e)}`);let n=Object.entries(e).reduce((r,[s,a])=>(r[s]={version:a.version,flag:a},r),{});await this.D.init(t,n),this.Kt.requestStateUpdate(E.Valid)}async handlePatch(t,e){this.t.debug(`Got PATCH ${JSON.stringify(e,null,2)}`),this.D.upsert(t,e.key,{version:e.version,flag:e})}async handleDelete(t,e){this.t.debug(`Got DELETE ${JSON.stringify(e,null,2)}`),this.D.upsert(t,e.key,{version:e.version,flag:D(g({},e),{deleted:!0,flagVersion:0,value:void 0,variation:0,trackEvents:!1})})}handleStreamingError(t){this.Kt.reportError(t.kind,t.message,t.code,t.recoverable)}handlePollingError(t){this.Kt.reportError(t.kind,t.message,t.status,t.recoverable)}},Te=class{constructor(t,e=()=>Date.now()){this.R=t,this.vt=E.Closed,this.Ae=e(),this.pt=e}get status(){return{state:this.vt,stateSince:this.Ae,lastError:this._i}}Oe(t,e=!1){let n=t===E.Interrupted&&this.vt===E.Initializing?E.Initializing:t,r=this.vt!==n;r&&(this.vt=n,this.Ae=this.pt()),(r||e)&&this.R.emit("dataSourceStatus",this.status)}requestStateUpdate(t){this.Oe(t)}reportError(t,e,n,r=!1){let s={kind:t,message:e,statusCode:n,time:this.pt()};this._i=s,this.Oe(r?E.Interrupted:E.Closed,!0)}};function fi(i){i==null||i.debug("Poll completed after the processor was closed. Skipping processing.")}var Ae=class{constructor(t,e,n,r,s){this.Ji=t,this.qi=e,this.Yi=n,this.y=r,this.t=s,this.h=!1}async $e(){var s,a,o,c,l,u,d;if(this.h)return;let t=f=>{var m,p,y;(m=this.t)==null||m.error("Polling received invalid data"),(p=this.t)==null||p.debug(`Invalid JSON follows: ${f}`),(y=this.y)==null||y.call(this,new R(w.InvalidData,"Malformed JSON data in polling response"))};(s=this.t)==null||s.debug("Polling LaunchDarkly for feature flag updates");let e=Date.now();try{let f=await this.Ji.requestPayload();try{if(this.h){fi(this.t);return}let m=JSON.parse(f);try{(a=this.Yi)==null||a.call(this,m)}catch(p){(o=this.t)==null||o.error(`Exception from data handler: ${p}`)}}catch(m){t(f)}}catch(f){if(this.h){fi(this.t);return}let m=f;if(m.status!==void 0&&!Z(m.status)){(c=this.t)==null||c.error($(f,"polling request")),(l=this.y)==null||l.call(this,new R(w.ErrorResponse,m.message,m.status));return}(u=this.t)==null||u.error($(f,"polling request","will retry"))}let n=Date.now()-e,r=Math.max(this.qi*1e3-n,0);(d=this.t)==null||d.debug("Elapsed: %d ms, sleeping for %d ms",n,r),this.Gt=setTimeout(()=>{this.$e()},r)}start(){this.$e()}stop(){this.Gt&&(clearTimeout(this.Gt),this.Gt=void 0),this.h=!0}close(){this.stop()}},mr=(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 j(w.InvalidData,"Malformed JSON data in event stream"))};function yr(i,t){t==null||t.debug(`Received ${i} event after processor was closed. Skipping processing.`)}function gi(i){i==null||i.debug("Ping completed after processor was closed. Skipping processing.")}var Oe=class{constructor(t,e,n,r,s,a,o,c,l){var f;this.Zi=t,this.Wt=e,this.e=n,this.$=r,this.Xi=a,this.C=o,this.y=c,this.t=l,this.h=!1;let u;e.useReport&&!r.getEventSourceCapabilities().customMethod?u=e.paths.pathPing(s,t):u=e.useReport?e.paths.pathReport(s,t):e.paths.pathGet(s,t);let d=[...(f=e.queryParameters)!=null?f:[]];this.Wt.withReasons&&d.push({key:"withReasons",value:"true"}),this.$=r,this.gt=g({},e.baseHeaders),this.t=l,this.Qi=ii(e.serviceEndpoints,u,d)}Ne(){this.wt=Date.now()}_t(t){this.wt&&this.C&&this.C.recordStreamInit(this.wt,!t,Date.now()-this.wt),this.wt=void 0}tn(t){var e,n,r;return Rt(t)?((r=this.t)==null||r.warn($(t,"streaming request","will retry")),this._t(!1),this.Ne(),!0):(this._t(!1),(e=this.y)==null||e.call(this,new j(w.ErrorResponse,t.message,t.status,!1)),(n=this.t)==null||n.error($(t,"streaming request")),!1)}start(){this.Ne();let t;this.Wt.useReport?(this.gt["content-type"]="application/json",t={method:"REPORT",body:this.Zi}):t={};let e=this.$.createEventSource(this.Qi,D(g({headers:this.gt},t),{errorFilter:n=>this.tn(n),initialRetryDelayMillis:this.Wt.initialRetryDelayMillis,readTimeoutMillis:300*1e3,retryResetIntervalMillis:60*1e3}));this.Fe=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 r;(r=this.t)==null||r.info(`Will retry stream connection in ${n.delayMillis} milliseconds`)},this.e.forEach(({deserializeData:n,processJson:r},s)=>{e.addEventListener(s,a=>{var o,c;if(this.h){yr(s,this.t);return}if((o=this.t)==null||o.debug(`Received ${s} event`),a!=null&&a.data){this._t(!0);let{data:l}=a,u=n(l);if(!u){mr(s,l,this.t,this.y);return}r(u)}else(c=this.y)==null||c.call(this,new j(w.InvalidData,"Unexpected payload from event stream"))})}),e.addEventListener("ping",async()=>{var n,r,s,a,o,c,l;(n=this.t)==null||n.debug("Got PING, going to poll LaunchDarkly for feature flag updates");try{let u=await this.Xi.requestPayload();try{if(this.h){gi(this.t);return}let d=JSON.parse(u);try{(r=this.e.get("put"))==null||r.processJson(d)}catch(f){(s=this.t)==null||s.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: ${u}`),(c=this.y)==null||c.call(this,new R(w.InvalidData,"Malformed JSON data in ping polling response"))}}catch(u){if(this.h){gi(this.t);return}let d=u;(l=this.y)==null||l.call(this,new R(w.ErrorResponse,d.message,d.status))}})}stop(){var t;(t=this.Fe)==null||t.close(),this.Fe=void 0,this.h=!0}close(){this.stop()}},jt=class{constructor(t,e,n,r,s,a,o,c,l){this.platform=t,this.flagManager=e,this.credential=n,this.config=r,this.getPollingPaths=s,this.getStreamingPaths=a,this.baseHeaders=o,this.emitter=c,this.diagnosticsManager=l,this.closed=!1,this.logger=r.logger,this.dataSourceStatusManager=new Te(c),this.Y=new Ie(e,this.dataSourceStatusManager,this.config.logger)}setConnectionParams(t){this.en=t}createPollingProcessor(t,e,n,r,s){let a=new Ae(n,this.config.pollInterval,async o=>{await this.Y.handlePut(e,o),r==null||r()},o=>{this.emitter.emit("error",t,o),this.Y.handlePollingError(o),s==null||s(o)},this.logger);this.updateProcessor=this.Re(a,this.dataSourceStatusManager)}createStreamingProcessor(t,e,n,r,s){var o;let a=new Oe(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.en)==null?void 0:o.queryParameters},this.createStreamListeners(e,r),this.platform.requests,this.platform.encoding,n,this.diagnosticsManager,c=>{this.emitter.emit("error",t,c),this.Y.handleStreamingError(c),s==null||s(c)},this.logger);this.updateProcessor=this.Re(a,this.dataSourceStatusManager)}createStreamListeners(t,e){let n=new Map;return n.set("put",{deserializeData:JSON.parse,processJson:async r=>{await this.Y.handlePut(t,r),e==null||e()}}),n.set("patch",{deserializeData:JSON.parse,processJson:async r=>{this.Y.handlePatch(t,r)}}),n.set("delete",{deserializeData:JSON.parse,processJson:async r=>{this.Y.handleDelete(t,r)}}),n}Re(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 zt(i,t){let e=Object.keys(t),n="$flagsState",r="$valid",s=t[n];!s&&e.length&&i.warn("LaunchDarkly client was initialized with bootstrap data that did not include flag metadata. Events may not be sent correctly."),t[r]===!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!==r){let c;s&&s[o]?c=g({value:t[o]},s[o]):c={value:t[o],version:0},a[o]={version:c.version,flag:c}}}),a}function Ht(){return typeof document!==void 0}function Fe(){return typeof window!==void 0}function Bt(i,t,e){return Ht()?(document.addEventListener(i,t,e),()=>{document.removeEventListener(i,t,e)}):()=>{}}function Kt(i,t,e){return Ht()?(window.addEventListener(i,t,e),()=>{window.removeEventListener(i,t,e)}):()=>{}}function T(){return Fe()?window.location.href:""}function Pi(){return Fe()?window.location.search:""}function Ii(){return Fe()?window.location.hash:""}function Ti(){if(typeof crypto!==void 0)return crypto;throw Error("Access to a web crypto API is required")}function Ai(){return Ht()?document.visibilityState:"visibile"}function Oi(i){if(Ht())return document.querySelectorAll(i)}var vr="[BrowserDataManager]",it=class extends jt{constructor(e,n,r,s,a,o,c,l,u,d){super(e,n,r,s,o,c,l,u,d);this.yn=a;this.it=void 0;this.Jt=!1;this.it=a.streaming}P(e,...n){this.logger.debug(`${vr} ${e}`,...n)}async identify(e,n,r,s){if(this.closed){this.P("Identify called after data manager was closed.");return}this.context=r;let a=s;a!=null&&a.hash?this.setConnectionParams({queryParameters:[{key:"h",value:a.hash}]}):this.setConnectionParams(),this.qt=a==null?void 0:a.hash,a!=null&&a.bootstrap?this.nn(r,a.bootstrap,e):(await this.flagManager.loadCached(r)&&this.P("Identify - Flags loaded from cache. Continuing to initialize via a poll."),await this.rn(r,e,n)),this.Yt()}async sn(e){let n=JSON.stringify(S.toLDContext(e)),r=$e(n,this.config.serviceEndpoints,this.getPollingPaths(),this.platform.requests,this.platform.encoding,this.baseHeaders,[],this.config.withReasons,this.config.useReport,this.qt),s=3,a;for(let o=0;o<=s;o+=1)try{return await r.requestPayload()}catch(c){if(!Rt(c))throw c;a=c,o<s&&(this.P($(c,"initial poll request","will retry")),await Ee(1e3))}throw a}async rn(e,n,r){var s,a;try{this.dataSourceStatusManager.requestStateUpdate(E.Initializing);let o=await this.sn(e);try{let l=this.createStreamListeners(e,n).get("put");l.processJson(l.deserializeData(o))}catch(c){this.dataSourceStatusManager.reportError(w.InvalidData,(s=c.message)!=null?s:"Could not parse poll response")}}catch(o){this.dataSourceStatusManager.reportError(w.NetworkError,(a=o.message)!=null?a:"unexpected network error",o.status),r(o)}}nn(e,n,r){this.flagManager.setBootstrap(e,zt(this.logger,n)),this.P("Identify - Initialization completed from bootstrap"),r()}setForcedStreaming(e){this.it=e,this.Yt()}setAutomaticStreamingState(e){this.Jt=e,this.Yt()}Yt(){let e=this.it||this.Jt&&this.it===void 0;this.P(`Updating streaming state. forced(${this.it}) automatic(${this.Jt})`),e?this.an():this.cn()}cn(){var e;this.updateProcessor&&this.P("Stopping update processor."),(e=this.updateProcessor)==null||e.close(),this.updateProcessor=void 0}an(){if(this.updateProcessor){this.P("Update processor already active. Not changing state.");return}if(!this.context){this.P("Context not set, not starting update processor.");return}this.P("Starting update processor."),this.ln(this.context)}ln(e,n,r){var c;let s=S.toLDContext(e);(c=this.updateProcessor)==null||c.close();let a=JSON.stringify(S.toLDContext(e)),o=$e(a,this.config.serviceEndpoints,this.getPollingPaths(),this.platform.requests,this.platform.encoding,this.baseHeaders,[],this.config.withReasons,this.config.useReport,this.qt);this.createStreamingProcessor(s,e,o,n,r),this.updateProcessor.start()}};function $i(i){let e=Bt("visibilitychange",()=>{Ai()==="hidden"&&i()}),n=Kt("pagehide",i);return()=>{e(),n()}}function nt(i){if(typeof i!="string")throw new TypeError("Expected a string");return i.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function wr(i,t,e,n){let s=((i.kind==="substring"||i.kind==="regex")&&n.includes("/")?t:t.replace(n,"")).replace(e,"");switch(i.kind){case"exact":return new RegExp(`^${nt(i.url)}/?$`).test(t);case"canonical":return new RegExp(`^${nt(i.url)}/?$`).test(s);case"substring":return new RegExp(`.*${nt(i.substring)}.*$`).test(s);case"regex":return new RegExp(i.pattern).test(s);default:return!1}}function Er(i,t){let e=[];return t.forEach(n=>{let r=i.target,{selector:s}=n,a=Oi(s);for(;r&&(a!=null&&a.length);){for(let o=0;o<a.length;o+=1)if(r===a[o]){e.push(n);break}r=r.parentNode}}),e}var rt=class{constructor(t,e){let n=t.filter(a=>{var o;return(o=a.urls)==null?void 0:o.some(c=>wr(c,T(),Pi(),Ii()))}),r=n.filter(a=>a.kind==="pageview"),s=n.filter(a=>a.kind==="click");if(r.forEach(a=>e(a)),s.length){let a=o=>{Er(o,s).forEach(c=>{e(c)})};this.Me=Bt("click",a)}}close(){var t;(t=this.Me)==null||t.call(this)}};var Dr=300,Gt=class{constructor(t){this.Zt=T();let e=()=>{let r=T();r!==this.Zt&&(this.Zt=r,t())};this.Xt=setInterval(e,Dr);let n=Kt("popstate",e);this.Ue=()=>{n()}}close(){var t;this.Xt&&clearInterval(this.Xt),(t=this.Ue)==null||t.call(this)}};var st=class{constructor(t,e,n,r,s,a=o=>new Gt(o)){this.$=e;this.dn=r;this.hn=s;this.Et=[];this.je=!1;this.Dt=`${n}/sdk/goals/${t}`,this.Ve=a(()=>{this.te()})}async initialize(){await this.un(),this.te()}startTracking(){this.je=!0,this.te()}te(){var t;this.je&&((t=this.Qt)==null||t.close(),this.Et&&this.Et.length&&(this.Qt=new rt(this.Et,e=>{this.hn(T(),e)})))}async un(){try{let t=await this.$.fetch(this.Dt);this.Et=await t.json()}catch(t){this.dn(new J(`Encountered error fetching goals: ${t}`))}}close(){var t,e;(t=this.Ve)==null||t.close(),(e=this.Qt)==null||e.close()}};function Ni(i){return i.kind==="click"}var br=2,Fi={fetchGoals:!0,eventUrlTransformer:i=>i,streaming:void 0,plugins:[]},kr={fetchGoals:h.Boolean,eventUrlTransformer:h.Function,streaming:h.Boolean,plugins:h.createTypeArray("LDPlugin",{})};function xr(i){var e;let t=g({},i);return(e=t.flushInterval)!=null||(t.flushInterval=br),t}function Ri(i){let t=xr(i);return Object.keys(Fi).forEach(e=>{delete t[e]}),t}function Re(i,t){let e=g({},Fi);return Object.entries(kr).forEach(n=>{let[r,s]=n,a=i[r];a!==void 0&&(s.is(a)?e[r]=a:t.warn(b.wrongOptionType(r,s.getType(),typeof a)))}),e}var at=class{constructor(t,e){this.fn=t;this.ze=[];switch(e){case"sha1":this.ee="SHA-1";break;case"sha256":this.ee="SHA-256";break;default:throw new Error(`Algorithm is not supported ${e}`)}}async asyncDigest(t){let e=this.ze.join(""),n=new TextEncoder().encode(e),r=await this.fn.subtle.digest(this.ee,n);switch(t){case"base64":return btoa(String.fromCharCode(...new Uint8Array(r)));case"hex":return[...new Uint8Array(r)].map(s=>s.toString(16).padStart(2,"0")).join("");default:throw new Error(`Encoding is not supported ${t}`)}}update(t){return this.ze.push(t),this}};var Lr={start:0,end:3},Sr={start:4,end:5},Me={start:6,end:7},Ue={start:8,end:8},Cr={start:9,end:9},Pr={start:10,end:15};function Ir(){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 B(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 Tr(i){return i[Ue.start]=(i[Ue.start]|128)&191,i[Me.start]=i[Me.start]&15|64,`${B(i,Lr)}-${B(i,Sr)}-${B(i,Me)}-${B(i,Ue)}${B(i,Cr)}-${B(i,Pr)}`}function Ar(){let i=Ir();return Tr(i)}function Ve(){return typeof crypto!==void 0&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Ar()}var ot=class{createHash(t){return new at(Ti(),t)}randomUUID(){return Ve()}};function Or(i){let t=Array.from(i,e=>String.fromCodePoint(e)).join("");return btoa(t)}var ct=class{btoa(t){return Or(new TextEncoder().encode(t))}};var lt=class{constructor(t){this.r=t}platformData(){return{name:"JS"}}sdkData(){let t={name:"@launchdarkly/js-client-sdk",version:"0.12.0",userAgentBase:"JSClient"};return this.r.wrapperName&&(t.wrapperName=this.r.wrapperName),this.r.wrapperVersion&&(t.wrapperVersion=this.r.wrapperVersion),t}};var ut=class{constructor(t,e){this.Dt=t;this.e={};this.T=new kt(e.initialRetryDelayMillis,e.retryResetIntervalMillis),this.He=e.errorFilter,this.Be()}Be(){this.Z=new EventSource(this.Dt),this.Z.onopen=()=>{var t;this.T.success(),(t=this.onopen)==null||t.call(this)},this.Z.onerror=t=>{var e;this.gn(t),(e=this.onerror)==null||e.call(this,t)},Object.entries(this.e).forEach(([t,e])=>{e.forEach(n=>{var r;(r=this.Z)==null||r.addEventListener(t,n)})})}addEventListener(t,e){var n,r,s;(r=(n=this.e)[t])!=null||(n[t]=[]),this.e[t].push(e),(s=this.Z)==null||s.addEventListener(t,e)}close(){var t,e;clearTimeout(this.ie),this.ie=void 0,(t=this.Z)==null||t.close(),(e=this.onclose)==null||e.call(this)}pn(t){var e;(e=this.onretrying)==null||e.call(this,{delayMillis:t}),this.ie=setTimeout(()=>{this.Be()},t)}gn(t){this.close(),!(t.status&&typeof t.status=="number"&&!this.He(t))&&this.pn(this.T.fail())}};var ht=class{fetch(t,e){return fetch(t,e)}createEventSource(t,e){return new ut(t,e)}getEventSourceCapabilities(){return{customMethod:!1,readTimeout:!1,headers:!1}}};function je(){return typeof localStorage!="undefined"}function Mi(){if(!je())return[];let i=[];for(let t=0;t<localStorage.length;t+=1){let e=localStorage.key(t);e&&i.push(e)}return i}var dt=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(r){(n=this.t)==null||n.error(`Error setting key in localStorage: ${t}, reason: ${r}`)}}};var ft=class{constructor(t,e){this.encoding=new ct;this.crypto=new ot;this.requests=new ht;je()&&(this.storage=new dt(t)),this.info=new lt(e)}};var ze=class extends Vt{constructor(t,e,n={},r){var m;let{logger:s,debug:a}=n,o=s!=null?s:new M({destination:{debug:console.debug,info:console.info,warn:console.warn,error:console.error},level:a?"debug":"info"}),c=(m=n.baseUri)!=null?m:"https://clientsdk.launchdarkly.com",l=r!=null?r:new ft(o,n),u=Re(n,o),d=Ri(D(g({},n),{logger:o})),{eventUrlTransformer:f}=u;super(t,e,l,d,(p,y,x,L,K)=>new it(l,p,t,y,u,()=>({pathGet(P,N){return`/sdk/evalx/${t}/contexts/${we(N,P)}`},pathReport(P,N){return`/sdk/evalx/${t}/context`},pathPing(P,N){throw new Error("Ping for polling unsupported.")}}),()=>({pathGet(P,N){return`/eval/${t}/${we(N,P)}`},pathReport(P,N){return`/eval/${t}`},pathPing(P,N){return`/ping/${t}`}}),x,L,K),{getLegacyStorageKeys:()=>Mi().filter(p=>p.startsWith(`ld:${t}:`)),analyticsEventPath:`/events/bulk/${t}`,diagnosticEventPath:`/events/diagnostic/${t}`,includeAuthorizationHeader:!1,highTimeoutThreshold:5,userAgentHeaderName:"x-launchdarkly-user-agent",trackEventModifier:p=>new k.InputCustomEvent(p.context,p.key,p.data,p.metricValue,p.samplingRatio,f(T())),getImplementationHooks:p=>k.safeGetHooks(o,p,u.plugins),credentialType:"clientSideId"}),this.setEventSendingEnabled(!0,!1),this.re=u.plugins,u.fetchGoals&&(this.ne=new st(t,l.requests,c,p=>{o.error(p.message)},(p,y)=>{let x=this.getInternalContext();if(!x)return;let L=f(p);Ni(y)?this.sendEvent({kind:"click",url:L,samplingRatio:1,key:y.key,creationDate:Date.now(),context:x,selector:y.selector}):this.sendEvent({kind:"pageview",url:L,samplingRatio:1,key:y.key,creationDate:Date.now(),context:x})}),this.ne.initialize(),u.automaticBackgroundHandling&&$i(()=>this.flush()))}registerPlugins(t){k.safeRegisterPlugins(this.logger,this.environmentMetadata,t,this.re||[]);let e=this.getDebugOverrides();e&&Ci(this.logger,e,this.re||[])}setInitialContext(t){this.se=t}async identify(t,e){return super.identify(t,e)}async identifyResult(t,e){var s;if(!this.nt)return this.logger.error("Client must be started before it can identify a context, did you forget to call start()?"),{status:"error",error:new Error("Identify called before start")};let n=g({},e);(e==null?void 0:e.sheddable)===void 0&&(n.sheddable=!0);let r=await super.identifyResult(t,n);return(s=this.ne)==null||s.startTracking(),r}start(t){var n,r;if(this.initializeResult)return Promise.resolve(this.initializeResult);if(this.nt)return this.nt;if(!this.se)return this.logger.error("Initial context not set"),Promise.resolve({status:"failed",error:new Error("Initial context not set")});let e=D(g({},(n=t==null?void 0:t.identifyOptions)!=null?n:{}),{sheddable:!1});if(t!=null&&t.bootstrap&&!e.bootstrap&&(e.bootstrap=t.bootstrap),e!=null&&e.bootstrap)try{let s=zt(this.logger,e.bootstrap);this.presetFlags(s)}catch(s){this.logger.error("Failed to bootstrap data",s)}return this.initializedPromise||(this.initializedPromise=new Promise(s=>{this.initResolve=s})),this.nt=this.promiseWithTimeout(this.initializedPromise,(r=t==null?void 0:t.timeout)!=null?r:5),this.identifyResult(this.se,e),this.nt}setStreaming(t){this.dataManager.setForcedStreaming(t)}Ke(){this.dataManager.setAutomaticStreamingState(!!this.emitter.listenerCount("change"))}on(t,e){super.on(t,e),this.Ke()}off(t,e){super.off(t,e),this.Ke()}};function Ui(i,t,e,n={},r){let s=new ze(i,e,n,r);s.setInitialContext(t);let a={variation:(o,c)=>s.variation(o,c),variationDetail:(o,c)=>s.variationDetail(o,c),boolVariation:(o,c)=>s.boolVariation(o,c),boolVariationDetail:(o,c)=>s.boolVariationDetail(o,c),numberVariation:(o,c)=>s.numberVariation(o,c),numberVariationDetail:(o,c)=>s.numberVariationDetail(o,c),stringVariation:(o,c)=>s.stringVariation(o,c),stringVariationDetail:(o,c)=>s.stringVariationDetail(o,c),jsonVariation:(o,c)=>s.jsonVariation(o,c),jsonVariationDetail:(o,c)=>s.jsonVariationDetail(o,c),track:(o,c,l)=>s.track(o,c,l),on:(o,c)=>s.on(o,c),off:(o,c)=>s.off(o,c),flush:()=>s.flush(),setStreaming:o=>s.setStreaming(o),identify:(o,c)=>s.identifyResult(o,c),getContext:()=>s.getContext(),close:()=>s.close(),allFlags:()=>s.allFlags(),addHook:o=>s.addHook(o),waitForInitialization:o=>s.waitForInitialization(o),logger:s.logger,start:o=>s.start(o)};return s.registerPlugins(a),a}var Vi=["ready","failed","initialized"],gt=class{constructor(t){this.n=t;this.e=new Map}on(t,e){var n;Vi.includes(t)?this.e.has(t)?(n=this.e.get(t))==null||n.push(e):this.e.set(t,[e]):this.n.on(t,e)}off(t,e){if(Vi.includes(t)){let n=this.e.get(t);if(!n)return;if(e){let r=n.filter(s=>s!==e);r.length===0?this.e.delete(t):this.e.set(t,r);return}this.e.delete(t)}else this.n.off(t,e)}zt(t,e,...n){try{t(...n)}catch(r){this.n.logger.error(`Encountered error invoking handler for "${e}", detail: "${r}"`)}}emit(t,...e){let n=this.e.get(t);n==null||n.forEach(r=>this.zt(r,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}};function Wt(i,t){let e=i.then(n=>(t&&setTimeout(()=>{t(null,n)},0),n),n=>{if(t)setTimeout(()=>{t(n,null)},0);else return Promise.reject(n)});return t?void 0:e}var pt=class{constructor(t,e,n){this.ae="initializing";let r=n==null?void 0:n.bootstrap,s=n==null?void 0:n.hash,a=g({},n);delete a.bootstrap,delete a.hash,this.n=Ui(t,e,z.Disabled,n),this.R=new gt(this.n),this.logger=this.n.logger,this.n.start(),this.mn(e,r,s)}async mn(t,e,n){var r,s;try{let a=await this.n.identify(t,{noTimeout:!0,bootstrap:e,hash:n,sheddable:!1});if(a.status==="error")throw a.error;if(a.status==="timeout")throw new I("Identify timed out");this.ae="success",(r=this.Ge)==null||r.call(this),this.R.emit("initialized")}catch(a){this._e=a,this.ae="failure",(s=this.We)==null||s.call(this,a),this.R.emit("failed",a)}this.R.emit("ready")}allFlags(){return this.n.allFlags()}boolVariation(t,e){return this.n.boolVariation(t,e)}boolVariationDetail(t,e){return this.n.boolVariationDetail(t,e)}jsonVariation(t,e){return this.n.jsonVariation(t,e)}jsonVariationDetail(t,e){return this.n.jsonVariationDetail(t,e)}numberVariation(t,e){return this.n.numberVariation(t,e)}numberVariationDetail(t,e){return this.n.numberVariationDetail(t,e)}off(t,e){this.R.off(t,e)}on(t,e){this.R.on(t,e)}stringVariation(t,e){return this.n.stringVariation(t,e)}stringVariationDetail(t,e){return this.n.stringVariationDetail(t,e)}track(t,e,n){this.n.track(t,e,n)}variation(t,e){return this.n.variation(t,e)}variationDetail(t,e){return this.n.variationDetail(t,e)}addHook(t){this.n.addHook(t)}setStreaming(t){this.n.setStreaming(t)}identify(t,e,n){return Wt(this.n.identify(t,{hash:e,sheddable:!1}).then(r=>{if(r.status==="error")throw r.error;if(r.status==="timeout")throw new I("Identify timed out");return this.allFlags()}),n)}close(t){return Wt(this.n.close().then(),t)}flush(t){return Wt(this.n.flush().then(()=>{}),t)}getContext(){return this.n.getContext()}waitForInitialization(t){var e;if(this.rt)return this.Je(this.rt,t);switch(this.ae){case"success":return Promise.resolve();case"failure":return Promise.reject(this._e);case"initializing":break;default:throw new Error("Unexpected initialization state. This represents an implementation error in the SDK.")}return t===void 0&&((e=this.logger)==null||e.warn("The waitForInitialization function was called without a timeout specified. In a future version a default timeout will be applied.")),this.rt||(this.rt=new Promise((n,r)=>{this.Ge=n,this.We=r})),this.Je(this.rt,t)}async waitUntilReady(){try{await this.waitForInitialization()}catch(t){}}Je(t,e){if(e){let n=$t(e,"waitForInitialization");return Promise.race([t.then(()=>n.cancel()),n.promise]).catch(r=>{var s;throw r instanceof I&&((s=this.logger)==null||s.error(r.message)),r})}return t}};function $r(i){return new M(i)}function Nr(i,t,e){return new pt(i,t,e)}0&&(module.exports={basicLogger,initialize});
2
2
  //# sourceMappingURL=compat.cjs.map