@statsig/js-client 0.0.1-beta.30 → 0.0.1-beta.31
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/build/statsig-js-client+session-replay+web-analytics.min.js +1 -1
- package/build/statsig-js-client+web-analytics.min.js +1 -1
- package/build/statsig-js-client.min.js +1 -1
- package/package.json +2 -2
- package/src/StatsigClient.d.ts +9 -9
- package/src/StatsigClient.js +17 -14
- package/src/index.d.ts +3 -1
- package/src/index.js +1 -1
- package/build/js-client+session-replay+web-analytics-stats.json +0 -11400
- package/build/js-client+web-analytics-stats.json +0 -10787
- package/build/js-client-stats.json +0 -11024
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Statsig=e():t.Statsig=e()}(this,()=>(()=>{"use strict";var $Q=(e)=>Object.defineProperty(e,"__esModule",{value:!0});var $P = (a,b) => Object.assign(a,b);var n={496:(t,e,n)=>{$Q(e),e.i=void 0;var i,o="__STATSIG__",s="undefined"!=typeof window?window:{},n=void 0!==n.g?n.g:{},r="undefined"!=typeof globalThis?globalThis:{};const u=null!=(i=null!=(i=null!=(i=s[o])?i:n[o])?i:r[o])?i:{};s[o]=u,n[o]=u,r[o]=u;e.i=()=>null!==__STATSIG__&&void 0!==__STATSIG__?__STATSIG__:u},856:(t,e)=>{$Q(e)},320:function(t,e,n){var s=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.DataAdapterCore=void 0;const i=n(512),o=n(780),r=n(104),u=n(283),l=n(296),a=n(444),c=n(412);e.DataAdapterCore=class{constructor(t,e){this.o=t,this.u=e,this.l=null,this.h=null,this.v={},this._="statsig.last_modified_time."+e}attach(t,e){this.h=t,this.l=new i.ErrorBoundary(t),(0,r.monitorClass)(this.l,this)}getDataSync(t){var t=this.m(t),e=this.v[t];return e||((e=this.p(t))?(this.S(t,e),this.v[t]):null)}getDataAsync(n,i){var o;return s(this,void 0,void 0,function*(){var t=null!=n?n:this.getDataSync(i),t=yield this.O(null!=(o=null==t?void 0:t.data)?o:null,i),e=this.m(i);return t&&this.S(e,t),"Network"!==(null==t?void 0:t.source)&&"NetworkNotModified"!==(null==t?void 0:t.source)||(yield this.j(e,t)),t})}prefetchData(n){return s(this,void 0,void 0,function*(){var t=this.m(n),e=yield this.getDataAsync(null,n);e&&this.S(t,$P($P({},e),{source:"Prefetch"}))})}setData(t,e){e=this.m(e);this.S(e,{source:"Bootstrap",data:t,receivedAt:Date.now()})}__primeInMemoryCache(t){this.v=$P($P({},this.v),t)}O(n,i){return s(this,void 0,void 0,function*(){var t,e=yield this.T(n,i);return e?(t=(0,c.typedJsonParse)(e,"has_updates","Failure while attempting to persist latest value"),n&&!1===(null==t?void 0:t.has_updates)?{source:"NetworkNotModified",data:n,receivedAt:Date.now()}:!0!==(null==t?void 0:t.has_updates)?null:{source:"Network",data:e,receivedAt:Date.now()}):(o.Log.debug("No response returned for latest value"),null)})}I(){return null!=this.h?this.h:(o.Log.error(this.o+" is not attached to a Client"),"")}m(t){t=(0,l.getUserStorageKey)(this.I(),t);return`${u.DataAdapterCachePrefix}.${this.u}.`+t}S(t,e){var n=Object.entries(this.v);n.length<10||([n]=n.reduce((t,e)=>e[1]<t[1]?e:t),delete this.v[n]),this.v[t]=e}p(t){var e=null==(e=a.Storage.A)?void 0:e.call(a.Storage,t);return null!=e&&(t=(0,c.typedJsonParse)(e,"source","Failed to parse cached result"))?$P($P({},t),{source:"Cache"}):null}j(t,e){return s(this,void 0,void 0,function*(){yield a.Storage.M(t,JSON.stringify(e)),yield this.D(t)})}D(n){var i;return s(this,void 0,void 0,function*(){var t=null!=(i=yield(0,a.N)(this._))?i:{},e=(t[n]=Date.now(),Object.entries(t));e.length<=10||(delete t[(e=e.reduce((t,e)=>e[1]<t[1]?e:t))[0]],yield a.Storage.P(e[0])),yield(0,a.R)(this._,t)})}}},280:(t,e,n)=>{$Q(e),e.Diagnostics=e.captureDiagnostics=void 0;const i=n(780),o=n(256),s="undefined"!=typeof performance&&void 0!==performance.mark;let r=[];e.captureDiagnostics=function(t,e){u.mark(t+":start"),e=e();const n=()=>{u.mark(t+":end"),(t+":end").startsWith("initialize:")&&u.flush()};return e&&e instanceof Promise?e.finally(()=>n()):(n(),e)};class u{static mark(t,e){s&&(t=performance.mark(t,{detail:e}),r.push(t))}static flush(){var t=performance.getEntriesByType("resource").filter(t=>t.name.startsWith(o.NetworkDefault.initializeApi)||t.name.startsWith(o.NetworkDefault.specsApi)||t.name.startsWith(o.NetworkDefault.eventsApi)),t={markers:r,resources:t};i.Log.debug("Diagnostics",t,JSON.stringify(t)),r=[]}}e.Diagnostics=u},184:(t,e)=>{$Q(e)},512:function(t,l,e){var n=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};Object.defineProperty(l,"__esModule",{value:!0}),l.ErrorBoundary=l.EXCEPTION_ENDPOINT=void 0;const i=e(780),a=e(360),c=e(972);l.EXCEPTION_ENDPOINT="https://statsigapi.net/v1/sdk_exception";l.ErrorBoundary=class{constructor(t){this.h=t,this.C=new Set}capture(e,t,n){try{var i=t();return i&&i instanceof Promise?i.catch(t=>this.G(e,t,n)):i}catch(t){return this.G(e,t,n),null}}logError(t,e){this.G(t,e)}G(s,r,u){try{i.Log.warn("Caught error in "+s,{error:r});n(this,void 0,void 0,function*(){var t,e,n=null!=r?r:Error("[Statsig] Error was empty"),i=n instanceof Error,o=i?n.name:"No Name";this.C.has(o)||(this.C.add(o),t=a.SDKType.F(this.h),e=c.StatsigMetadataProvider.get(),i=i?n.stack:function(t){try{return JSON.stringify(t)}catch(t){return"[Statsig] Failed to get string for error."}}(n),n=JSON.stringify($P({tag:s,exception:o,info:i},$P($P({},e),{sdkType:t}))),yield fetch(l.EXCEPTION_ENDPOINT,{method:"POST",headers:{"STATSIG-API-KEY":this.h,"STATSIG-SDK-TYPE":String(t),"STATSIG-SDK-VERSION":String(e.sdkVersion),"Content-Type":"application/json"},body:n}),null!=u&&u({name:"error",error:r}))}).then(()=>{}).catch(()=>{})}catch(t){}}}},500:(t,e)=>{$Q(e)},788:(t,e)=>{$Q(e)},728:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.EventLogger=void 0;const o=n(832),s=n(780),r=n(256),u=n(452),l=n(876),a=n(444),c=n(412),d=n(84),h=n(100);e.EventLogger=class{constructor(t,e,n,i){this.h=t,this.L=e,this.U=n,this.J=i,this.K=[],this.q={},this.V={},this.B=!1,this.$=Date.now(),this.H=!0===(null==i?void 0:i.disableLogging),this.W=null!=(t=null==i?void 0:i.loggingBufferMaxSize)?t:50;n=null!=(e=null==i?void 0:i.loggingIntervalMs)?e:1e4,this.Y=setInterval(()=>this.X(),n),t=null==i?void 0:i.networkConfig;this.Z=(0,d.tt)(null==t?void 0:t.logEventUrl,null==t?void 0:t.api,"/rgstr",r.NetworkDefault.eventsApi),this.et=(0,d.tt)(null==t?void 0:t.logEventBeaconUrl,null==t?void 0:t.api,"/log_event_beacon",r.NetworkDefault.eventsApi),(0,h.nt)(this.it.bind(this)),this.ot()}setLoggingDisabled(t){this.H=t}enqueue(t){this.rt(t)&&(this.ut(t),this.lt(),this.K.length>this.W)&&this.X()}incrementNonExposureCount(t){var e=null!=(e=this.V[t])?e:0;this.V[t]=e+1}reset(){this.q={}}shutdown(){return i(this,void 0,void 0,function*(){this.Y&&(clearInterval(this.Y),this.Y=null),yield this.flush()})}flush(){return i(this,void 0,void 0,function*(){var t;this.ct(),0!==this.K.length&&(t=this.K,this.K=[],yield this.dt(t))})}it(t){"background"===t&&this.X()}lt(){this.B||(this.B=!0,200<Date.now()-this.$)||setTimeout(()=>this.X(),200)}rt(t){if((0,l.ht)(t)){var t=[t.eventName,null==(e=t.user)?void 0:e.userID,null==(e=t.metadata)?void 0:e.gate,null==(e=t.metadata)?void 0:e.config,null==(e=t.metadata)?void 0:e.ruleID].join("|"),e=this.q[t],n=Date.now();if(e&&n-e<6e4)return!1;1e3<Object.keys(this.q).length&&(this.q={}),this.q[t]=n}return!0}X(){this.flush().catch(()=>{})}dt(t){return i(this,void 0,void 0,function*(){if(this.H)this.vt(t);else try{(!(0,h._t)()&&this.U.isBeaconSupported()?yield this.ft(t):yield this.gt(t)).success?this.L({name:"logs_flushed",events:t}):this.vt(t)}catch(t){s.Log.warn("Failed to flush events.")}})}gt(e){return i(this,void 0,void 0,function*(){var t=yield this.U.post({sdkKey:this.h,data:{events:e},url:this.Z,retries:3,params:{[u.NetworkParam.EventCount]:String(e.length)}}),t=null!=t&&t.body?(0,c.typedJsonParse)(t.body,"success","Failed to parse SendEventsResponse"):null;return{success:!0===(null==t?void 0:t.success)}})}ft(t){return i(this,void 0,void 0,function*(){return{success:yield this.U.beacon({sdkKey:this.h,data:{events:t},url:this.et})}})}vt(t){for(;500<t.length;)t.shift();var e=this.bt();(0,a.R)(e,t).catch(()=>{s.Log.warn("Unable to save failed logs to storage")})}ot(){const e=this.bt();i(this,void 0,void 0,function*(){var t=yield(0,a.N)(e);t&&(yield a.Storage.P(e),yield this.dt(t))}).catch(()=>{s.Log.warn("Failed to flush stored logs")})}bt(){return"statsig.failed_logs."+(0,o.DJB2)(this.h)}ut(t){t.user&&(t.user=$P({},t.user),delete t.user.privateAttributes);var e={},n=this.yt();n&&(e.statsigMetadata={currentPage:n}),this.K.push($P($P({},t),e))}ct(){0!==Object.keys(this.V).length&&(this.ut({eventName:"statsig::non_exposed_checks",user:null,time:Date.now(),metadata:{checks:$P({},this.V)}}),this.V={})}yt(){var t;if(!1!==(null==(t=this.J)?void 0:t.includeCurrentPageUrlWithEvents)&&"undefined"!=typeof window&&"object"==typeof window.location)try{return window.location.href.split(/[?#]/)[0]}catch(t){}}}},832:(t,e)=>{$Q(e),e.DJB2Object=e.DJB2=void 0;e.DJB2=e=>{let n=0;for(let t=0;t<e.length;t++){var i=e.charCodeAt(t);n=(n<<5)-n+i,n&=n}return String(n>>>0)};e.DJB2Object=t=>(0,e.DJB2)(JSON.stringify(o(t)));const o=n=>{if(null==n)return null;var t=Object.keys(n).sort();const i={};return t.forEach(t=>{let e=n[t];e instanceof Object&&(e=o(e)),i[t]=e}),i}},664:(t,e)=>{$Q(e)},780:(t,e)=>{function n(t){return t.unshift("[Statsig]"),t}var i,o;$Q(e),e.Log=e.LogLevel=void 0,(o=i||(e.LogLevel=i={}))[o.None=0]="None",o[o.Error=1]="Error",o[o.Warn=2]="Warn",o[o.Info=3]="Info",o[o.Debug=4]="Debug";class s{static info(...t){this.level>=i.Info&&console.info(...n(t))}static debug(...t){this.level>=i.Debug&&console.debug(...n(t))}static warn(...t){this.level>=i.Warn&&console.warn(...n(t))}static error(...t){this.level>=i.Error&&console.error(...n(t))}}(e.Log=s).level=i.Error},104:(t,e,n)=>{$Q(e),e.monitorClass=void 0;const s=n(280),r=n(688);function c(t,e,n,i){var o=i instanceof r.StatsigClientBase?i.St.bind(i):void 0;return t.capture(e,()=>(0,s.captureDiagnostics)(e,()=>n.apply(i)),o)}function d(t){return"object"==typeof t&&(t=Object.getPrototypeOf(t))&&"object"==typeof t?t:null}e.monitorClass=function(e,t){try{{var n=e;var i=t;var o;const s=i;for(const r of function(t){const e=new Set;let n=d(t);for(;n&&n!==Object.prototype;)Object.getOwnPropertyNames(n).filter(t=>"function"==typeof(null===n||void 0===n?void 0:n[t])).forEach(t=>e.add(t)),n=Object.getPrototypeOf(n);return Array.from(e)}(s))if("constructor"!==r){const u=s[r];s[r]=function(...t){return c(n,r,()=>u.apply(this,t),i)}}for(const l of function(t){const e=new Set,n=d(t);return Object.getOwnPropertyNames((null===n||void 0===n?void 0:n.constructor)||{}).filter(t=>{var e;return"caller"!==t&&"arguments"!==t&&"callee"!==t&&"function"==typeof(null==(e=null===n||void 0===n?void 0:n.constructor)?void 0:e[t])}).forEach(t=>e.add(t)),Array.from(e)}(s)){const a=null==(o=null===s||void 0===s?void 0:s.constructor)?void 0:o[l];(null===s||void 0===s?void 0:s.constructor)[l]=function(...t){return c(n,s.constructor.name+"."+l,()=>a.apply(s.constructor,t),i)}}return}}catch(t){e.logError("monitorClass",t)}}},188:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.NetworkCore=void 0,n(496);const h=n(280),v=n(780),o=n(452),s=n(360),r=n(612),u=n(604),l=n(972);e.NetworkCore=class{constructor(t,e){this.J=t,this.L=e,this.Ot=null!=(t=null==(e=null==t?void 0:t.networkConfig)?void 0:e.networkTimeoutMs)?t:1e4}post(e){return i(this,void 0,void 0,function*(){var t=yield this.jt(e);return this.Tt($P({method:"POST",body:this.t(e,t)},e))})}get(t){return this.Tt($P({method:"GET"},t))}isBeaconSupported(){return"undefined"!=typeof navigator&&"function"==typeof(null===navigator||void 0===navigator?void 0:navigator.sendBeacon)}beacon(n){return i(this,void 0,void 0,function*(){var t=yield this.wt(n),e=yield this.jt(n);return navigator.sendBeacon(t,e)})}Tt(c){var d;return i(this,void 0,void 0,function*(){var{method:e,body:n,retries:i}=c;const o=new AbortController;var t,s,r,u=setTimeout(()=>o.abort(`Timeout of ${this.Ot}ms expired.`),this.Ot),l=yield this.wt(c);let a=null;try{if(a=yield fetch(l,{method:e,body:n,headers:$P({},c.headers),signal:o.signal}),clearTimeout(u),a.ok)return r=yield a.text(),h.Diagnostics.mark("_sendRequest:response-received",{status:a.status,contentLength:a.headers.get("content-length")}),{body:r,code:a.status};throw t=yield a.text().catch(()=>"No Text"),(s=new Error(`Failed to fetch: ${l} `+t)).name="NetworkError",s}catch(t){n=function(t,e){if(t.signal.aborted&&"string"==typeof t.signal.reason)return t.signal.reason;if("string"==typeof e)return e;if(e instanceof Error)return e.name+": "+e.message;return null}(o,t);return h.Diagnostics.mark("_sendRequest:error",{error:n,status:null===a||void 0===a?void 0:a.status,contentLength:null===a||void 0===a?void 0:a.headers.get("content-length")}),!i||i<=0?(null!=(d=this.L)&&d.call(this,{name:"error",error:t}),v.Log.error(`A networking error occured during ${e} request to ${l}.`,n,t),null):this.Tt($P($P({},c),{retries:i-1}))}})}wt(e){return i(this,void 0,void 0,function*(){var t=$P({[o.NetworkParam.SdkKey]:e.sdkKey,[o.NetworkParam.SdkType]:s.SDKType.F(e.sdkKey),[o.NetworkParam.SdkVersion]:l.SDK_VERSION,[o.NetworkParam.Time]:String(Date.now()),[o.NetworkParam.SessionID]:yield r.SessionID.get(e.sdkKey)},e.params),t=Object.entries(t).map(([t,e])=>encodeURIComponent(t)+"="+encodeURIComponent(e)).join("&");return e.url+(t?"?"+t:"")})}jt(o){return i(this,void 0,void 0,function*(){var{data:t,sdkKey:e}=o,n=yield u.StableID.get(e),i=yield r.SessionID.get(e),e=s.SDKType.F(e);return JSON.stringify($P($P({},t),{statsigMetadata:$P($P({},l.StatsigMetadataProvider.get()),{stableID:n,sessionID:i,sdkType:e})}))})}t(t,e){var n;return!(null!=(null===__STATSIG__||void 0===__STATSIG__?void 0:__STATSIG__["no-encode"])||null!=(n=this.J)&&n.disableStatsigEncoding)&&t.isStatsigEncodable&&"undefined"!=typeof window&&window.btoa&&(t.params=$P($P({},null!=(n=t.params)?n:{}),{[o.NetworkParam.StatsigEncoded]:"1"}),null!=(t=window.btoa(e).split("").reverse().join("")))?t:e}}},256:(t,e)=>{$Q(e),e.NetworkDefault=void 0,e.NetworkDefault={eventsApi:"https://events.statsigapi.net/v1",initializeApi:"https://featuregates.org/v1",specsApi:"https://api.statsigcdn.com/v1"}},452:(t,e)=>{$Q(e),e.NetworkParam=void 0,e.NetworkParam={EventCount:"ec",SdkKey:"k",SdkType:"st",SdkVersion:"sv",Time:"t",SessionID:"sid",StatsigEncoded:"se"}},264:(t,e)=>{$Q(e)},360:(t,e)=>{$Q(e),e.SDKType=void 0;const n={};let i;e.SDKType={F:t=>{return(null!=(t=n[t])?t:"js-mono")+(null!==i&&void 0!==i?i:"")},It(t,e){n[t]=e},At(t){i&&"-react"!==i||(i="-"+t)}}},48:(t,i)=>{Object.defineProperty(i,"__esModule",{value:!0}),i.xt=i.Mt=i.Dt=i.Et=void 0;i.Et=()=>"undefined"!=typeof window?window:null,i.Dt=()=>{var t=(0,i.Et)();return null!=(t=null==t?void 0:t.document)?t:null},i.Mt=(t,e)=>{var n=(0,i.Et)();"function"==typeof(null==n?void 0:n.addEventListener)&&n.addEventListener(t,e)};i.xt=(t,e)=>{var n=(0,i.Dt)();"function"==typeof(null==n?void 0:n.addEventListener)&&n.addEventListener(t,e)}},612:function(t,r,e){var n=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0}),r.SessionID=void 0;const i=e(832),u=e(780),l=e(444),a=e(556),c={},d={},h={};function v(t){return"statsig.session_id."+(0,i.DJB2)(t)}r.SessionID={get:t=>null!=h[t]?h[t]:h[t]=r.SessionID.Nt(t),Nt:s=>n(void 0,void 0,void 0,function*(){let e=c[s];var n=Date.now();if(null==e){let t=yield function(t){t=v(t);return(0,l.N)(t)}(s);null==t&&(t={sessionID:(0,a.getUUID)(),startTime:n,lastUpdate:n}),e=t,c[s]=e}var t=null!=(t=d[s])?t:{ageTimeoutID:null,idleTimeoutID:null,emitFunction:()=>{}},i=((144e5<n-e.startTime||18e5<n-e.lastUpdate)&&(e.sessionID=(0,a.getUUID)(),e.startTime=n),e.lastUpdate=n,e),o=s;return o=v(s),(0,l.R)(o,i).catch(()=>{u.Log.warn("Failed to save SessionID")}),t.idleTimeoutID=r.SessionID.kt(t,t.idleTimeoutID,18e5),t.ageTimeoutID=r.SessionID.kt(t,t.ageTimeoutID,144e5-(n-e.startTime)),c[s]=e,d[s]=t,h[s]=null,e.sessionID}),Pt:(t,e)=>{var n=null!=(n=d[e])?n:{ageTimeoutID:null,idleTimeoutID:null,emitFunction:t};n.emitFunction=t,d[e]=n},kt:(t,e,n)=>(clearTimeout(null!=e?e:void 0),setTimeout(t.emitFunction,n))}},604:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.StableID=void 0;const o=n(832),s=n(780),r=n(444),u=n(556),l={};function a(t){return"statsig.stable_id."+(0,o.DJB2)(t)}function c(t,e){e=a(e);(0,r.R)(e,t).catch(()=>{s.Log.warn("Failed to save StableID")})}e.StableID={get:e=>i(void 0,void 0,void 0,function*(){return null==l[e]&&(l[e]=function(t){t=a(t);return(0,r.N)(t)}(e).then(t=>{return null!=t||c(t=(0,u.getUUID)(),e),t})),l[e]}),setOverride:(t,e)=>{l[e]=Promise.resolve(t),c(t,e)}}},688:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.StatsigClientBase=void 0,n(496);const s=n(512),r=n(728),u=n(780),l=n(612),a=n(604),c=n(444);e.StatsigClientBase=class{constructor(t,e,n,i){this.loadingStatus="Uninitialized",this.Rt={},this.h=t,this.J=null!=i?i:{},null!=i&&i.disableStorage&&c.Storage.Ct(!0),null!=i&&i.overrideStableID&&a.StableID.setOverride(i.overrideStableID,t),u.Log.level=null!=(o=null==i?void 0:i.logLevel)?o:u.LogLevel.Warn,this.Gt=null!=(o=null==i?void 0:i.overrideAdapter)?o:null,this.Ft=new r.EventLogger(t,this.St.bind(this),n,i),l.SessionID.Pt(()=>{this.St({name:"session_expired"})},t),this.l=new s.ErrorBoundary(t);var o=null!==__STATSIG__&&void 0!==__STATSIG__?__STATSIG__:{},n=null!=(n=o.instances)?n:{};n[t]=this,o.lastInstance=this,o.instances=n,__STATSIG__=o,this.dataAdapter=e,this.dataAdapter.attach(t,i)}updateRuntimeOptions(t){null!=t.disableLogging&&(this.J.disableLogging=t.disableLogging,this.Ft.setLoggingDisabled(t.disableLogging)),null!=t.disableStorage&&(this.J.disableStorage=t.disableStorage,c.Storage.Ct(t.disableStorage))}flush(){return this.Ft.flush()}shutdown(){return i(this,void 0,void 0,function*(){this.St({name:"pre_shutdown"}),yield this.Ft.shutdown()})}on(t,e){this.Rt[t]||(this.Rt[t]=[]),this.Rt[t].push(e)}off(t,e){this.Rt[t]&&-1!==(e=this.Rt[t].indexOf(e))&&this.Rt[t].splice(e,1)}__on(t,e){e.__isInternal=!0,this.on(t,e)}St(n){var t;const e=e=>{try{e(n)}catch(t){!0===e.__isInternal?this.l.logError("_emit:"+n.name,t):u.Log.error("An error occurred in a StatsigClientEvent listener. This is not an issue with Statsig.",n)}};this.Rt[n.name]&&this.Rt[n.name].forEach(t=>e(t)),null!=(t=this.Rt["*"])&&t.forEach(e)}Lt(t,e){this.loadingStatus=t,this.St({name:"values_updated",status:t,values:e})}Ut(t,e,n){!0===(null==n?void 0:n.disableExposureLog)?this.Ft.incrementNonExposureCount(t):this.Ft.enqueue(e)}}},808:(t,e)=>{$Q(e)},283:(t,e)=>{$Q(e),e.DataAdapterCachePrefix=void 0,e.DataAdapterCachePrefix="statsig.cached"},876:(t,e)=>{$Q(e),e.Jt=e.Kt=e.qt=e.ht=void 0;const n="statsig::config_exposure",i="statsig::gate_exposure",l=(t,e,n,i,o)=>({eventName:t,user:e,value:null,metadata:s(n,i),secondaryExposures:o,time:Date.now()});e.ht=({eventName:t})=>t===i||t===n,e.qt=(t,e)=>{return l(i,t,e.details,{gate:e.name,gateValue:String(e.value),ruleID:e.ruleID},null!=(e=null==(t=e.__evaluation)?void 0:t.secondary_exposures)?e:[])},e.Kt=(t,e)=>{return l(n,t,e.details,{config:e.name,ruleID:e.ruleID},null!=(e=null==(t=e.__evaluation)?void 0:t.secondary_exposures)?e:[])};e.Jt=(t,e,n)=>{var i,o=e.__evaluation,s=!0===(null==(s=null==o?void 0:o.explicit_parameters)?void 0:s.includes(n));let r="",u=null!=(i=null==o?void 0:o.undelegated_secondary_exposures)?i:[];return s&&(r=null!=(i=o.allocated_experiment_name)?i:"",u=o.secondary_exposures),l("statsig::layer_exposure",t,e.details,{config:e.name,parameterName:n,ruleID:e.ruleID,allocatedExperiment:r,isExplicitParameter:String(s)},u)};const s=(t,e)=>(e.reason=t.reason,t.lcut&&(e.lcut=String(t.lcut)),t.receivedAt&&(e.receivedAt=String(t.receivedAt)),e)},972:(t,e)=>{$Q(e),e.StatsigMetadataProvider=e.SDK_VERSION=void 0,e.SDK_VERSION="0.0.1-beta.30";let n={sdkVersion:e.SDK_VERSION,sdkType:"js-mono"};e.StatsigMetadataProvider={get:()=>n,add:t=>{n=$P($P({},n),t)}}},384:(t,e)=>{$Q(e)},396:(t,e)=>{$Q(e),e.Vt=e.zt=e.Bt=e.$t=void 0;const o="default";function s(t,e,n,i){return{name:t,details:e,ruleID:null!=(t=null==n?void 0:n.rule_id)?t:o,__evaluation:n,value:i}}function r(s,r){return(t,e)=>{var n,i,o=null!=(o=null==s?void 0:s[t])?o:null;return null==o||null!=e&&(n=e,(i=t=>Array.isArray(t)?"array":typeof t)(o)!==i(n))?null!=e?e:null:(null!=r&&r(t),o)}}e.$t=function(t,e,n){return s(t,e,n,!0===(null==n?void 0:n.value))},e.Bt=function(t,e,n){return $P($P({},s(t,e,n,null!=(t=null==n?void 0:n.value)?t:{})),{groupName:null,get:r(null==n?void 0:n.value)})},e.zt=function(t,e,n,i){return $P($P({},s(t,e,n,void 0)),{get:r(null==n?void 0:n.value,i),groupName:null!=(t=null==n?void 0:n.group_name)?t:null,__value:null!=(e=null==n?void 0:n.value)?e:{}})},e.Vt=function(t,e,n,i){return $P($P($P({},t),e),{get:r(n,i)})}},136:(t,e)=>{$Q(e)},296:(t,e,n)=>{$Q(e),e.getUnitIDFromUser=e.getUserStorageKey=e.normalizeUser=void 0;const i=n(832);e.normalizeUser=function(t,e){try{var n=JSON.parse(JSON.stringify(t));return null!=e&&(n.statsigEnvironment=e),n}catch(t){throw new Error("User object must be convertable to JSON string.")}},e.getUserStorageKey=function(t,e){return(0,i.DJB2Object)({sdkKey:t,user:e})},e.getUnitIDFromUser=function(t,e){var n;return"string"==typeof e&&"userid"!==e.toLowerCase()?null!=(n=null==(n=t.customIDs)?void 0:n[e])?n:null==(n=null==t?void 0:t.customIDs)?void 0:n[e.toLowerCase()]:t.userID}},444:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})},n=($Q(e),e.R=e.N=e.Storage=void 0,n(780));const o={},s={Ht:()=>"InMemory",A(t){return null!=(t=o[t])?t:null},Wt(t){return Promise.resolve(null!=(t=o[t])?t:null)},M(t,e){return o[t]=e,Promise.resolve()},P(t){return delete o[t],Promise.resolve()},Yt(){return Promise.resolve(Object.keys(o))}};let r=null;try{"undefined"!=typeof window&&"localStorage"in window&&(r={Ht:()=>"LocalStorage",A(t){return localStorage.getItem(t)},Wt(t){return Promise.resolve(localStorage.getItem(t))},M(t,e){return localStorage.setItem(t,e),Promise.resolve()},P(t){return localStorage.removeItem(t),Promise.resolve()},Yt(){var t=Object.keys(localStorage);return Promise.resolve(t)}})}catch(t){n.Log.warn("Failed to setup localStorageProvider.")}let u=null!==r&&void 0!==r?r:s,l=u;e.Storage={Ht:()=>l.Ht(),Wt:t=>l.Wt(t),M:(t,e)=>l.M(t,e),P:t=>l.P(t),Yt:()=>l.Yt(),A:t=>{var e;return null!=(e=null==(e=l.A)?void 0:e.call(l,t))?e:null},Qt:t=>{u=t,l=t},Ct:t=>{l=t?s:u}},e.N=function(e){return i(this,void 0,void 0,function*(){var t=yield l.Wt(e);return JSON.parse(null!=t?t:"null")})},e.R=function(t,e){return i(this,void 0,void 0,function*(){yield l.M(t,JSON.stringify(e))})}},412:(t,e,n)=>{$Q(e),e.typedJsonParse=void 0;const o=n(780);e.typedJsonParse=function(t,e,n){try{var i=JSON.parse(t);return"object"==typeof i&&0 in i,i}catch(t){}return o.Log.error(n),null}},556:(t,e)=>{$Q(e),e.getUUID=void 0,e.getUUID=function(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();let n=(new Date).getTime(),i="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return`xxxxxxxx-xxxx-4xxx-${"89ab"[Math.floor(4*Math.random())]}xxx-xxxxxxxxxxxx`.replace(/[xy]/g,t=>{let e=16*Math.random();return 0<n?(e=(n+e)%16|0,n=Math.floor(n/16)):(e=(i+e)%16|0,i=Math.floor(i/16)),("x"===t?e:7&e|8).toString(16)})}},84:(t,e)=>{$Q(e),e.tt=void 0,e.tt=function(t,e,n,i){return t||(e?""+e+n:""+i+n)}},539:(t,e)=>{$Q(e)},100:(t,e,n)=>{$Q(e),e.Xt=e.nt=e._t=void 0;n=n(48);const i="foreground",o="background",s=[];let r=i;e._t=()=>r===i,e.nt=t=>{s.unshift(t)};e.Xt=e=>{e!==r&&(r=e,s.forEach(t=>t(e)))},(0,n.Mt)("focus",()=>(0,e.Xt)(i)),(0,n.Mt)("blur",()=>(0,e.Xt)(o)),(0,n.Mt)("beforeunload",()=>(0,e.Xt)(o)),(0,n.xt)("visibilitychange",()=>{(0,e.Xt)("visible"===document.visibilityState?i:o)})},464:function(t,e,n){var i=this&&this.__createBinding||(Object.create?function(t,e,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&("get"in o?e.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,o)}:function(t,e,n,i){t[i=void 0===i?n:i]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||i(e,t,n)};$Q(e),e.Log=e.Storage=e.EventLogger=void 0,n(496);const s=n(728),r=(Object.defineProperty(e,"EventLogger",{enumerable:!0,get:function(){return s.EventLogger}}),n(780));Object.defineProperty(e,"Log",{enumerable:!0,get:function(){return r.Log}});var u=n(972);const l=n(444);Object.defineProperty(e,"Storage",{enumerable:!0,get:function(){return l.Storage}});var a=n(556);o(n(496),e),o(n(856),e),o(n(320),e),o(n(184),e),o(n(512),e),o(n(500),e),o(n(788),e),o(n(832),e),o(n(664),e),o(n(780),e),o(n(104),e),o(n(452),e),o(n(188),e),o(n(256),e),o(n(264),e),o(n(48),e),o(n(360),e),o(n(612),e),o(n(604),e),o(n(688),e),o(n(808),e),o(n(283),e),o(n(876),e),o(n(972),e),o(n(384),e),o(n(396),e),o(n(136),e),o(n(296),e),o(n(444),e),o(n(412),e),o(n(84),e),o(n(539),e),o(n(556),e),o(n(100),e),__STATSIG__=$P($P({},null!==__STATSIG__&&void 0!==__STATSIG__?__STATSIG__:{}),{EventLogger:s.EventLogger,Log:r.Log,getUUID:a.getUUID,Storage:l.Storage,SDK_VERSION:u.SDK_VERSION})},696:function(t,e,n){var i=this&&this.__createBinding||(Object.create?function(t,e,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&("get"in o?e.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,o)}:function(t,e,n,i){t[i=void 0===i?n:i]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||i(e,t,n)};$Q(e),o(n(208),e),e.default=__STATSIG__},96:(t,e,n)=>{$Q(e),e.resolveDeltasResponse=void 0;const i=n(464);function o(t,e){null!=t&&t.forEach(t=>{delete e[t]})}e.resolveDeltasResponse=function(t,e){var n;return(e=(0,i.typedJsonParse)(e,"checksum","Failed to parse DeltasEvaluationResponse"))?(t=t,n=e,t=$P($P($P({},t),n),{feature_gates:$P($P({},t.feature_gates),n.feature_gates),layer_configs:$P($P({},t.layer_configs),n.layer_configs),dynamic_configs:$P($P({},t.dynamic_configs),n.dynamic_configs)}),o((t=n=t).deleted_gates,t.feature_gates),delete t.deleted_gates,o(n.deleted_configs,t.dynamic_configs),delete t.deleted_configs,o(n.deleted_layers,t.layer_configs),delete t.deleted_layers,n=t,(t=(0,i.DJB2Object)({feature_gates:n.feature_gates,dynamic_configs:n.dynamic_configs,layer_configs:n.layer_configs}))===e.checksum?JSON.stringify(n):{hadBadDeltaChecksum:!0,badChecksum:t,badMergedConfigs:n,badFullResponse:e.deltas_full_response}):{hadBadDeltaChecksum:!0}}},536:(t,e,n)=>{$Q(e);const i=n(464);e.default=class{constructor(){this.Zt=null,this.te=null,this.ee="Uninitialized",this.ne=0,this.ie=0}getValues(){return this.Zt?(0,i.typedJsonParse)(this.Zt,"has_updates","Failed to parse EvaluationStoreValues"):null}reset(){this.te=null,this.Zt=null,this.ee="Loading",this.ne=0,this.ie=0}finalize(){this.te||(this.ee="NoValues")}setValuesFromDataAdapter(t){var e;t&&!0===(null==(e=(0,i.typedJsonParse)(t.data,"has_updates","Failed to parse EvaluationResponse"))?void 0:e.has_updates)&&(this.Zt=t.data,this.ne=e.time,this.ie=t.receivedAt,this.ee=t.source,this.te=e)}getGate(t){var e,t=null!=(e=null==(e=this.te)?void 0:e.feature_gates[t])?e:null;return this.se(t)}getConfig(t){var e,t=null!=(e=null==(e=this.te)?void 0:e.dynamic_configs[t])?e:null;return this.se(t)}getLayer(t){var e,t=null!=(e=null==(e=this.te)?void 0:e.layer_configs[t])?e:null;return this.se(t)}se(t){return{evaluation:t,details:this.oe(null==t)}}oe(t){return"Uninitialized"===this.ee||"NoValues"===this.ee?{reason:this.ee}:{reason:this.ee+":"+(t?"Unrecognized":"Recognized"),lcut:this.ne,receivedAt:this.ie}}}},400:function(t,e,n){var s=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e);const r=n(464),u=n(96);class i extends r.NetworkCore{constructor(t,e){super(t,e);e=null==t?void 0:t.networkConfig;this.re=(0,r.tt)(null==e?void 0:e.initializeUrl,null==e?void 0:e.api,"/initialize",r.NetworkDefault.initializeApi)}fetchEvaluations(n,i,o){return s(this,void 0,void 0,function*(){var t=i?(0,r.typedJsonParse)(i,"has_updates","Failed to parse cached EvaluationResponse"):null;let e={user:o,hash:"djb2",deltasResponseRequested:!1};return null!=t&&t.has_updates&&(e=$P($P({},e),{sinceTime:t.time,previousDerivedFields:"derived_fields"in t?t.derived_fields:{},deltasResponseRequested:!0})),this.ue(n,t,e)})}ue(e,n,i){var o;return s(this,void 0,void 0,function*(){var t=yield this.post({sdkKey:e,url:this.re,data:i,retries:2,isStatsigEncodable:!0});return 204===(null==t?void 0:t.code)?'{"has_updates": false}':200!==(null==t?void 0:t.code)?null!=(o=null==t?void 0:t.body)?o:null:!0!==(null==n?void 0:n.has_updates)||!0!==(null==(o=t.body)?void 0:o.includes('"is_delta":true'))?t.body:"string"==typeof(t=(0,u.resolveDeltasResponse)(n,t.body))?t:this.ue(e,n,$P($P($P({},i),t),{deltasResponseRequested:!1}))})}}e.default=i},520:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e);const r=n(464),o=n(536),s=n(400),u=n(364);class l extends r.StatsigClientBase{constructor(t,e,n=null){r.SDKType.It(t,"javascript-client");var i=new s.default(n,t=>{this.St(t)});super(t,null!=(t=null==n?void 0:n.dataAdapter)?t:new u.StatsigEvaluationsDataAdapter,i,n),(0,r.monitorClass)(this.l,this),(0,r.monitorClass)(this.l,i),this.le=new o.default,this.ae=e}static instance(t){var e,n=(0,r.i)();return t?null==(e=n.instances)?void 0:e[t]:n.lastInstance}initializeSync(){this.updateUserSync(this.ae)}initializeAsync(){return this.updateUserAsync(this.ae)}updateUserSync(t){this.ce(t);t=this.dataAdapter.getDataSync(this.ae);this.le.setValuesFromDataAdapter(t),this.le.finalize(),this.Lt("Ready",t),this.de(null!=t?t:null,this.ae)}updateUserAsync(n){return i(this,void 0,void 0,function*(){this.ce(n);var t=this.ae,e=this.dataAdapter.getDataSync(t);this.Lt("Loading",e),this.le.setValuesFromDataAdapter(e),e=yield this.dataAdapter.getDataAsync(e,t),t===this.ae&&this.le.setValuesFromDataAdapter(e),this.le.finalize(),this.Lt("Ready",e)})}getContext(){return{sdkKey:this.h,options:this.J,values:this.le.getValues(),user:JSON.parse(JSON.stringify(this.ae))}}getAsyncContext(){return i(this,void 0,void 0,function*(){return $P($P({},this.getContext()),{sessionID:yield r.SessionID.get(this.h),stableID:yield r.StableID.get(this.h)})})}checkGate(t,e){return this.getFeatureGate(t,e).value}getFeatureGate(t,e){var n=(0,r.DJB2)(t),{evaluation:n,details:i}=this.le.getGate(n),i=(0,r.$t)(t,i,n),o=null==(o=null==(n=this.Gt)?void 0:n.getGateOverride)?void 0:o.call(n,i,this.ae,e),n=null!=o?o:i;return this.Ut(t,(0,r.qt)(this.ae,n),e),this.St({name:"gate_evaluation",gate:n}),n}getDynamicConfig(t,e){t=this.he("dynamic_config",t,e);return this.St({name:"dynamic_config_evaluation",dynamicConfig:t}),t}getExperiment(t,e){t=this.he("experiment",t,e);return this.St({name:"experiment_evaluation",experiment:t}),t}getLayer(e,n){var t=(0,r.DJB2)(e),{evaluation:t,details:i}=this.le.getLayer(t),i=(0,r.zt)(e,i,t),o=null==(o=null==(t=this.Gt)?void 0:t.getLayerOverride)?void 0:o.call(t,i,this.ae,n);const s=(0,r.Vt)(i,o,null!=(t=null==o?void 0:o.__value)?t:i.__value,t=>{this.Ut(e,(0,r.Jt)(this.ae,s,t),n)});return this.St({name:"layer_evaluation",layer:s}),s}logEvent(t,e,n){this.Ft.enqueue($P($P({},"string"==typeof t?{eventName:t,value:e,metadata:n}:t),{user:this.ae,time:Date.now()}))}de(t,e){this.dataAdapter.getDataAsync(t,e).catch(t=>{r.Log.error("An error occurred after update.",t)})}ce(t){this.Ft.reset(),this.le.reset(),this.ae=(0,r.normalizeUser)(t,this.J.environment)}he(t,e,n){var i=(0,r.DJB2)(e),{evaluation:i,details:o}=this.le.getConfig(i),o=(0,r.Bt)(e,o,i),i="experiment"===t?null==(t=null==(i=this.Gt)?void 0:i.getExperimentOverride)?void 0:t.call(i,o,this.ae,n):null==(i=null==(t=this.Gt)?void 0:t.getDynamicConfigOverride)?void 0:i.call(t,o,this.ae,n),t=null!=i?i:o;return this.Ut(e,(0,r.Kt)(this.ae,t),n),t}}e.default=l},364:function(t,e,n){var o=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})},i=($Q(e),e.StatsigEvaluationsDataAdapter=void 0,n(464));const s=n(400);class r extends i.DataAdapterCore{constructor(){super("EvaluationsDataAdapter","evaluations"),this.U=null}attach(t,e){super.attach(t,e),this.U=new s.default(null!=e?e:{})}T(e,n){var i;return o(this,void 0,void 0,function*(){var t=yield null==(i=this.U)?void 0:i.fetchEvaluations(this.I(),e,n);return null!=t?t:null})}}e.StatsigEvaluationsDataAdapter=r},208:(t,e,n)=>{$Q(e),e.StatsigClient=e.StatsigEvaluationsDataAdapter=void 0;var i=n(520);e.StatsigClient=i.default;const o=n(364);Object.defineProperty(e,"StatsigEvaluationsDataAdapter",{enumerable:!0,get:function(){return o.StatsigEvaluationsDataAdapter}}),__STATSIG__=$P($P({},null!==__STATSIG__&&void 0!==__STATSIG__?__STATSIG__:{}),{StatsigEvaluationsDataAdapter:o.StatsigEvaluationsDataAdapter,StatsigClient:i.default,instance:i.default.instance}),e.default=__STATSIG__}},i={};function o(t){var e=i[t];return void 0!==e||(e=i[t]={exports:{}},n[t].call(e.exports,e,e.exports,o)),e.exports}return o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o(696).default})());
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Statsig=e():t.Statsig=e()}(this,()=>(()=>{"use strict";var $Q=(e)=>Object.defineProperty(e,"__esModule",{value:!0});var $P = (a,b) => Object.assign(a,b);var n={496:(t,e,n)=>{$Q(e),e.st=e.i=void 0,e.i=()=>null!==__STATSIG__&&void 0!==__STATSIG__?__STATSIG__:u;e.st=t=>{var e;return t?null==(e=null===__STATSIG__||void 0===__STATSIG__?void 0:__STATSIG__.instances)?void 0:e[t]:null===__STATSIG__||void 0===__STATSIG__?void 0:__STATSIG__.lastInstance};var i,o="__STATSIG__",s="undefined"!=typeof window?window:{},n=void 0!==n.g?n.g:{},r="undefined"!=typeof globalThis?globalThis:{};const u=null!=(i=null!=(i=null!=(i=s[o])?i:n[o])?i:r[o])?i:{instance:e.st};s[o]=u,n[o]=u,r[o]=u},856:(t,e)=>{$Q(e)},320:function(t,e,n){var s=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.DataAdapterCore=void 0;const i=n(512),o=n(780),r=n(104),u=n(283),l=n(296),a=n(444),c=n(412);e.DataAdapterCore=class{constructor(t,e){this.o=t,this.u=e,this.l=null,this.h=null,this.v={},this._="statsig.last_modified_time."+e}attach(t,e){this.h=t,this.l=new i.ErrorBoundary(t),(0,r.monitorClass)(this.l,this)}getDataSync(t){var t=this.m(t),e=this.v[t];return e||((e=this.p(t))?(this.S(t,e),this.v[t]):null)}getDataAsync(n,i){var o;return s(this,void 0,void 0,function*(){var t=null!=n?n:this.getDataSync(i),t=yield this.O(null!=(o=null==t?void 0:t.data)?o:null,i),e=this.m(i);return t&&this.S(e,t),"Network"!==(null==t?void 0:t.source)&&"NetworkNotModified"!==(null==t?void 0:t.source)||(yield this.j(e,t)),t})}prefetchData(n){return s(this,void 0,void 0,function*(){var t=this.m(n),e=yield this.getDataAsync(null,n);e&&this.S(t,$P($P({},e),{source:"Prefetch"}))})}setData(t,e){e=this.m(e);this.S(e,{source:"Bootstrap",data:t,receivedAt:Date.now()})}__primeInMemoryCache(t){this.v=$P($P({},this.v),t)}O(n,i){return s(this,void 0,void 0,function*(){var t,e=yield this.T(n,i);return e?(t=(0,c.typedJsonParse)(e,"has_updates","Failure while attempting to persist latest value"),n&&!1===(null==t?void 0:t.has_updates)?{source:"NetworkNotModified",data:n,receivedAt:Date.now()}:!0!==(null==t?void 0:t.has_updates)?null:{source:"Network",data:e,receivedAt:Date.now()}):(o.Log.debug("No response returned for latest value"),null)})}I(){return null!=this.h?this.h:(o.Log.error(this.o+" is not attached to a Client"),"")}m(t){t=(0,l.getUserStorageKey)(this.I(),t);return`${u.DataAdapterCachePrefix}.${this.u}.`+t}S(t,e){var n=Object.entries(this.v);n.length<10||([n]=n.reduce((t,e)=>e[1]<t[1]?e:t),delete this.v[n]),this.v[t]=e}p(t){var e=null==(e=a.Storage.A)?void 0:e.call(a.Storage,t);return null!=e&&(t=(0,c.typedJsonParse)(e,"source","Failed to parse cached result"))?$P($P({},t),{source:"Cache"}):null}j(t,e){return s(this,void 0,void 0,function*(){yield a.Storage.M(t,JSON.stringify(e)),yield this.D(t)})}D(n){var i;return s(this,void 0,void 0,function*(){var t=null!=(i=yield(0,a.N)(this._))?i:{},e=(t[n]=Date.now(),Object.entries(t));e.length<=10||(delete t[(e=e.reduce((t,e)=>e[1]<t[1]?e:t))[0]],yield a.Storage.P(e[0])),yield(0,a.R)(this._,t)})}}},280:(t,e,n)=>{$Q(e),e.Diagnostics=e.captureDiagnostics=void 0;const i=n(780),o=n(256),s="undefined"!=typeof performance&&void 0!==performance.mark;let r=[];e.captureDiagnostics=function(t,e){u.mark(t+":start"),e=e();const n=()=>{u.mark(t+":end"),(t+":end").startsWith("initialize:")&&u.flush()};return e&&e instanceof Promise?e.finally(()=>n()):(n(),e)};class u{static mark(t,e){s&&(t=performance.mark(t,{detail:e}),r.push(t))}static flush(){var t=performance.getEntriesByType("resource").filter(t=>t.name.startsWith(o.NetworkDefault.initializeApi)||t.name.startsWith(o.NetworkDefault.specsApi)||t.name.startsWith(o.NetworkDefault.eventsApi)),t={markers:r,resources:t};i.Log.debug("Diagnostics",t,JSON.stringify(t)),r=[]}}e.Diagnostics=u},184:(t,e)=>{$Q(e)},512:function(t,l,e){var n=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};Object.defineProperty(l,"__esModule",{value:!0}),l.ErrorBoundary=l.EXCEPTION_ENDPOINT=void 0;const i=e(780),a=e(360),c=e(972);l.EXCEPTION_ENDPOINT="https://statsigapi.net/v1/sdk_exception";l.ErrorBoundary=class{constructor(t){this.h=t,this.C=new Set}capture(e,t,n){try{var i=t();return i&&i instanceof Promise?i.catch(t=>this.G(e,t,n)):i}catch(t){return this.G(e,t,n),null}}logError(t,e){this.G(t,e)}G(s,r,u){try{i.Log.warn("Caught error in "+s,{error:r});n(this,void 0,void 0,function*(){var t,e,n=null!=r?r:Error("[Statsig] Error was empty"),i=n instanceof Error,o=i?n.name:"No Name";this.C.has(o)||(this.C.add(o),t=a.SDKType.F(this.h),e=c.StatsigMetadataProvider.get(),i=i?n.stack:function(t){try{return JSON.stringify(t)}catch(t){return"[Statsig] Failed to get string for error."}}(n),n=JSON.stringify($P({tag:s,exception:o,info:i},$P($P({},e),{sdkType:t}))),yield fetch(l.EXCEPTION_ENDPOINT,{method:"POST",headers:{"STATSIG-API-KEY":this.h,"STATSIG-SDK-TYPE":String(t),"STATSIG-SDK-VERSION":String(e.sdkVersion),"Content-Type":"application/json"},body:n}),null!=u&&u({name:"error",error:r}))}).then(()=>{}).catch(()=>{})}catch(t){}}}},500:(t,e)=>{$Q(e)},788:(t,e)=>{$Q(e)},728:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.EventLogger=void 0;const o=n(832),s=n(780),r=n(256),u=n(452),l=n(876),a=n(444),c=n(412),d=n(84),h=n(100);e.EventLogger=class{constructor(t,e,n,i){this.h=t,this.L=e,this.U=n,this.J=i,this.K=[],this.q={},this.V={},this.B=!1,this.$=Date.now(),this.H=!0===(null==i?void 0:i.disableLogging),this.W=null!=(t=null==i?void 0:i.loggingBufferMaxSize)?t:50;n=null!=(e=null==i?void 0:i.loggingIntervalMs)?e:1e4,this.Y=setInterval(()=>this.X(),n),t=null==i?void 0:i.networkConfig;this.Z=(0,d.tt)(null==t?void 0:t.logEventUrl,null==t?void 0:t.api,"/rgstr",r.NetworkDefault.eventsApi),this.et=(0,d.tt)(null==t?void 0:t.logEventBeaconUrl,null==t?void 0:t.api,"/log_event_beacon",r.NetworkDefault.eventsApi),(0,h.nt)(this.it.bind(this)),this.ot()}setLoggingDisabled(t){this.H=t}enqueue(t){this.rt(t)&&(this.ut(t),this.lt(),this.K.length>this.W)&&this.X()}incrementNonExposureCount(t){var e=null!=(e=this.V[t])?e:0;this.V[t]=e+1}reset(){this.q={}}shutdown(){return i(this,void 0,void 0,function*(){this.Y&&(clearInterval(this.Y),this.Y=null),yield this.flush()})}flush(){return i(this,void 0,void 0,function*(){var t;this.ct(),0!==this.K.length&&(t=this.K,this.K=[],yield this.dt(t))})}it(t){"background"===t&&this.X()}lt(){this.B||(this.B=!0,200<Date.now()-this.$)||setTimeout(()=>this.X(),200)}rt(t){if((0,l.ht)(t)){var t=[t.eventName,null==(e=t.user)?void 0:e.userID,null==(e=t.metadata)?void 0:e.gate,null==(e=t.metadata)?void 0:e.config,null==(e=t.metadata)?void 0:e.ruleID].join("|"),e=this.q[t],n=Date.now();if(e&&n-e<6e4)return!1;1e3<Object.keys(this.q).length&&(this.q={}),this.q[t]=n}return!0}X(){this.flush().catch(()=>{})}dt(t){return i(this,void 0,void 0,function*(){if(this.H)this.vt(t);else try{(!(0,h._t)()&&this.U.isBeaconSupported()?yield this.ft(t):yield this.gt(t)).success?this.L({name:"logs_flushed",events:t}):this.vt(t)}catch(t){s.Log.warn("Failed to flush events.")}})}gt(e){return i(this,void 0,void 0,function*(){var t=yield this.U.post({sdkKey:this.h,data:{events:e},url:this.Z,retries:3,params:{[u.NetworkParam.EventCount]:String(e.length)}}),t=null!=t&&t.body?(0,c.typedJsonParse)(t.body,"success","Failed to parse SendEventsResponse"):null;return{success:!0===(null==t?void 0:t.success)}})}ft(t){return i(this,void 0,void 0,function*(){return{success:yield this.U.beacon({sdkKey:this.h,data:{events:t},url:this.et})}})}vt(t){for(;500<t.length;)t.shift();var e=this.bt();(0,a.R)(e,t).catch(()=>{s.Log.warn("Unable to save failed logs to storage")})}ot(){const e=this.bt();i(this,void 0,void 0,function*(){var t=yield(0,a.N)(e);t&&(yield a.Storage.P(e),yield this.dt(t))}).catch(()=>{s.Log.warn("Failed to flush stored logs")})}bt(){return"statsig.failed_logs."+(0,o.DJB2)(this.h)}ut(t){t.user&&(t.user=$P({},t.user),delete t.user.privateAttributes);var e={},n=this.yt();n&&(e.statsigMetadata={currentPage:n}),this.K.push($P($P({},t),e))}ct(){0!==Object.keys(this.V).length&&(this.ut({eventName:"statsig::non_exposed_checks",user:null,time:Date.now(),metadata:{checks:$P({},this.V)}}),this.V={})}yt(){var t;if(!1!==(null==(t=this.J)?void 0:t.includeCurrentPageUrlWithEvents)&&"undefined"!=typeof window&&"object"==typeof window.location)try{return window.location.href.split(/[?#]/)[0]}catch(t){}}}},832:(t,e)=>{$Q(e),e.DJB2Object=e.DJB2=void 0;e.DJB2=e=>{let n=0;for(let t=0;t<e.length;t++){var i=e.charCodeAt(t);n=(n<<5)-n+i,n&=n}return String(n>>>0)};e.DJB2Object=t=>(0,e.DJB2)(JSON.stringify(o(t)));const o=n=>{if(null==n)return null;var t=Object.keys(n).sort();const i={};return t.forEach(t=>{let e=n[t];e instanceof Object&&(e=o(e)),i[t]=e}),i}},664:(t,e)=>{$Q(e)},780:(t,e)=>{function n(t){return t.unshift("[Statsig]"),t}var i,o;$Q(e),e.Log=e.LogLevel=void 0,(o=i||(e.LogLevel=i={}))[o.None=0]="None",o[o.Error=1]="Error",o[o.Warn=2]="Warn",o[o.Info=3]="Info",o[o.Debug=4]="Debug";class s{static info(...t){this.level>=i.Info&&console.info(...n(t))}static debug(...t){this.level>=i.Debug&&console.debug(...n(t))}static warn(...t){this.level>=i.Warn&&console.warn(...n(t))}static error(...t){this.level>=i.Error&&console.error(...n(t))}}(e.Log=s).level=i.Error},104:(t,e,n)=>{$Q(e),e.monitorClass=void 0;const s=n(280),r=n(688);function c(t,e,n,i){var o=i instanceof r.StatsigClientBase?i.St.bind(i):void 0;return t.capture(e,()=>(0,s.captureDiagnostics)(e,()=>n.apply(i)),o)}function d(t){return"object"==typeof t&&(t=Object.getPrototypeOf(t))&&"object"==typeof t?t:null}e.monitorClass=function(e,t){try{{var n=e;var i=t;var o;const s=i;for(const r of function(t){const e=new Set;let n=d(t);for(;n&&n!==Object.prototype;)Object.getOwnPropertyNames(n).filter(t=>"function"==typeof(null===n||void 0===n?void 0:n[t])).forEach(t=>e.add(t)),n=Object.getPrototypeOf(n);return Array.from(e)}(s))if("constructor"!==r){const u=s[r];s[r]=function(...t){return c(n,r,()=>u.apply(this,t),i)}}for(const l of function(t){const e=new Set,n=d(t);return Object.getOwnPropertyNames((null===n||void 0===n?void 0:n.constructor)||{}).filter(t=>{var e;return"caller"!==t&&"arguments"!==t&&"callee"!==t&&"function"==typeof(null==(e=null===n||void 0===n?void 0:n.constructor)?void 0:e[t])}).forEach(t=>e.add(t)),Array.from(e)}(s)){const a=null==(o=null===s||void 0===s?void 0:s.constructor)?void 0:o[l];(null===s||void 0===s?void 0:s.constructor)[l]=function(...t){return c(n,s.constructor.name+"."+l,()=>a.apply(s.constructor,t),i)}}return}}catch(t){e.logError("monitorClass",t)}}},188:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.NetworkCore=void 0,n(496);const h=n(280),v=n(780),o=n(452),s=n(360),r=n(612),u=n(604),l=n(972);e.NetworkCore=class{constructor(t,e){this.J=t,this.L=e,this.Ot=null!=(t=null==(e=null==t?void 0:t.networkConfig)?void 0:e.networkTimeoutMs)?t:1e4}post(e){return i(this,void 0,void 0,function*(){var t=yield this.jt(e);return this.Tt($P({method:"POST",body:this.t(e,t)},e))})}get(t){return this.Tt($P({method:"GET"},t))}isBeaconSupported(){return"undefined"!=typeof navigator&&"function"==typeof(null===navigator||void 0===navigator?void 0:navigator.sendBeacon)}beacon(n){return i(this,void 0,void 0,function*(){var t,e;return!!f(n)&&(t=yield this.wt(n),e=yield this.jt(n),navigator.sendBeacon(t,e))})}Tt(c){var d;return i(this,void 0,void 0,function*(){if(!f(c))return null;var{method:e,body:n,retries:i}=c;const o=new AbortController;var t,s,r,u=setTimeout(()=>o.abort(`Timeout of ${this.Ot}ms expired.`),this.Ot),l=yield this.wt(c);let a=null;try{if(a=yield fetch(l,{method:e,body:n,headers:$P({},c.headers),signal:o.signal}),clearTimeout(u),a.ok)return r=yield a.text(),h.Diagnostics.mark("_sendRequest:response-received",{status:a.status,contentLength:a.headers.get("content-length")}),{body:r,code:a.status};throw t=yield a.text().catch(()=>"No Text"),(s=new Error(`Failed to fetch: ${l} `+t)).name="NetworkError",s}catch(t){n=function(t,e){if(t.signal.aborted&&"string"==typeof t.signal.reason)return t.signal.reason;if("string"==typeof e)return e;if(e instanceof Error)return e.name+": "+e.message;return null}(o,t);return h.Diagnostics.mark("_sendRequest:error",{error:n,status:null===a||void 0===a?void 0:a.status,contentLength:null===a||void 0===a?void 0:a.headers.get("content-length")}),!i||i<=0?(null!=(d=this.L)&&d.call(this,{name:"error",error:t}),v.Log.error(`A networking error occured during ${e} request to ${l}.`,n,t),null):this.Tt($P($P({},c),{retries:i-1}))}})}wt(e){return i(this,void 0,void 0,function*(){var t=$P({[o.NetworkParam.SdkKey]:e.sdkKey,[o.NetworkParam.SdkType]:s.SDKType.F(e.sdkKey),[o.NetworkParam.SdkVersion]:l.SDK_VERSION,[o.NetworkParam.Time]:String(Date.now()),[o.NetworkParam.SessionID]:yield r.SessionID.get(e.sdkKey)},e.params),t=Object.entries(t).map(([t,e])=>encodeURIComponent(t)+"="+encodeURIComponent(e)).join("&");return e.url+(t?"?"+t:"")})}jt(o){return i(this,void 0,void 0,function*(){var{data:t,sdkKey:e}=o,n=yield u.StableID.get(e),i=yield r.SessionID.get(e),e=s.SDKType.F(e);return JSON.stringify($P($P({},t),{statsigMetadata:$P($P({},l.StatsigMetadataProvider.get()),{stableID:n,sessionID:i,sdkType:e})}))})}t(t,e){var n;return!(null!=(null===__STATSIG__||void 0===__STATSIG__?void 0:__STATSIG__["no-encode"])||null!=(n=this.J)&&n.disableStatsigEncoding)&&t.isStatsigEncodable&&"undefined"!=typeof window&&window.btoa&&(t.params=$P($P({},null!=(n=t.params)?n:{}),{[o.NetworkParam.StatsigEncoded]:"1"}),null!=(t=window.btoa(e).split("").reverse().join("")))?t:e}};const f=t=>!!t.sdkKey||(v.Log.warn("Unable to make request without an SDK key"),!1)},256:(t,e)=>{$Q(e),e.NetworkDefault=void 0,e.NetworkDefault={eventsApi:"https://events.statsigapi.net/v1",initializeApi:"https://featuregates.org/v1",specsApi:"https://api.statsigcdn.com/v1"}},452:(t,e)=>{$Q(e),e.NetworkParam=void 0,e.NetworkParam={EventCount:"ec",SdkKey:"k",SdkType:"st",SdkVersion:"sv",Time:"t",SessionID:"sid",StatsigEncoded:"se"}},264:(t,e)=>{$Q(e)},360:(t,e)=>{$Q(e),e.SDKType=void 0;const n={};let i;e.SDKType={F:t=>{return(null!=(t=n[t])?t:"js-mono")+(null!==i&&void 0!==i?i:"")},It(t,e){n[t]=e},At(t){i&&"-react"!==i||(i="-"+t)}}},48:(t,i)=>{Object.defineProperty(i,"__esModule",{value:!0}),i.xt=i.Mt=i.Dt=i.Et=void 0;i.Et=()=>"undefined"!=typeof window?window:null,i.Dt=()=>{var t=(0,i.Et)();return null!=(t=null==t?void 0:t.document)?t:null},i.Mt=(t,e)=>{var n=(0,i.Et)();"function"==typeof(null==n?void 0:n.addEventListener)&&n.addEventListener(t,e)};i.xt=(t,e)=>{var n=(0,i.Dt)();"function"==typeof(null==n?void 0:n.addEventListener)&&n.addEventListener(t,e)}},612:function(t,r,e){var n=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};Object.defineProperty(r,"__esModule",{value:!0}),r.SessionID=void 0;const i=e(832),u=e(780),l=e(444),a=e(556),c={},d={},h={};function v(t){return"statsig.session_id."+(0,i.DJB2)(t)}r.SessionID={get:t=>null!=h[t]?h[t]:h[t]=r.SessionID.Nt(t),Nt:s=>n(void 0,void 0,void 0,function*(){let e=c[s];var n=Date.now();if(null==e){let t=yield function(t){t=v(t);return(0,l.N)(t)}(s);null==t&&(t={sessionID:(0,a.getUUID)(),startTime:n,lastUpdate:n}),e=t,c[s]=e}var t=null!=(t=d[s])?t:{ageTimeoutID:null,idleTimeoutID:null,emitFunction:()=>{}},i=((144e5<n-e.startTime||18e5<n-e.lastUpdate)&&(e.sessionID=(0,a.getUUID)(),e.startTime=n),e.lastUpdate=n,e),o=s;return o=v(s),(0,l.R)(o,i).catch(()=>{u.Log.warn("Failed to save SessionID")}),t.idleTimeoutID=r.SessionID.kt(t,t.idleTimeoutID,18e5),t.ageTimeoutID=r.SessionID.kt(t,t.ageTimeoutID,144e5-(n-e.startTime)),c[s]=e,d[s]=t,h[s]=null,e.sessionID}),Pt:(t,e)=>{var n=null!=(n=d[e])?n:{ageTimeoutID:null,idleTimeoutID:null,emitFunction:t};n.emitFunction=t,d[e]=n},kt:(t,e,n)=>(clearTimeout(null!=e?e:void 0),setTimeout(t.emitFunction,n))}},604:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.StableID=void 0;const o=n(832),s=n(780),r=n(444),u=n(556),l={};function a(t){return"statsig.stable_id."+(0,o.DJB2)(t)}function c(t,e){e=a(e);(0,r.R)(e,t).catch(()=>{s.Log.warn("Failed to save StableID")})}e.StableID={get:e=>i(void 0,void 0,void 0,function*(){return null==l[e]&&(l[e]=function(t){t=a(t);return(0,r.N)(t)}(e).then(t=>{return null!=t||c(t=(0,u.getUUID)(),e),t})),l[e]}),setOverride:(t,e)=>{l[e]=Promise.resolve(t),c(t,e)}}},688:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e),e.StatsigClientBase=void 0,n(496);const s=n(496),r=n(512),u=n(728),l=n(780),a=n(612),c=n(604),d=n(444);e.StatsigClientBase=class{constructor(t,e,n,i){this.loadingStatus="Uninitialized",this.Rt={},this.h=t,this.J=null!=i?i:{},null!=i&&i.disableStorage&&d.Storage.Ct(!0),null!=i&&i.overrideStableID&&c.StableID.setOverride(i.overrideStableID,t),l.Log.level=null!=(o=null==i?void 0:i.logLevel)?o:l.LogLevel.Warn,this.Gt=null!=(o=null==i?void 0:i.overrideAdapter)?o:null,this.Ft=new u.EventLogger(t,this.St.bind(this),n,i),a.SessionID.Pt(()=>{this.St({name:"session_expired"})},t),this.l=new r.ErrorBoundary(t);var o=(0,s.i)(),n=null!=(n=o.instances)?n:{};null!=n[t]&&l.Log.warn("Creating multiple Statsig clients with the same SDK key can lead to unexpected behavior. Multi-instance support requires different SDK keys.");n[t]=this,o.lastInstance=this,o.instances=n,__STATSIG__=o,this.dataAdapter=e,this.dataAdapter.attach(t,i)}updateRuntimeOptions(t){null!=t.disableLogging&&(this.J.disableLogging=t.disableLogging,this.Ft.setLoggingDisabled(t.disableLogging)),null!=t.disableStorage&&(this.J.disableStorage=t.disableStorage,d.Storage.Ct(t.disableStorage))}flush(){return this.Ft.flush()}shutdown(){return i(this,void 0,void 0,function*(){this.St({name:"pre_shutdown"}),yield this.Ft.shutdown()})}on(t,e){this.Rt[t]||(this.Rt[t]=[]),this.Rt[t].push(e)}off(t,e){this.Rt[t]&&-1!==(e=this.Rt[t].indexOf(e))&&this.Rt[t].splice(e,1)}__on(t,e){e.__isInternal=!0,this.on(t,e)}St(n){var t;const e=e=>{try{e(n)}catch(t){!0===e.__isInternal?this.l.logError("_emit:"+n.name,t):l.Log.error("An error occurred in a StatsigClientEvent listener. This is not an issue with Statsig.",n)}};this.Rt[n.name]&&this.Rt[n.name].forEach(t=>e(t)),null!=(t=this.Rt["*"])&&t.forEach(e)}Lt(t,e){this.loadingStatus=t,this.St({name:"values_updated",status:t,values:e})}Ut(t,e,n){!0===(null==n?void 0:n.disableExposureLog)?this.Ft.incrementNonExposureCount(t):this.Ft.enqueue(e)}}},808:(t,e)=>{$Q(e)},283:(t,e)=>{$Q(e),e.DataAdapterCachePrefix=void 0,e.DataAdapterCachePrefix="statsig.cached"},876:(t,e)=>{$Q(e),e.Jt=e.Kt=e.qt=e.ht=void 0;const n="statsig::config_exposure",i="statsig::gate_exposure",l=(t,e,n,i,o)=>({eventName:t,user:e,value:null,metadata:s(n,i),secondaryExposures:o,time:Date.now()});e.ht=({eventName:t})=>t===i||t===n,e.qt=(t,e)=>{return l(i,t,e.details,{gate:e.name,gateValue:String(e.value),ruleID:e.ruleID},null!=(e=null==(t=e.__evaluation)?void 0:t.secondary_exposures)?e:[])},e.Kt=(t,e)=>{return l(n,t,e.details,{config:e.name,ruleID:e.ruleID},null!=(e=null==(t=e.__evaluation)?void 0:t.secondary_exposures)?e:[])};e.Jt=(t,e,n)=>{var i,o=e.__evaluation,s=!0===(null==(s=null==o?void 0:o.explicit_parameters)?void 0:s.includes(n));let r="",u=null!=(i=null==o?void 0:o.undelegated_secondary_exposures)?i:[];return s&&(r=null!=(i=o.allocated_experiment_name)?i:"",u=o.secondary_exposures),l("statsig::layer_exposure",t,e.details,{config:e.name,parameterName:n,ruleID:e.ruleID,allocatedExperiment:r,isExplicitParameter:String(s)},u)};const s=(t,e)=>(e.reason=t.reason,t.lcut&&(e.lcut=String(t.lcut)),t.receivedAt&&(e.receivedAt=String(t.receivedAt)),e)},972:(t,e)=>{$Q(e),e.StatsigMetadataProvider=e.SDK_VERSION=void 0,e.SDK_VERSION="0.0.1-beta.31";let n={sdkVersion:e.SDK_VERSION,sdkType:"js-mono"};e.StatsigMetadataProvider={get:()=>n,add:t=>{n=$P($P({},n),t)}}},384:(t,e)=>{$Q(e)},396:(t,e)=>{$Q(e),e.Vt=e.zt=e.Bt=e.$t=void 0;const o="default";function s(t,e,n,i){return{name:t,details:e,ruleID:null!=(t=null==n?void 0:n.rule_id)?t:o,__evaluation:n,value:i}}function r(s,r){return(t,e)=>{var n,i,o=null!=(o=null==s?void 0:s[t])?o:null;return null==o||null!=e&&(n=e,(i=t=>Array.isArray(t)?"array":typeof t)(o)!==i(n))?null!=e?e:null:(null!=r&&r(t),o)}}e.$t=function(t,e,n){return s(t,e,n,!0===(null==n?void 0:n.value))},e.Bt=function(t,e,n){return $P($P({},s(t,e,n,null!=(t=null==n?void 0:n.value)?t:{})),{groupName:null,get:r(null==n?void 0:n.value)})},e.zt=function(t,e,n,i){return $P($P({},s(t,e,n,void 0)),{get:r(null==n?void 0:n.value,i),groupName:null!=(t=null==n?void 0:n.group_name)?t:null,__value:null!=(e=null==n?void 0:n.value)?e:{}})},e.Vt=function(t,e,n,i){return $P($P($P({},t),e),{get:r(n,i)})}},136:(t,e)=>{$Q(e)},296:(t,e,n)=>{$Q(e),e.getUnitIDFromUser=e.getUserStorageKey=e.normalizeUser=void 0;const i=n(832);e.normalizeUser=function(t,e){try{var n=JSON.parse(JSON.stringify(t));return null!=e&&(n.statsigEnvironment=e),n}catch(t){throw new Error("User object must be convertable to JSON string.")}},e.getUserStorageKey=function(t,e){return(0,i.DJB2Object)({sdkKey:t,user:e})},e.getUnitIDFromUser=function(t,e){var n;return"string"==typeof e&&"userid"!==e.toLowerCase()?null!=(n=null==(n=t.customIDs)?void 0:n[e])?n:null==(n=null==t?void 0:t.customIDs)?void 0:n[e.toLowerCase()]:t.userID}},444:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})},n=($Q(e),e.R=e.N=e.Storage=void 0,n(780));const o={},s={Ht:()=>"InMemory",A(t){return null!=(t=o[t])?t:null},Wt(t){return Promise.resolve(null!=(t=o[t])?t:null)},M(t,e){return o[t]=e,Promise.resolve()},P(t){return delete o[t],Promise.resolve()},Yt(){return Promise.resolve(Object.keys(o))}};let r=null;try{"undefined"!=typeof window&&"localStorage"in window&&(r={Ht:()=>"LocalStorage",A(t){return localStorage.getItem(t)},Wt(t){return Promise.resolve(localStorage.getItem(t))},M(t,e){return localStorage.setItem(t,e),Promise.resolve()},P(t){return localStorage.removeItem(t),Promise.resolve()},Yt(){var t=Object.keys(localStorage);return Promise.resolve(t)}})}catch(t){n.Log.warn("Failed to setup localStorageProvider.")}let u=null!==r&&void 0!==r?r:s,l=u;e.Storage={Ht:()=>l.Ht(),Wt:t=>l.Wt(t),M:(t,e)=>l.M(t,e),P:t=>l.P(t),Yt:()=>l.Yt(),A:t=>{var e;return null!=(e=null==(e=l.A)?void 0:e.call(l,t))?e:null},Qt:t=>{u=t,l=t},Ct:t=>{l=t?s:u}},e.N=function(e){return i(this,void 0,void 0,function*(){var t=yield l.Wt(e);return JSON.parse(null!=t?t:"null")})},e.R=function(t,e){return i(this,void 0,void 0,function*(){yield l.M(t,JSON.stringify(e))})}},412:(t,e,n)=>{$Q(e),e.typedJsonParse=void 0;const o=n(780);e.typedJsonParse=function(t,e,n){try{var i=JSON.parse(t);return"object"==typeof i&&0 in i,i}catch(t){}return o.Log.error(n),null}},556:(t,e)=>{$Q(e),e.getUUID=void 0,e.getUUID=function(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();let n=(new Date).getTime(),i="undefined"!=typeof performance&&performance.now&&1e3*performance.now()||0;return`xxxxxxxx-xxxx-4xxx-${"89ab"[Math.floor(4*Math.random())]}xxx-xxxxxxxxxxxx`.replace(/[xy]/g,t=>{let e=16*Math.random();return 0<n?(e=(n+e)%16|0,n=Math.floor(n/16)):(e=(i+e)%16|0,i=Math.floor(i/16)),("x"===t?e:7&e|8).toString(16)})}},84:(t,e)=>{$Q(e),e.tt=void 0,e.tt=function(t,e,n,i){return t||(e?""+e+n:""+i+n)}},539:(t,e)=>{$Q(e)},100:(t,e,n)=>{$Q(e),e.Xt=e.nt=e._t=void 0;n=n(48);const i="foreground",o="background",s=[];let r=i;e._t=()=>r===i,e.nt=t=>{s.unshift(t)};e.Xt=e=>{e!==r&&(r=e,s.forEach(t=>t(e)))},(0,n.Mt)("focus",()=>(0,e.Xt)(i)),(0,n.Mt)("blur",()=>(0,e.Xt)(o)),(0,n.Mt)("beforeunload",()=>(0,e.Xt)(o)),(0,n.xt)("visibilitychange",()=>{(0,e.Xt)("visible"===document.visibilityState?i:o)})},464:function(t,e,n){var i=this&&this.__createBinding||(Object.create?function(t,e,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&("get"in o?e.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,o)}:function(t,e,n,i){t[i=void 0===i?n:i]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||i(e,t,n)};$Q(e),e.Log=e.Storage=e.EventLogger=void 0,n(496);const s=n(728),r=(Object.defineProperty(e,"EventLogger",{enumerable:!0,get:function(){return s.EventLogger}}),n(780));Object.defineProperty(e,"Log",{enumerable:!0,get:function(){return r.Log}});var u=n(972);const l=n(444);Object.defineProperty(e,"Storage",{enumerable:!0,get:function(){return l.Storage}});var a=n(556);o(n(496),e),o(n(856),e),o(n(320),e),o(n(184),e),o(n(512),e),o(n(500),e),o(n(788),e),o(n(832),e),o(n(664),e),o(n(780),e),o(n(104),e),o(n(452),e),o(n(188),e),o(n(256),e),o(n(264),e),o(n(48),e),o(n(360),e),o(n(612),e),o(n(604),e),o(n(688),e),o(n(808),e),o(n(283),e),o(n(876),e),o(n(972),e),o(n(384),e),o(n(396),e),o(n(136),e),o(n(296),e),o(n(444),e),o(n(412),e),o(n(84),e),o(n(539),e),o(n(556),e),o(n(100),e),__STATSIG__=$P($P({},null!==__STATSIG__&&void 0!==__STATSIG__?__STATSIG__:{}),{EventLogger:s.EventLogger,Log:r.Log,getUUID:a.getUUID,Storage:l.Storage,SDK_VERSION:u.SDK_VERSION})},696:function(t,e,n){var i=this&&this.__createBinding||(Object.create?function(t,e,n,i){void 0===i&&(i=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&("get"in o?e.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,o)}:function(t,e,n,i){t[i=void 0===i?n:i]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||i(e,t,n)};$Q(e),o(n(208),e),e.default=__STATSIG__},96:(t,e,n)=>{$Q(e),e.resolveDeltasResponse=void 0;const i=n(464);function o(t,e){null!=t&&t.forEach(t=>{delete e[t]})}e.resolveDeltasResponse=function(t,e){var n;return(e=(0,i.typedJsonParse)(e,"checksum","Failed to parse DeltasEvaluationResponse"))?(t=t,n=e,t=$P($P($P({},t),n),{feature_gates:$P($P({},t.feature_gates),n.feature_gates),layer_configs:$P($P({},t.layer_configs),n.layer_configs),dynamic_configs:$P($P({},t.dynamic_configs),n.dynamic_configs)}),o((t=n=t).deleted_gates,t.feature_gates),delete t.deleted_gates,o(n.deleted_configs,t.dynamic_configs),delete t.deleted_configs,o(n.deleted_layers,t.layer_configs),delete t.deleted_layers,n=t,(t=(0,i.DJB2Object)({feature_gates:n.feature_gates,dynamic_configs:n.dynamic_configs,layer_configs:n.layer_configs}))===e.checksum?JSON.stringify(n):{hadBadDeltaChecksum:!0,badChecksum:t,badMergedConfigs:n,badFullResponse:e.deltas_full_response}):{hadBadDeltaChecksum:!0}}},536:(t,e,n)=>{$Q(e);const i=n(464);e.default=class{constructor(){this.Zt=null,this.te=null,this.ee="Uninitialized",this.ne=0,this.ie=0}getValues(){return this.Zt?(0,i.typedJsonParse)(this.Zt,"has_updates","Failed to parse EvaluationStoreValues"):null}reset(){this.te=null,this.Zt=null,this.ee="Loading",this.ne=0,this.ie=0}finalize(){this.te||(this.ee="NoValues")}setValuesFromDataAdapter(t){var e;t&&!0===(null==(e=(0,i.typedJsonParse)(t.data,"has_updates","Failed to parse EvaluationResponse"))?void 0:e.has_updates)&&(this.Zt=t.data,this.ne=e.time,this.ie=t.receivedAt,this.ee=t.source,this.te=e)}getGate(t){var e,t=null!=(e=null==(e=this.te)?void 0:e.feature_gates[t])?e:null;return this.se(t)}getConfig(t){var e,t=null!=(e=null==(e=this.te)?void 0:e.dynamic_configs[t])?e:null;return this.se(t)}getLayer(t){var e,t=null!=(e=null==(e=this.te)?void 0:e.layer_configs[t])?e:null;return this.se(t)}se(t){return{evaluation:t,details:this.oe(null==t)}}oe(t){return"Uninitialized"===this.ee||"NoValues"===this.ee?{reason:this.ee}:{reason:this.ee+":"+(t?"Unrecognized":"Recognized"),lcut:this.ne,receivedAt:this.ie}}}},400:function(t,e,n){var s=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e);const r=n(464),u=n(96);class i extends r.NetworkCore{constructor(t,e){super(t,e);e=null==t?void 0:t.networkConfig;this.re=(0,r.tt)(null==e?void 0:e.initializeUrl,null==e?void 0:e.api,"/initialize",r.NetworkDefault.initializeApi)}fetchEvaluations(n,i,o){return s(this,void 0,void 0,function*(){var t=i?(0,r.typedJsonParse)(i,"has_updates","Failed to parse cached EvaluationResponse"):null;let e={user:o,hash:"djb2",deltasResponseRequested:!1};return null!=t&&t.has_updates&&(e=$P($P({},e),{sinceTime:t.time,previousDerivedFields:"derived_fields"in t?t.derived_fields:{},deltasResponseRequested:!0})),this.ue(n,t,e)})}ue(e,n,i){var o;return s(this,void 0,void 0,function*(){var t=yield this.post({sdkKey:e,url:this.re,data:i,retries:2,isStatsigEncodable:!0});return 204===(null==t?void 0:t.code)?'{"has_updates": false}':200!==(null==t?void 0:t.code)?null!=(o=null==t?void 0:t.body)?o:null:!0!==(null==n?void 0:n.has_updates)||!0!==(null==(o=t.body)?void 0:o.includes('"is_delta":true'))?t.body:"string"==typeof(t=(0,u.resolveDeltasResponse)(n,t.body))?t:this.ue(e,n,$P($P($P({},i),t),{deltasResponseRequested:!1}))})}}e.default=i},520:function(t,e,n){var i=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})};$Q(e);const r=n(464),o=n(536),s=n(400),u=n(364);class l extends r.StatsigClientBase{static instance(t){var e=(0,r.i)().instance(t);return e instanceof l?e:(r.Log.warn("Unable to find StatsigClient instance"),new l(null!=t?t:"",{}))}constructor(t,e,n=null){r.SDKType.It(t,"javascript-client");var i=new s.default(n,t=>{this.St(t)});super(t,null!=(t=null==n?void 0:n.dataAdapter)?t:new u.StatsigEvaluationsDataAdapter,i,n),(0,r.monitorClass)(this.l,this),(0,r.monitorClass)(this.l,i),this.le=new o.default,this.ae=e}initializeSync(){this.updateUserSync(this.ae)}initializeAsync(){return this.updateUserAsync(this.ae)}updateUserSync(t){this.ce(t);t=this.dataAdapter.getDataSync(this.ae);this.le.setValuesFromDataAdapter(t),this.le.finalize(),this.Lt("Ready",t),this.de(null!=t?t:null,this.ae)}updateUserAsync(n){return i(this,void 0,void 0,function*(){this.ce(n);var t=this.ae,e=this.dataAdapter.getDataSync(t);this.Lt("Loading",e),this.le.setValuesFromDataAdapter(e),e=yield this.dataAdapter.getDataAsync(e,t),t===this.ae&&this.le.setValuesFromDataAdapter(e),this.le.finalize(),this.Lt("Ready",e)})}getContext(){return{sdkKey:this.h,options:this.J,values:this.le.getValues(),user:JSON.parse(JSON.stringify(this.ae))}}getAsyncContext(){return i(this,void 0,void 0,function*(){return $P($P({},this.getContext()),{sessionID:yield r.SessionID.get(this.h),stableID:yield r.StableID.get(this.h)})})}checkGate(t,e){return this.getFeatureGate(t,e).value}getFeatureGate(t,e){var n=(0,r.DJB2)(t),{evaluation:n,details:i}=this.le.getGate(n),i=(0,r.$t)(t,i,n),o=null==(o=null==(n=this.Gt)?void 0:n.getGateOverride)?void 0:o.call(n,i,this.ae,e),n=null!=o?o:i;return this.Ut(t,(0,r.qt)(this.ae,n),e),this.St({name:"gate_evaluation",gate:n}),n}getDynamicConfig(t,e){t=this.he("dynamic_config",t,e);return this.St({name:"dynamic_config_evaluation",dynamicConfig:t}),t}getExperiment(t,e){t=this.he("experiment",t,e);return this.St({name:"experiment_evaluation",experiment:t}),t}getLayer(e,n){var t=(0,r.DJB2)(e),{evaluation:t,details:i}=this.le.getLayer(t),i=(0,r.zt)(e,i,t),o=null==(o=null==(t=this.Gt)?void 0:t.getLayerOverride)?void 0:o.call(t,i,this.ae,n);const s=(0,r.Vt)(i,o,null!=(t=null==o?void 0:o.__value)?t:i.__value,t=>{this.Ut(e,(0,r.Jt)(this.ae,s,t),n)});return this.St({name:"layer_evaluation",layer:s}),s}logEvent(t,e,n){this.Ft.enqueue($P($P({},"string"==typeof t?{eventName:t,value:e,metadata:n}:t),{user:this.ae,time:Date.now()}))}de(t,e){this.dataAdapter.getDataAsync(t,e).catch(t=>{r.Log.error("An error occurred after update.",t)})}ce(t){this.Ft.reset(),this.le.reset(),this.ae=(0,r.normalizeUser)(t,this.J.environment)}he(t,e,n){var i=(0,r.DJB2)(e),{evaluation:i,details:o}=this.le.getConfig(i),o=(0,r.Bt)(e,o,i),i="experiment"===t?null==(t=null==(i=this.Gt)?void 0:i.getExperimentOverride)?void 0:t.call(i,o,this.ae,n):null==(i=null==(t=this.Gt)?void 0:t.getDynamicConfigOverride)?void 0:i.call(t,o,this.ae,n),t=null!=i?i:o;return this.Ut(e,(0,r.Kt)(this.ae,t),n),t}}e.default=l},364:function(t,e,n){var o=this&&this.__awaiter||function(t,r,u,l){return new(u=u||Promise)(function(n,e){function i(t){try{s(l.next(t))}catch(t){e(t)}}function o(t){try{s(l.throw(t))}catch(t){e(t)}}function s(t){var e;t.done?n(t.value):((e=t.value)instanceof u?e:new u(function(t){t(e)})).then(i,o)}s((l=l.apply(t,r||[])).next())})},i=($Q(e),e.StatsigEvaluationsDataAdapter=void 0,n(464));const s=n(400);class r extends i.DataAdapterCore{constructor(){super("EvaluationsDataAdapter","evaluations"),this.U=null}attach(t,e){super.attach(t,e),this.U=new s.default(null!=e?e:{})}T(e,n){var i;return o(this,void 0,void 0,function*(){var t=yield null==(i=this.U)?void 0:i.fetchEvaluations(this.I(),e,n);return null!=t?t:null})}}e.StatsigEvaluationsDataAdapter=r},208:(t,e,n)=>{$Q(e),e.StatsigClient=e.StatsigEvaluationsDataAdapter=void 0;var i=n(520);e.StatsigClient=i.default;const o=n(364);Object.defineProperty(e,"StatsigEvaluationsDataAdapter",{enumerable:!0,get:function(){return o.StatsigEvaluationsDataAdapter}}),__STATSIG__=$P($P({},null!==__STATSIG__&&void 0!==__STATSIG__?__STATSIG__:{}),{StatsigEvaluationsDataAdapter:o.StatsigEvaluationsDataAdapter,StatsigClient:i.default}),e.default=__STATSIG__}},i={};function o(t){var e=i[t];return void 0!==e||(e=i[t]={exports:{}},n[t].call(e.exports,e,e.exports,o)),e.exports}return o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),o(696).default})());
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/js-client",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.31",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "0.0.1-beta.
|
|
5
|
+
"@statsig/client-core": "0.0.1-beta.31"
|
|
6
6
|
},
|
|
7
7
|
"jsdelivr": "./build/statsig-js-client.min.js",
|
|
8
8
|
"type": "commonjs",
|
package/src/StatsigClient.d.ts
CHANGED
|
@@ -3,14 +3,6 @@ import type { StatsigOptions } from './StatsigOptions';
|
|
|
3
3
|
export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdapter> implements PrecomputedEvaluationsInterface {
|
|
4
4
|
private _store;
|
|
5
5
|
private _user;
|
|
6
|
-
/**
|
|
7
|
-
* StatsigClient constuctor
|
|
8
|
-
*
|
|
9
|
-
* @param {string} sdkKey A Statsig client SDK key. eg "client-xyz123..."
|
|
10
|
-
* @param {StatsigUser} user StatsigUser object containing various attributes related to a user.
|
|
11
|
-
* @param {StatsigOptions | null} options StatsigOptions, used to customize the behavior of the SDK.
|
|
12
|
-
*/
|
|
13
|
-
constructor(sdkKey: string, user: StatsigUser, options?: StatsigOptions | null);
|
|
14
6
|
/**
|
|
15
7
|
* Retrieves an instance of the StatsigClient based on the provided SDK key.
|
|
16
8
|
* If no SDK key is provided, the method returns the most recently created instance of the StatsigClient.
|
|
@@ -19,7 +11,15 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
|
|
|
19
11
|
* @param {string} [sdkKey] - Optional. The SDK key used to identify a specific instance of the StatsigClient. If omitted, the method returns the last created instance.
|
|
20
12
|
* @returns {StatsigClient|undefined} Returns the StatsigClient instance associated with the given SDK key, or undefined if no instance is associated with the key or if no key is provided and no instances exist.
|
|
21
13
|
*/
|
|
22
|
-
static instance(sdkKey?: string): StatsigClient
|
|
14
|
+
static instance(sdkKey?: string): StatsigClient;
|
|
15
|
+
/**
|
|
16
|
+
* StatsigClient constructor
|
|
17
|
+
*
|
|
18
|
+
* @param {string} sdkKey A Statsig client SDK key. eg "client-xyz123..."
|
|
19
|
+
* @param {StatsigUser} user StatsigUser object containing various attributes related to a user.
|
|
20
|
+
* @param {StatsigOptions | null} options StatsigOptions, used to customize the behavior of the SDK.
|
|
21
|
+
*/
|
|
22
|
+
constructor(sdkKey: string, user: StatsigUser, options?: StatsigOptions | null);
|
|
23
23
|
/**
|
|
24
24
|
* Initializes the StatsigClient using cached values. This method sets up the client synchronously by utilizing previously cached values.
|
|
25
25
|
* After initialization, cache values are updated in the background for future use, either in subsequent sessions or when `updateUser` is called.
|
package/src/StatsigClient.js
CHANGED
|
@@ -15,7 +15,23 @@ const Network_1 = require("./Network");
|
|
|
15
15
|
const StatsigEvaluationsDataAdapter_1 = require("./StatsigEvaluationsDataAdapter");
|
|
16
16
|
class StatsigClient extends client_core_1.StatsigClientBase {
|
|
17
17
|
/**
|
|
18
|
-
* StatsigClient
|
|
18
|
+
* Retrieves an instance of the StatsigClient based on the provided SDK key.
|
|
19
|
+
* If no SDK key is provided, the method returns the most recently created instance of the StatsigClient.
|
|
20
|
+
* The method ensures that each unique SDK key corresponds to a single instance of StatsigClient, effectively implementing a singleton pattern for each key.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} [sdkKey] - Optional. The SDK key used to identify a specific instance of the StatsigClient. If omitted, the method returns the last created instance.
|
|
23
|
+
* @returns {StatsigClient|undefined} Returns the StatsigClient instance associated with the given SDK key, or undefined if no instance is associated with the key or if no key is provided and no instances exist.
|
|
24
|
+
*/
|
|
25
|
+
static instance(sdkKey) {
|
|
26
|
+
const instance = (0, client_core_1._getStatsigGlobal)().instance(sdkKey);
|
|
27
|
+
if (instance instanceof StatsigClient) {
|
|
28
|
+
return instance;
|
|
29
|
+
}
|
|
30
|
+
client_core_1.Log.warn('Unable to find StatsigClient instance');
|
|
31
|
+
return new StatsigClient(sdkKey !== null && sdkKey !== void 0 ? sdkKey : '', {});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* StatsigClient constructor
|
|
19
35
|
*
|
|
20
36
|
* @param {string} sdkKey A Statsig client SDK key. eg "client-xyz123..."
|
|
21
37
|
* @param {StatsigUser} user StatsigUser object containing various attributes related to a user.
|
|
@@ -33,19 +49,6 @@ class StatsigClient extends client_core_1.StatsigClientBase {
|
|
|
33
49
|
this._store = new EvaluationStore_1.default();
|
|
34
50
|
this._user = user;
|
|
35
51
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Retrieves an instance of the StatsigClient based on the provided SDK key.
|
|
38
|
-
* If no SDK key is provided, the method returns the most recently created instance of the StatsigClient.
|
|
39
|
-
* The method ensures that each unique SDK key corresponds to a single instance of StatsigClient, effectively implementing a singleton pattern for each key.
|
|
40
|
-
*
|
|
41
|
-
* @param {string} [sdkKey] - Optional. The SDK key used to identify a specific instance of the StatsigClient. If omitted, the method returns the last created instance.
|
|
42
|
-
* @returns {StatsigClient|undefined} Returns the StatsigClient instance associated with the given SDK key, or undefined if no instance is associated with the key or if no key is provided and no instances exist.
|
|
43
|
-
*/
|
|
44
|
-
static instance(sdkKey) {
|
|
45
|
-
var _a;
|
|
46
|
-
const sGlobal = (0, client_core_1._getStatsigGlobal)();
|
|
47
|
-
return (sdkKey ? (_a = sGlobal.instances) === null || _a === void 0 ? void 0 : _a[sdkKey] : sGlobal.lastInstance);
|
|
48
|
-
}
|
|
49
52
|
/**
|
|
50
53
|
* Initializes the StatsigClient using cached values. This method sets up the client synchronously by utilizing previously cached values.
|
|
51
54
|
* After initialization, cache values are updated in the background for future use, either in subsequent sessions or when `updateUser` is called.
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { StatsigGlobal } from '@statsig/client-core';
|
|
1
2
|
import StatsigClient from './StatsigClient';
|
|
2
3
|
import { StatsigEvaluationsDataAdapter } from './StatsigEvaluationsDataAdapter';
|
|
3
4
|
import type { StatsigOptions } from './StatsigOptions';
|
|
4
5
|
export type { StatsigEnvironment, StatsigEvent, StatsigUser, InitializeResponse, } from '@statsig/client-core';
|
|
5
6
|
export { StatsigEvaluationsDataAdapter, StatsigClient, StatsigOptions };
|
|
6
|
-
|
|
7
|
+
declare const _default: StatsigGlobal;
|
|
8
|
+
export default _default;
|
package/src/index.js
CHANGED
|
@@ -6,5 +6,5 @@ exports.StatsigClient = StatsigClient_1.default;
|
|
|
6
6
|
const StatsigEvaluationsDataAdapter_1 = require("./StatsigEvaluationsDataAdapter");
|
|
7
7
|
Object.defineProperty(exports, "StatsigEvaluationsDataAdapter", { enumerable: true, get: function () { return StatsigEvaluationsDataAdapter_1.StatsigEvaluationsDataAdapter; } });
|
|
8
8
|
__STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { StatsigEvaluationsDataAdapter: StatsigEvaluationsDataAdapter_1.StatsigEvaluationsDataAdapter,
|
|
9
|
-
StatsigClient: StatsigClient_1.default
|
|
9
|
+
StatsigClient: StatsigClient_1.default });
|
|
10
10
|
exports.default = __STATSIG__;
|