@statsig/js-client 0.0.1-beta.30 → 0.0.1-beta.32
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 +18 -14
- package/src/StatsigClient.js +25 -20
- package/src/StatsigEvaluationsDataAdapter.d.ts +3 -1
- package/src/StatsigEvaluationsDataAdapter.js +6 -0
- 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.t=e.i=void 0,e.i=()=>null!==__STATSIG__&&void 0!==__STATSIG__?__STATSIG__:u;e.t=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.t};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),r=n(780),o=n(104),u=n(283),l=n(296),a=n(444),c=n(412);e.DataAdapterCore=class{constructor(t,e){this.o=t,this.l=e,this.u=null,this.h=null,this.v={},this._="statsig.last_modified_time."+e}attach(t,e){this.h=t,this.u=new i.ErrorBoundary(t),(0,o.monitorClass)(this.u,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)}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(e,n,i){var o;return s(this,void 0,void 0,function*(){var t=null!=e?e:this.getDataSync(n),t=[this.j(null!=(o=null==t?void 0:t.data)?o:null,n)];return null!=i&&i.timeoutMs&&t.push(new Promise(t=>setTimeout(t,i.timeoutMs)).then(()=>(r.Log.debug("Fetching latest value timed out"),null))),yield Promise.race(t)})}T(n,i){return s(this,void 0,void 0,function*(){var t=this.m(n),e=yield this.O(null,n,i);e&&this.S(t,$P($P({},e),{source:"Prefetch"}))})}j(i,o){return s(this,void 0,void 0,function*(){var t=yield this.I(i,o);if(!t)return r.Log.debug("No response returned for latest value"),null;var e=(0,c.typedJsonParse)(t,"has_updates","Failure while attempting to persist latest value");let n=null;return!0===(null==e?void 0:e.has_updates)?n={source:"Network",data:t,receivedAt:Date.now()}:i&&!1===(null==e?void 0:e.has_updates)&&(n={source:"NetworkNotModified",data:i,receivedAt:Date.now()}),n?(t=this.m(o),this.S(t,n),yield this.A(t,n),n):null})}M(){return null!=this.h?this.h:(r.Log.error(this.o+" is not attached to a Client"),"")}m(t){t=(0,l.getUserStorageKey)(this.M(),t);return`${u.DataAdapterCachePrefix}.${this.l}.`+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.D)?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}A(t,e){return s(this,void 0,void 0,function*(){yield a.Storage.k(t,JSON.stringify(e)),yield this.N(t)})}N(n){var i;return s(this,void 0,void 0,function*(){var t=null!=(i=yield(0,a.P)(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.C(e[0])),yield(0,a.G)(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.R=new Set}capture(e,t,n){try{var i=t();return i&&i instanceof Promise?i.catch(t=>this.F(e,t,n)):i}catch(t){return this.F(e,t,n),null}}logError(t,e){this.F(t,e)}F(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.R.has(o)||(this.R.add(o),t=a.SDKType.L(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(48),a=n(876),c=n(444),d=n(412),h=n(84),v=n(100);e.EventLogger=class{constructor(t,e,n,i){this.h=t,this.U=e,this.K=n,this.J=i,this.q=[],this.V={},this.B={},this.$=!1,this.H=Date.now(),this.W=!0===(null==i?void 0:i.disableLogging),this.Y=null!=(t=null==i?void 0:i.loggingBufferMaxSize)?t:50;n=null!=(e=null==i?void 0:i.loggingIntervalMs)?e:1e4,this.X=setInterval(()=>this.Z(),n),t=null==i?void 0:i.networkConfig;this.tt=(0,h.et)(null==t?void 0:t.logEventUrl,null==t?void 0:t.api,"/rgstr",r.NetworkDefault.eventsApi),this.nt=(0,h.et)(null==t?void 0:t.logEventBeaconUrl,null==t?void 0:t.api,"/log_event_beacon",r.NetworkDefault.eventsApi),(0,v.it)(this.st.bind(this)),this.ot()}setLoggingDisabled(t){this.W=t}enqueue(t){this.rt(t)&&(this.lt(t),this.ut(),this.q.length>this.Y)&&this.Z()}incrementNonExposureCount(t){var e=null!=(e=this.B[t])?e:0;this.B[t]=e+1}reset(){this.V={}}shutdown(){return i(this,void 0,void 0,function*(){this.X&&(clearInterval(this.X),this.X=null),yield this.flush()})}flush(){return i(this,void 0,void 0,function*(){var t;this.ct(),0!==this.q.length&&(t=this.q,this.q=[],yield this.dt(t))})}st(t){"background"===t&&this.Z()}ut(){this.$||(this.$=!0,200<Date.now()-this.H)||setTimeout(()=>this.Z(),200)}rt(t){if((0,a.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.V[t],n=Date.now();if(e&&n-e<6e4)return!1;1e3<Object.keys(this.V).length&&(this.V={}),this.V[t]=n}return!0}Z(){this.flush().catch(()=>{})}dt(t){return i(this,void 0,void 0,function*(){if(this.W)this.vt(t);else try{(!(0,v._t)()&&this.K.isBeaconSupported()?yield this.ft(t):yield this.gt(t)).success?this.U({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.K.post({sdkKey:this.h,data:{events:e},url:this.tt,retries:3,params:{[u.NetworkParam.EventCount]:String(e.length)}}),t=null!=t&&t.body?(0,d.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.K.beacon({sdkKey:this.h,data:{events:t},url:this.nt})}})}vt(t){for(;500<t.length;)t.shift();var e=this.bt();(0,c.G)(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,c.P)(e);t&&(yield c.Storage.C(e),yield this.dt(t))}).catch(()=>{s.Log.warn("Failed to flush stored logs")})}bt(){return"statsig.failed_logs."+(0,o.DJB2)(this.h)}lt(t){t.user&&(t.user=$P({},t.user),delete t.user.privateAttributes);var e={},n=this.yt();n&&(e.statsigMetadata={currentPage:n}),this.q.push($P($P({},t),e))}ct(){0!==Object.keys(this.B).length&&(this.lt({eventName:"statsig::non_exposed_checks",user:null,time:Date.now(),metadata:{checks:$P({},this.B)}}),this.B={})}yt(){var t;if(!1!==(null==(t=this.J)?void 0:t.includeCurrentPageUrlWithEvents))return(0,l.ln)()}}},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.U=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.wt(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.It(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.It(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.U)&&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}))}})}It(e){return i(this,void 0,void 0,function*(){var t=$P({[o.NetworkParam.SdkKey]:e.sdkKey,[o.NetworkParam.SdkType]:s.SDKType.L(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.L(e);return JSON.stringify($P($P({},t),{statsigMetadata:$P($P({},l.StatsigMetadataProvider.get()),{stableID:n,sessionID:i,sdkType:e})}))})}wt(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={L:t=>{return(null!=(t=n[t])?t:"js-mono")+(null!==i&&void 0!==i?i:"")},At(t,e){n[t]=e},Mt(t){i&&"-react"!==i||(i="-"+t)}}},48:(t,i)=>{Object.defineProperty(i,"__esModule",{value:!0}),i.ln=i.xt=i.Dt=i.an=i.Et=i.kt=void 0;i.kt=()=>"undefined"!=typeof window?window:null,i.Et=()=>{var t=(0,i.kt)();return null!=(t=null==t?void 0:t.document)?t:null},i.an=()=>null!=(0,i.Et)(),i.Dt=(t,e)=>{var n=(0,i.kt)();"function"==typeof(null==n?void 0:n.addEventListener)&&n.addEventListener(t,e)},i.xt=(t,e)=>{var n=(0,i.Et)();"function"==typeof(null==n?void 0:n.addEventListener)&&n.addEventListener(t,e)};i.ln=()=>{var t;try{return null==(t=(0,i.kt)())?void 0:t.location.href.split(/[?#]/)[0]}catch(t){}}},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.P)(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.G)(o,i).catch(()=>{u.Log.warn("Failed to save SessionID")}),t.idleTimeoutID=r.SessionID.Pt(t,t.idleTimeoutID,18e5),t.ageTimeoutID=r.SessionID.Pt(t,t.ageTimeoutID,144e5-(n-e.startTime)),c[s]=e,d[s]=t,h[s]=null,e.sessionID}),Ct:(t,e)=>{var n=null!=(n=d[e])?n:{ageTimeoutID:null,idleTimeoutID:null,emitFunction:t};n.emitFunction=t,d[e]=n},Pt:(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.G)(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.P)(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(48),c=n(612),d=n(604),h=n(444);e.StatsigClientBase=class{constructor(t,e,n,i){this.loadingStatus="Uninitialized",this.Gt={},this.h=t,this.J=null!=i?i:{},null!=i&&i.disableStorage&&h.Storage.Rt(!0),null!=i&&i.overrideStableID&&d.StableID.setOverride(i.overrideStableID,t),l.Log.level=null!=(o=null==i?void 0:i.logLevel)?o:l.LogLevel.Warn,this.Ft=null!=(o=null==i?void 0:i.overrideAdapter)?o:null,this.Lt=new u.EventLogger(t,this.St.bind(this),n,i),c.SessionID.Ct(()=>{this.St({name:"session_expired"})},t),this.u=new r.ErrorBoundary(t);var o=(0,s.i)(),n=null!=(n=o.instances)?n:{};null!=n[t]&&(0,a.an)()&&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.Lt.setLoggingDisabled(t.disableLogging)),null!=t.disableStorage&&(this.J.disableStorage=t.disableStorage,h.Storage.Rt(t.disableStorage))}flush(){return this.Lt.flush()}shutdown(){return i(this,void 0,void 0,function*(){this.St({name:"pre_shutdown"}),yield this.Lt.shutdown()})}on(t,e){this.Gt[t]||(this.Gt[t]=[]),this.Gt[t].push(e)}off(t,e){this.Gt[t]&&-1!==(e=this.Gt[t].indexOf(e))&&this.Gt[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.u.logError("_emit:"+n.name,t):l.Log.error("An error occurred in a StatsigClientEvent listener. This is not an issue with Statsig.",n)}};this.Gt[n.name]&&this.Gt[n.name].forEach(t=>e(t)),null!=(t=this.Gt["*"])&&t.forEach(e)}Ut(t,e){this.loadingStatus=t,this.St({name:"values_updated",status:t,values:e})}Kt(t,e,n){!0===(null==n?void 0:n.disableExposureLog)?this.Lt.incrementNonExposureCount(t):this.Lt.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.qt=e.Vt=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.Vt=(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.qt=(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.32";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.zt=e.Bt=e.$t=e.Ht=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.Ht=function(t,e,n){return s(t,e,n,!0===(null==n?void 0:n.value))},e.$t=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.Bt=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.zt=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.G=e.P=e.Storage=void 0,n(780));const o={},s={Wt:()=>"InMemory",D(t){return null!=(t=o[t])?t:null},Yt(t){return Promise.resolve(null!=(t=o[t])?t:null)},k(t,e){return o[t]=e,Promise.resolve()},C(t){return delete o[t],Promise.resolve()},Qt(){return Promise.resolve(Object.keys(o))}};let r=null;try{"undefined"!=typeof window&&"localStorage"in window&&(r={Wt:()=>"LocalStorage",D(t){return localStorage.getItem(t)},Yt(t){return Promise.resolve(localStorage.getItem(t))},k(t,e){return localStorage.setItem(t,e),Promise.resolve()},C(t){return localStorage.removeItem(t),Promise.resolve()},Qt(){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={Wt:()=>l.Wt(),Yt:t=>l.Yt(t),k:(t,e)=>l.k(t,e),C:t=>l.C(t),Qt:()=>l.Qt(),D:t=>{var e;return null!=(e=null==(e=l.D)?void 0:e.call(l,t))?e:null},Xt:t=>{u=t,l=t},Rt:t=>{l=t?s:u}},e.P=function(e){return i(this,void 0,void 0,function*(){var t=yield l.Yt(e);return JSON.parse(null!=t?t:"null")})},e.G=function(t,e){return i(this,void 0,void 0,function*(){yield l.k(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.et=void 0,e.et=function(t,e,n,i){return t||(e?""+e+n:""+i+n)}},539:(t,e)=>{$Q(e)},100:(t,e,n)=>{$Q(e),e.Zt=e.it=e._t=void 0;n=n(48);const i="foreground",o="background",s=[];let r=i;e._t=()=>r===i,e.it=t=>{s.unshift(t)};e.Zt=e=>{e!==r&&(r=e,s.forEach(t=>t(e)))},(0,n.Dt)("focus",()=>(0,e.Zt)(i)),(0,n.Dt)("blur",()=>(0,e.Zt)(o)),(0,n.Dt)("beforeunload",()=>(0,e.Zt)(o)),(0,n.xt)("visibilitychange",()=>{(0,e.Zt)("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.te=null,this.ee=null,this.ne="Uninitialized",this.ie=0,this.se=0}getValues(){return this.te?(0,i.typedJsonParse)(this.te,"has_updates","Failed to parse EvaluationStoreValues"):null}reset(){this.ee=null,this.te=null,this.ne="Loading",this.ie=0,this.se=0}finalize(){this.ee||(this.ne="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.te=t.data,this.ie=e.time,this.se=t.receivedAt,this.ne=t.source,this.ee=e)}getGate(t){var e,t=null!=(e=null==(e=this.ee)?void 0:e.feature_gates[t])?e:null;return this.oe(t)}getConfig(t){var e,t=null!=(e=null==(e=this.ee)?void 0:e.dynamic_configs[t])?e:null;return this.oe(t)}getLayer(t){var e,t=null!=(e=null==(e=this.ee)?void 0:e.layer_configs[t])?e:null;return this.oe(t)}oe(t){return{evaluation:t,details:this.re(null==t)}}re(t){return"Uninitialized"===this.ne||"NoValues"===this.ne?{reason:this.ne}:{reason:this.ne+":"+(t?"Unrecognized":"Recognized"),lcut:this.ie,receivedAt:this.se}}}},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.le=(0,r.et)(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.le,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 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())})};$Q(e);const r=n(464),s=n(536),u=n(400),l=n(364);class i extends r.StatsigClientBase{static instance(t){var e=(0,r.i)().instance(t);return e instanceof i?e:(r.Log.warn("Unable to find StatsigClient instance"),new i(null!=t?t:"",{}))}constructor(t,e,n=null){r.SDKType.At(t,"javascript-client");var i=new u.default(n,t=>{this.St(t)});super(t,null!=(t=null==n?void 0:n.dataAdapter)?t:new l.StatsigEvaluationsDataAdapter,i,n),(0,r.monitorClass)(this.u,this),(0,r.monitorClass)(this.u,i),this.ae=new s.default,this.ce=e}initializeSync(){this.updateUserSync(this.ce)}initializeAsync(t){return this.updateUserAsync(this.ce,t)}updateUserSync(t){this.de(t);t=this.dataAdapter.getDataSync(this.ce);this.ae.setValuesFromDataAdapter(t),this.ae.finalize(),this.Ut("Ready",t),this.he(null!=t?t:null,this.ce)}updateUserAsync(n,i){return o(this,void 0,void 0,function*(){this.de(n);var t=this.ce,e=this.dataAdapter.getDataSync(t);this.Ut("Loading",e),this.ae.setValuesFromDataAdapter(e),e=yield this.dataAdapter.getDataAsync(e,t,i),t===this.ce&&this.ae.setValuesFromDataAdapter(e),this.ae.finalize(),this.Ut("Ready",e)})}getContext(){return{sdkKey:this.h,options:this.J,values:this.ae.getValues(),user:JSON.parse(JSON.stringify(this.ce))}}getAsyncContext(){return o(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.ae.getGate(n),i=(0,r.Ht)(t,i,n),o=null==(o=null==(n=this.Ft)?void 0:n.getGateOverride)?void 0:o.call(n,i,this.ce,e),n=null!=o?o:i;return this.Kt(t,(0,r.Vt)(this.ce,n),e),this.St({name:"gate_evaluation",gate:n}),n}getDynamicConfig(t,e){t=this.ve("dynamic_config",t,e);return this.St({name:"dynamic_config_evaluation",dynamicConfig:t}),t}getExperiment(t,e){t=this.ve("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.ae.getLayer(t),i=(0,r.Bt)(e,i,t),o=null==(o=null==(t=this.Ft)?void 0:t.getLayerOverride)?void 0:o.call(t,i,this.ce,n);const s=(0,r.zt)(i,o,null!=(t=null==o?void 0:o.__value)?t:i.__value,t=>{this.Kt(e,(0,r.Jt)(this.ce,s,t),n)});return this.St({name:"layer_evaluation",layer:s}),s}logEvent(t,e,n){this.Lt.enqueue($P($P({},"string"==typeof t?{eventName:t,value:e,metadata:n}:t),{user:this.ce,time:Date.now()}))}he(t,e){this.dataAdapter.getDataAsync(t,e).catch(t=>{r.Log.error("An error occurred after update.",t)})}de(t){this.Lt.reset(),this.ae.reset(),this.ce=(0,r.normalizeUser)(t,this.J.environment)}ve(t,e,n){var i=(0,r.DJB2)(e),{evaluation:i,details:o}=this.ae.getConfig(i),o=(0,r.$t)(e,o,i),i="experiment"===t?null==(t=null==(i=this.Ft)?void 0:i.getExperimentOverride)?void 0:t.call(i,o,this.ce,n):null==(i=null==(t=this.Ft)?void 0:t.getDynamicConfigOverride)?void 0:i.call(t,o,this.ce,n),t=null!=i?i:o;return this.Kt(e,(0,r.qt)(this.ce,t),n),t}}e.default=i},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.K=null}attach(t,e){super.attach(t,e),this.K=new s.default(null!=e?e:{})}getDataAsync(t,e,n){return this.O(t,e,n)}prefetchData(t,e){return this.T(t,e)}I(e,n){var i;return o(this,void 0,void 0,function*(){var t=yield null==(i=this.K)?void 0:i.fetchEvaluations(this.M(),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.32",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "0.0.1-beta.
|
|
5
|
+
"@statsig/client-core": "0.0.1-beta.32"
|
|
6
6
|
},
|
|
7
7
|
"jsdelivr": "./build/statsig-js-client.min.js",
|
|
8
8
|
"type": "commonjs",
|
package/src/StatsigClient.d.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import { DynamicConfig, DynamicConfigEvaluationOptions, EvaluationsDataAdapter, Experiment, ExperimentEvaluationOptions, FeatureGate, FeatureGateEvaluationOptions, Layer, LayerEvaluationOptions, PrecomputedEvaluationsAsyncContext, PrecomputedEvaluationsContext, PrecomputedEvaluationsInterface, StatsigClientBase, StatsigEvent, StatsigUser } from '@statsig/client-core';
|
|
1
|
+
import { DataAdapterAsyncOptions, DynamicConfig, DynamicConfigEvaluationOptions, EvaluationsDataAdapter, Experiment, ExperimentEvaluationOptions, FeatureGate, FeatureGateEvaluationOptions, Layer, LayerEvaluationOptions, PrecomputedEvaluationsAsyncContext, PrecomputedEvaluationsContext, PrecomputedEvaluationsInterface, StatsigClientBase, StatsigEvent, StatsigUser } from '@statsig/client-core';
|
|
2
2
|
import type { StatsigOptions } from './StatsigOptions';
|
|
3
|
+
type AsyncOptions = DataAdapterAsyncOptions;
|
|
3
4
|
export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdapter> implements PrecomputedEvaluationsInterface {
|
|
4
5
|
private _store;
|
|
5
6
|
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
7
|
/**
|
|
15
8
|
* Retrieves an instance of the StatsigClient based on the provided SDK key.
|
|
16
9
|
* If no SDK key is provided, the method returns the most recently created instance of the StatsigClient.
|
|
@@ -19,7 +12,15 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
|
|
|
19
12
|
* @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
13
|
* @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
14
|
*/
|
|
22
|
-
static instance(sdkKey?: string): StatsigClient
|
|
15
|
+
static instance(sdkKey?: string): StatsigClient;
|
|
16
|
+
/**
|
|
17
|
+
* StatsigClient constructor
|
|
18
|
+
*
|
|
19
|
+
* @param {string} sdkKey A Statsig client SDK key. eg "client-xyz123..."
|
|
20
|
+
* @param {StatsigUser} user StatsigUser object containing various attributes related to a user.
|
|
21
|
+
* @param {StatsigOptions | null} options StatsigOptions, used to customize the behavior of the SDK.
|
|
22
|
+
*/
|
|
23
|
+
constructor(sdkKey: string, user: StatsigUser, options?: StatsigOptions | null);
|
|
23
24
|
/**
|
|
24
25
|
* Initializes the StatsigClient using cached values. This method sets up the client synchronously by utilizing previously cached values.
|
|
25
26
|
* After initialization, cache values are updated in the background for future use, either in subsequent sessions or when `updateUser` is called.
|
|
@@ -34,10 +35,11 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
|
|
|
34
35
|
* there might be a transition from cached to network values during the session, which can affect consistency.
|
|
35
36
|
* This method is useful when it's acceptable to begin with potentially stale data and switch to the latest configuration as it becomes available.
|
|
36
37
|
*
|
|
37
|
-
* @
|
|
38
|
+
* @param {AsyncOptions} [options] - Optional. Additional options to customize the method call.
|
|
39
|
+
* @returns {Promise<void>} A promise that resolves once the client is fully initialized with the latest values from the network or a timeout (if set) is hit.
|
|
38
40
|
* @see {@link initializeSync} for the synchronous version of this method.
|
|
39
41
|
*/
|
|
40
|
-
initializeAsync(): Promise<void>;
|
|
42
|
+
initializeAsync(options?: AsyncOptions): Promise<void>;
|
|
41
43
|
/**
|
|
42
44
|
* Synchronously updates the user in the Statsig client and switches the internal state to use cached values for the newly specified user.
|
|
43
45
|
* After the initial switch to cached values, this method updates these values in the background, preparing them for future sessions or subsequent calls to updateUser.
|
|
@@ -54,10 +56,11 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
|
|
|
54
56
|
* This method is best used in scenarios where up-to-date configuration is critical and initial delays are acceptable.
|
|
55
57
|
*
|
|
56
58
|
* @param {StatsigUser} user - The new StatsigUser for which the client should update its internal state.
|
|
57
|
-
* @
|
|
59
|
+
* @param {AsyncOptions} [options] - Optional. Additional options to customize the method call.
|
|
60
|
+
* @returns {Promise<void>} A promise that resolves once the client is fully updated with the latest values from the network or a timeout (if set) is hit.
|
|
58
61
|
* @see {@link updateUserSync} for the synchronous version of this method.
|
|
59
62
|
*/
|
|
60
|
-
updateUserAsync(user: StatsigUser): Promise<void>;
|
|
63
|
+
updateUserAsync(user: StatsigUser, options?: AsyncOptions): Promise<void>;
|
|
61
64
|
/**
|
|
62
65
|
* Retrieves a synchronous context containing data currently being used by the SDK. Represented as a {@link PrecomputedEvaluationsContext} object.
|
|
63
66
|
*
|
|
@@ -124,3 +127,4 @@ export default class StatsigClient extends StatsigClientBase<EvaluationsDataAdap
|
|
|
124
127
|
private _resetForUser;
|
|
125
128
|
private _getConfigImpl;
|
|
126
129
|
}
|
|
130
|
+
export {};
|
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.
|
|
@@ -62,11 +65,12 @@ class StatsigClient extends client_core_1.StatsigClientBase {
|
|
|
62
65
|
* there might be a transition from cached to network values during the session, which can affect consistency.
|
|
63
66
|
* This method is useful when it's acceptable to begin with potentially stale data and switch to the latest configuration as it becomes available.
|
|
64
67
|
*
|
|
65
|
-
* @
|
|
68
|
+
* @param {AsyncOptions} [options] - Optional. Additional options to customize the method call.
|
|
69
|
+
* @returns {Promise<void>} A promise that resolves once the client is fully initialized with the latest values from the network or a timeout (if set) is hit.
|
|
66
70
|
* @see {@link initializeSync} for the synchronous version of this method.
|
|
67
71
|
*/
|
|
68
|
-
initializeAsync() {
|
|
69
|
-
return this.updateUserAsync(this._user);
|
|
72
|
+
initializeAsync(options) {
|
|
73
|
+
return this.updateUserAsync(this._user, options);
|
|
70
74
|
}
|
|
71
75
|
/**
|
|
72
76
|
* Synchronously updates the user in the Statsig client and switches the internal state to use cached values for the newly specified user.
|
|
@@ -91,17 +95,18 @@ class StatsigClient extends client_core_1.StatsigClientBase {
|
|
|
91
95
|
* This method is best used in scenarios where up-to-date configuration is critical and initial delays are acceptable.
|
|
92
96
|
*
|
|
93
97
|
* @param {StatsigUser} user - The new StatsigUser for which the client should update its internal state.
|
|
94
|
-
* @
|
|
98
|
+
* @param {AsyncOptions} [options] - Optional. Additional options to customize the method call.
|
|
99
|
+
* @returns {Promise<void>} A promise that resolves once the client is fully updated with the latest values from the network or a timeout (if set) is hit.
|
|
95
100
|
* @see {@link updateUserSync} for the synchronous version of this method.
|
|
96
101
|
*/
|
|
97
|
-
updateUserAsync(user) {
|
|
102
|
+
updateUserAsync(user, options) {
|
|
98
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
104
|
this._resetForUser(user);
|
|
100
105
|
const initiator = this._user;
|
|
101
106
|
let result = this.dataAdapter.getDataSync(initiator);
|
|
102
107
|
this._setStatus('Loading', result);
|
|
103
108
|
this._store.setValuesFromDataAdapter(result);
|
|
104
|
-
result = yield this.dataAdapter.getDataAsync(result, initiator);
|
|
109
|
+
result = yield this.dataAdapter.getDataAsync(result, initiator, options);
|
|
105
110
|
// ensure the user hasn't changed while we were waiting
|
|
106
111
|
if (initiator === this._user) {
|
|
107
112
|
this._store.setValuesFromDataAdapter(result);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { AnyStatsigOptions, DataAdapterCore, EvaluationsDataAdapter, StatsigUser } from '@statsig/client-core';
|
|
1
|
+
import { AnyStatsigOptions, DataAdapterAsyncOptions, DataAdapterCore, DataAdapterResult, EvaluationsDataAdapter, StatsigUser } from '@statsig/client-core';
|
|
2
2
|
export declare class StatsigEvaluationsDataAdapter extends DataAdapterCore implements EvaluationsDataAdapter {
|
|
3
3
|
private _network;
|
|
4
4
|
constructor();
|
|
5
5
|
attach(sdkKey: string, options: AnyStatsigOptions | null): void;
|
|
6
|
+
getDataAsync(current: DataAdapterResult | null, user: StatsigUser, options?: DataAdapterAsyncOptions): Promise<DataAdapterResult | null>;
|
|
7
|
+
prefetchData(user: StatsigUser, options?: DataAdapterAsyncOptions): Promise<void>;
|
|
6
8
|
protected _fetchFromNetwork(current: string | null, user?: StatsigUser): Promise<string | null>;
|
|
7
9
|
}
|
|
@@ -21,6 +21,12 @@ class StatsigEvaluationsDataAdapter extends client_core_1.DataAdapterCore {
|
|
|
21
21
|
super.attach(sdkKey, options);
|
|
22
22
|
this._network = new Network_1.default(options !== null && options !== void 0 ? options : {});
|
|
23
23
|
}
|
|
24
|
+
getDataAsync(current, user, options) {
|
|
25
|
+
return this._getDataAsyncImpl(current, user, options);
|
|
26
|
+
}
|
|
27
|
+
prefetchData(user, options) {
|
|
28
|
+
return this._prefetchDataImpl(user, options);
|
|
29
|
+
}
|
|
24
30
|
_fetchFromNetwork(current, user) {
|
|
25
31
|
var _a;
|
|
26
32
|
return __awaiter(this, void 0, void 0, function* () {
|
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__;
|