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