configcat-vue
Version:
A community-maintained SDK for integrating ConfigCat feature flags into Vue.js applications.
9 lines • 84.9 kB
JavaScript
(function(h,$){typeof exports=="object"&&typeof module<"u"?$(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],$):(h=typeof globalThis<"u"?globalThis:h||self,$(h["configcat-vue"]={},h.Vue))})(this,(function(h,$){"use strict";class xe{constructor(){this.callbacks=[]}get aborted(){return!this.callbacks}abort(){if(!this.aborted){const e=this.callbacks;this.callbacks=void 0;for(const t of e)t()}}registerCallback(e){return this.aborted?(e(),()=>{}):(this.callbacks.push(e),()=>{const t=this.callbacks;let i;t&&(i=t.indexOf(e))>=0&&t.splice(i,1)})}}function Ot(n,e){let t;return new Promise(i=>{const s=e==null?void 0:e.registerCallback(()=>{clearTimeout(t),i(!1)});t=setTimeout(()=>{s==null||s(),i(!0)},n)})}const Ct=typeof performance<"u"&&P(performance==null?void 0:performance.now)?()=>performance.now():()=>new Date().getTime();function Tt(n){return new Cn(n)}const Cn=typeof WeakRef=="function"?WeakRef:Tn();function Tn(){const n=function(e){this.target=e};return n.prototype.deref=function(){return this.target},n.isFallback=!0,n}function L(n){try{return typeof n=="symbol"?"[symbol]":typeof n=="object"&&n!==null&&!P(n.toString)?Object.prototype.toString.call(n):String(n)}catch{return"[unknown]"}}function G(n,e=!1){return n instanceof Error?t(n,""):L(n);function t(i,s,r){const o=i.toString();let a=(s&&s.substring(4)+"--> ")+o;if(e&&i.stack){let l=i.stack.trim();l.lastIndexOf(o,0)===0&&(l=l.substring(o.length).trim()),a+=`
`+l.replace(/^\s*(?:at\s)?/gm,s+" at ")}if(typeof AggregateError=="function"&&i instanceof AggregateError){(r??(r=[])).push(i);for(const l of i.errors)if(l instanceof Error){if(r.indexOf(l)>=0)continue;a+=`
`+t(l,s+" ",r)}else a+=`
`+s+"--> "+L(l);r.pop()}return a}}function F(){return Object.create(null)}const bt=P(Object.setPrototypeOf)?Object.setPrototypeOf:(n,e)=>(n.__proto__=e,n);function je(n,e){n instanceof e||bt(n,e.prototype)}function D(n,e){return Object.prototype.hasOwnProperty.call(n,e)}function Ve(n){return typeof n=="boolean"}function W(n){return typeof n=="number"}function It(n,e,t){return W(n)&&e<=n&&n<=t}const Be=P(Number.isSafeInteger)?Number.isSafeInteger:n=>W(n)&&isFinite(n)&&Math.floor(n)===n&&Math.abs(n)<=9007199254740991;function Ke(n,e,t){return Be(n)&&e<=n&&n<=t}function S(n){return typeof n=="string"}function Se(n){return typeof n=="object"&&n!==null&&!M(n)}function M(n){return Array.isArray(n)}function wt(n){return M(n)&&!n.some(e=>!S(e))}function P(n){return typeof n=="function"}function Rt(n){return P(n==null?void 0:n.then)}function We(n,e,t){return Ve(n)||re(n,e,"boolean",t),n}function Nt(n,e,t){return W(n)||re(n,e,"number",t),n}function Ae(n,e,t,i,s){return Nt(n,e,s),i(n)||Q(e,`Expected a value ${t}, got ${n}.`,s,RangeError),n}function ee(n,e,t,i,s){return Nt(n,e,s),i(n)||Q(e,`Expected a valid \`${t}\` value, got '${n}'.`,s,RangeError),n}function Y(n,e,t,i){return S(n)||re(n,e,"string",i),n.length||!t||Q(e,"Expected a non-empty string.",i),n}function Ft(n,e,t){return P(n)||re(n,e,"function",t),n}function _(n,e,t,i){if(Se(n)||re(n,e,"object",i),t)for(const s in t){const r=t[s];(!(s in n)||r&&!P(n[s]))&&Q(e,`Expected an object with ${r?"method":"property"} \`${s}\`.`,i,TypeError)}return n}function re(n,e,t,i){Q(e,`Expected a value of type ${t}, got ${n===null?"null":typeof n}.`,i,TypeError)}function Q(n,e,t,i){const s=t?"property":(t="","argument");throw(i??Error)(`Invalid ${s} \`${n}${t}\`. ${e}`)}function ze(n,e=0,t,i=", "){const s=n.length;if(!s)return"";let r="";return e>0&&s>e&&(n=n.slice(0,e),t&&(r=t(s-e))),"'"+n.join("'"+i+"'")+"'"+r}function oe(n){function e(o,a){const l=o.charCodeAt(a);if(55296<=l&&l<56320){const c=o.charCodeAt(a+1);if(56320<=c&&c<=57343)return(l<<10)+c-56613888}return l}let t="",i=0;const s=String.fromCharCode;let r;for(r=0;r<n.length;r++){const o=e(n,r);o<=127||(t+=n.slice(i,r),o<=2047?(t+=s(192|o>>6),t+=s(128|o&63)):o<=65535?(t+=s(224|o>>12),t+=s(128|o>>6&63),t+=s(128|o&63)):(t+=s(240|o>>18),t+=s(128|o>>12&63),t+=s(128|o>>6&63),t+=s(128|o&63),++r),i=r+1)}return t+=n.slice(i,r)}function bn(n){if(!n.length||!/^\s*[+-]?\d+\s*$/.test(n))return NaN;const e=+n;return Be(e)?e:NaN}function Je(n){return!n.length||/^\s*$|^\s*0[^\d.eE]/.test(n)?NaN:+n}function Lt(n,e){const t={};for(const i in n)if(D(n,i)){const s=n[i];t[i]=e?e(i,s):s}return t}class ae{constructor(e,t){this.state=e,this.factoryOrValue=t}toString(){let{factoryOrValue:e}=this;return S(e)||(this.factoryOrValue=e=e(this.state),this.state=void 0),e}}class Dt{constructor(){this.events=F(),this.eventCount=0}addListenerCore(e,t,i){if(!P(t))throw TypeError("Listener must be a function");const s=this.events[e],r={fn:t,once:i};return s?M(s)?s.push(r):this.events[e]=[s,r]:(this.events[e]=r,this.eventCount++),this}removeListenerCore(e,t,i){const s=this.events[e];if(!s)return this;if(M(s)){for(let r=s.length-1;r>=0;r--)if(i(s[r],t)){s.splice(r,1),s.length?s.length===1&&(this.events[e]=s[0]):this.removeEvent(e);break}}else i(s,t)&&this.removeEvent(e);return this}removeEvent(e){--this.eventCount===0?this.events=F():delete this.events[e]}on(e,t){return this.addListenerCore(e,t,!1)}once(e,t){return this.addListenerCore(e,t,!0)}removeListener(e,t){if(!P(t))throw TypeError("Listener must be a function");return this.removeListenerCore(e,t,(i,s)=>i.fn===s)}removeAllListeners(e){return arguments.length?this.events[e]&&this.removeEvent(e):(this.events=F(),this.eventCount=0),this}listeners(e){const t=this.events[e];if(!t)return[];if(!M(t))return[t.fn];const i=t.length,s=new Array(i);for(let r=0;r<i;r++)s[r]=t[r].fn;return s}listenerCount(e){const t=this.events[e];return t?M(t)?t.length:1:0}eventNames(){const e=[];if(this.eventCount===0)return e;const t=this.events;for(const i in t)e.push(i);return P(Object.getOwnPropertySymbols)?e.concat(Object.getOwnPropertySymbols(t)):e}emit(e,t,i,s,r,...o){let a=this.events[e];if(!a)return!1;let l,c;M(a)?(a=a.slice(),[l,c]=[a[0],a.length]):[l,c]=[a,1];const f=arguments.length-1;for(let u=0;;){switch(l.once&&this.removeListenerCore(e,l,(g,d)=>g===d),f){case 0:l.fn.call(this);break;case 1:l.fn.call(this,t);break;case 2:l.fn.call(this,t,i);break;case 3:l.fn.call(this,t,i,s);break;case 4:l.fn.call(this,t,i,s,r);break;default:const g=new Array(f);for(let d=0;d<f;d++)g[d]=arguments[d+1];l.fn.apply(this,g);break}if(++u>=c)break;l=a[u]}return!0}}const Oe=Dt.prototype;Oe.addListener=Oe.on,Oe.off=Oe.removeListener;var Ge;(function(n){n[n.No=0]="No",n[n.Should=1]="Should",n[n.Force=2]="Force"})(Ge||(Ge={})),h.SettingType=void 0,(function(n){n[n.Boolean=0]="Boolean",n[n.String=1]="String",n[n.Int=2]="Int",n[n.Double=3]="Double"})(h.SettingType||(h.SettingType={})),h.UserComparator=void 0,(function(n){n[n.TextIsOneOf=0]="TextIsOneOf",n[n.TextIsNotOneOf=1]="TextIsNotOneOf",n[n.TextContainsAnyOf=2]="TextContainsAnyOf",n[n.TextNotContainsAnyOf=3]="TextNotContainsAnyOf",n[n.SemVerIsOneOf=4]="SemVerIsOneOf",n[n.SemVerIsNotOneOf=5]="SemVerIsNotOneOf",n[n.SemVerLess=6]="SemVerLess",n[n.SemVerLessOrEquals=7]="SemVerLessOrEquals",n[n.SemVerGreater=8]="SemVerGreater",n[n.SemVerGreaterOrEquals=9]="SemVerGreaterOrEquals",n[n.NumberEquals=10]="NumberEquals",n[n.NumberNotEquals=11]="NumberNotEquals",n[n.NumberLess=12]="NumberLess",n[n.NumberLessOrEquals=13]="NumberLessOrEquals",n[n.NumberGreater=14]="NumberGreater",n[n.NumberGreaterOrEquals=15]="NumberGreaterOrEquals",n[n.SensitiveTextIsOneOf=16]="SensitiveTextIsOneOf",n[n.SensitiveTextIsNotOneOf=17]="SensitiveTextIsNotOneOf",n[n.DateTimeBefore=18]="DateTimeBefore",n[n.DateTimeAfter=19]="DateTimeAfter",n[n.SensitiveTextEquals=20]="SensitiveTextEquals",n[n.SensitiveTextNotEquals=21]="SensitiveTextNotEquals",n[n.SensitiveTextStartsWithAnyOf=22]="SensitiveTextStartsWithAnyOf",n[n.SensitiveTextNotStartsWithAnyOf=23]="SensitiveTextNotStartsWithAnyOf",n[n.SensitiveTextEndsWithAnyOf=24]="SensitiveTextEndsWithAnyOf",n[n.SensitiveTextNotEndsWithAnyOf=25]="SensitiveTextNotEndsWithAnyOf",n[n.SensitiveArrayContainsAnyOf=26]="SensitiveArrayContainsAnyOf",n[n.SensitiveArrayNotContainsAnyOf=27]="SensitiveArrayNotContainsAnyOf",n[n.TextEquals=28]="TextEquals",n[n.TextNotEquals=29]="TextNotEquals",n[n.TextStartsWithAnyOf=30]="TextStartsWithAnyOf",n[n.TextNotStartsWithAnyOf=31]="TextNotStartsWithAnyOf",n[n.TextEndsWithAnyOf=32]="TextEndsWithAnyOf",n[n.TextNotEndsWithAnyOf=33]="TextNotEndsWithAnyOf",n[n.ArrayContainsAnyOf=34]="ArrayContainsAnyOf",n[n.ArrayNotContainsAnyOf=35]="ArrayNotContainsAnyOf"})(h.UserComparator||(h.UserComparator={})),h.PrerequisiteFlagComparator=void 0,(function(n){n[n.Equals=0]="Equals",n[n.NotEquals=1]="NotEquals"})(h.PrerequisiteFlagComparator||(h.PrerequisiteFlagComparator={})),h.SegmentComparator=void 0,(function(n){n[n.IsIn=0]="IsIn",n[n.IsNotIn=1]="IsNotIn"})(h.SegmentComparator||(h.SegmentComparator={}));const In=Object.freeze(Object.defineProperty({__proto__:null,get PrerequisiteFlagComparator(){return h.PrerequisiteFlagComparator},get RedirectMode(){return Ge},get SegmentComparator(){return h.SegmentComparator},get SettingType(){return h.SettingType},get UserComparator(){return h.UserComparator}},Symbol.toStringTag,{value:"Module"}));class b{static contentEquals(e,t){return e.httpETag&&t.httpETag?e.httpETag===t.httpETag:e.configJson===t.configJson}constructor(e,t,i,s){this.configJson=e,this.config=t,this.timestamp=i,this.httpETag=s}with(e){return new b(this.configJson,this.config,e,this.httpETag)}get isEmpty(){return!this.config}isExpired(e){return this===b.empty||this.timestamp+e<b.generateTimestamp()}static generateTimestamp(){return new Date().getTime()}static serialize(e){var t,i;return e.timestamp+`
`+((t=e.httpETag)!==null&&t!==void 0?t:"")+`
`+((i=e.configJson)!==null&&i!==void 0?i:"")}static deserialize(e){const t=Array(2);let i=0;for(let f=0;f<t.length;f++){if(i=e.indexOf(`
`,i),i<0)throw Error("Number of values is fewer than expected.");t[f]=i++}let s=t[0],r=e.substring(0,s);const o=parseInt(r);if(isNaN(o))throw Error("Invalid fetch time: "+r);i=s+1,s=t[1],r=e.substring(i,s);const a=r.length>0?r:void 0;i=s+1,r=e.substring(i);let l,c;return r.length>0&&(l=Ye(r),c=r),new b(c,l,o,a)}}b.serializationFormatVersion="v2",b.empty=new b(void 0,void 0,0,void 0);function V(n){return n?new Date(n.timestamp):void 0}function Ye(n){Y(n,"configJson",!0);const e=JSON.parse(n);return Qe(e)}function Qe(n){var e;wn(n,["$"]);const t=n.f;if(t){const i=(e=n.p)===null||e===void 0?void 0:e.s,s=n.s;for(const r in t)if(D(t,r)){const o=t[r];o._configJsonSalt=i,o._configSegments=s}}return n}function Xe(n){const e=Object.create(Ze);return e.t=-1,e.v=n,e}const Ze=Object.create(null);Ze.toString=function(){return Object.prototype.toString.call(this)};function wn(n,e){n==null&&tt(e),k(n,e),p(n,"p",e,Rn),p(n,"s",e,Nn),p(n,"f",e,Ln)}function Rn(n,e){k(n,e),p(n,"r",e,z),p(n,"u",e,x),p(n,"s",e,x)}function Nn(n,e){ne(n,e);for(let t=0;t<n.length;t++)te(n,t,e,Fn)}function Fn(n,e){k(n,e),p(n,"n",e,x,!0),p(n,"r",e,Mn)}function Ln(n,e){k(n,e);for(const t in n)D(n,t)&&p(n,t,e,Dn,!0)}function Dn(n,e){k(n,e),p(n,"t",e,z,!0),p(n,"a",e,x),p(n,"r",e,kn),p(n,"p",e,$t),et(n,e)}function kn(n,e){ne(n,e);for(let t=0;t<n.length;t++)te(n,t,e,$n)}function $n(n,e){k(n,e),p(n,"c",e,Un),p(n,"s",e,et),p(n,"p",e,$t)}function Un(n,e){ne(n,e);for(let t=0;t<n.length;t++)te(n,t,e,Pn)}function Mn(n,e){ne(n,e);for(let t=0;t<n.length;t++)te(n,t,e,kt)}function Pn(n,e){k(n,e),p(n,"u",e,kt),p(n,"p",e,qn),p(n,"s",e,Hn)}function kt(n,e){k(n,e),p(n,"a",e,x,!0),p(n,"c",e,z,!0),p(n,"s",e,x),p(n,"d",e,Mt),p(n,"l",e,_n)}function _n(n,e){ne(n,e);for(let t=0;t<n.length;t++)te(n,t,e,x)}function qn(n,e){k(n,e),p(n,"f",e,x,!0),p(n,"c",e,z,!0),p(n,"v",e,Ut,!0)}function Hn(n,e){k(n,e),p(n,"s",e,z,!0),p(n,"c",e,z,!0)}function $t(n,e){ne(n,e);for(let t=0;t<n.length;t++)te(n,t,e,xn)}function xn(n,e){k(n,e),p(n,"p",e,z,!0),et(n,e)}function et(n,e){k(n,e),p(n,"v",e,Ut,!0),p(n,"i",e,x)}function Ut(n,e){k(n,e),p(n,"b",e,jn),p(n,"s",e,x),p(n,"i",e,z),p(n,"d",e,Mt)}function te(n,e,t,i){const s=n[e];t.push(`[${e}]`),s==null&&tt(t),i(s,t),t.pop()}function p(n,e,t,i,s){const r=n[e];t.push(`.${e}`),r==null?s&&tt(t):i(r,t),t.pop()}function ne(n,e){M(n)||ie(e)}function k(n,e){Se(n)||ie(e),bt(n,Ze)}function jn(n,e){Ve(n)||ie(e)}function x(n,e){S(n)||ie(e)}function z(n,e){Be(n)||ie(e)}function Mt(n,e){W(n)||ie(e)}function tt(n){throw TypeError(`Invalid config JSON content. Missing required value at ${n.join("")}`)}function ie(n){throw TypeError(`Invalid config JSON content. Type mismatch at ${n.join("")}`)}function Vn(n){return h.SettingType[n]}function nt(n){const e=n.t;if(Ke(e,0,3)||e===-1&&Kn(n))return e;I("Setting type is invalid.")}function it(n){switch(typeof n){case"boolean":return 0;case"string":return 1;case"number":return 3}}function Bn(n,e){switch(e){case 0:return Ve(n);case 1:return S(n);case 2:case 3:return W(n);default:return!1}}function st(n){return it(n)!==void 0}function Kn(n){var e,t;return!(!((e=n.r)===null||e===void 0)&&e.length)&&!(!((t=n.p)===null||t===void 0)&&t.length)}function rt(n,e){const t=n.s,i=n.p;if(t!=null){if(i==null)return!1}else if(i!=null&&i.length)return!0;e||I("Targeting rule THEN part is missing or invalid.")}function Wn(n){let e,t;return t=n.u,t!=null&&(e="u"),t=n.p,t!=null&&(e=e?!1:"p"),t=n.s,t!=null&&(e=e?!1:"s"),e||I("Condition is missing or invalid."),e}function q(n,e,t){switch(e){case 0:{const i=n.b;if(i!=null)return i;break}case 1:{const i=n.s;if(i!=null)return i;break}case 2:{const i=n.i;if(i!=null)return i;break}case 3:{const i=n.d;if(i!=null)return i;break}case-1:if(st(n))return n;default:t||I(n===null?"Setting value is null.":n===void 0?"Setting value is undefined.":`Setting value '${L(n)}' is of an unsupported type (${typeof n}).`);return}t||I("Setting value is missing or invalid.")}function I(n){throw new le(n)}class le extends Error{constructor(e){super(e),this.message=e,this.name=le.name,je(this,le)}}class Pt{constructor(){this.cachedConfig=b.empty}set(e,t){this.cachedConfig=t}get(e){return this.cachedConfig}getInMemory(){return this.cachedConfig}}class Ce{constructor(e,t){this.cache=e,this.logger=t,this.cachedConfig=b.empty,this.cachedSerializedConfig=void 0}async set(e,t){try{if(!t.isEmpty)this.cachedSerializedConfig=b.serialize(t),this.cachedConfig=t;else{this.cachedSerializedConfig=void 0,this.cachedConfig=t;return}await this.cache.set(e,this.cachedSerializedConfig)}catch(i){this.logger.configServiceCacheWriteError(i)}}updateCachedConfig(e){if(e==null||e===this.cachedSerializedConfig)return this.cachedConfig;const t=b.deserialize(e),i=!b.contentEquals(t,this.cachedConfig);return this.cachedConfig=t,this.cachedSerializedConfig=e,i?[this.cachedConfig]:this.cachedConfig}get(e){let t;try{const i=this.cache.get(e);if(Rt(i))return(async s=>{let r;try{r=this.updateCachedConfig(await s)}catch(o){r=this.cachedConfig,this.logger.configServiceCacheReadError(o)}return r})(i);t=this.updateCachedConfig(i)}catch(i){t=this.cachedConfig,this.logger.configServiceCacheReadError(i)}return t}getInMemory(){return this.cachedConfig}}h.LogLevel=void 0,(function(n){n[n.Debug=4]="Debug",n[n.Info=3]="Info",n[n.Warn=2]="Warn",n[n.Error=1]="Error",n[n.Off=-1]="Off"})(h.LogLevel||(h.LogLevel={}));function _t(n){return h.LogLevel[n]}class m{static from(...e){return(t,...i)=>new m(t,e,i)}constructor(e,t,i){this.strings=e,this.argNames=t,this.argValues=i,this.cachedDefaultFormattedMessage=void 0}get defaultFormattedMessage(){let e=this.cachedDefaultFormattedMessage;if(!S(e)){e="";const{strings:t,argValues:i}=this;let s=0;for(;s<t.length-1;s++)e+=t[s],e+=L(i[s]);e+=t[s],this.cachedDefaultFormattedMessage=e}return e}toString(){return this.defaultFormattedMessage}}function B(n){var e;return S(n)?n:(e=n.cachedDefaultFormattedMessage)!==null&&e!==void 0?e:new ae(n,t=>t.defaultFormattedMessage)}class zn{get level(){var e;return(e=this.logger.level)!==null&&e!==void 0?e:2}get eol(){var e;return(e=this.logger.eol)!==null&&e!==void 0?e:`
`}constructor(e,t,i){this.logger=e,this.filter=t,this.hooks=i}isEnabled(e){return this.level>=e}log(e,t,i,s){var r;return this.isEnabled(e)&&(!this.filter||this.filter(e,t,i,s))&&this.logger.log(e,t,i,s),e===1&&((r=this.hooks)===null||r===void 0||r.emit("clientError",B(i),s)),i}debug(e,t){this.log(4,0,e,t)}configJsonIsNotPresent(e){return this.log(1,1e3,m.from("DEFAULT_RETURN_VALUE")`Config JSON is not present. Returning ${e}.`)}configJsonIsNotPresentSingle(e,t,i){return this.log(1,1e3,m.from("KEY","DEFAULT_PARAM_NAME","DEFAULT_PARAM_VALUE")`Config JSON is not present when evaluating setting '${e}'. Returning the \`${t}\` parameter that you specified in your application: '${i}'.`)}settingEvaluationFailedDueToMissingKey(e,t,i,s){return this.log(1,1001,m.from("KEY","DEFAULT_PARAM_NAME","DEFAULT_PARAM_VALUE","AVAILABLE_KEYS")`Failed to evaluate setting '${e}' (the key was not found in config JSON). Returning the \`${t}\` parameter that you specified in your application: '${i}'. Available keys: [${s}].`)}settingEvaluationError(e,t,i){return this.log(1,1002,m.from("METHOD_NAME","DEFAULT_RETURN_VALUE")`Error occurred in the \`${e}\` method. Returning ${t}.`,i)}settingEvaluationErrorSingle(e,t,i,s,r){return this.log(1,1002,m.from("METHOD_NAME","KEY","DEFAULT_PARAM_NAME","DEFAULT_PARAM_VALUE")`Error occurred in the \`${e}\` method while evaluating setting '${t}'. Returning the \`${i}\` parameter that you specified in your application: '${s}'.`,r)}clientMethodError(e,t){return this.log(1,1003,m.from("METHOD_NAME")`Error occurred in the \`${e}\` method.`,t)}fetchFailedDueToInvalidSdkKey(e,t){return e=Ht(e),this.log(1,1100,t==null?m.from("SDK_KEY")`Your SDK Key seems to be wrong: '${e}'. You can find the valid SDK Key at https://app.configcat.com/sdkkey`:m.from("SDK_KEY","RAY_ID")`Your SDK Key seems to be wrong: '${e}'. You can find the valid SDK Key at https://app.configcat.com/sdkkey (Ray ID: ${t})`)}fetchFailedDueToUnexpectedHttpResponse(e,t,i){return this.log(1,1101,i==null?m.from("STATUS_CODE","REASON_PHRASE")`Unexpected HTTP response was received while trying to fetch config JSON: ${e} ${t}`:m.from("STATUS_CODE","REASON_PHRASE","RAY_ID")`Unexpected HTTP response was received while trying to fetch config JSON: ${e} ${t} (Ray ID: ${i})`)}fetchFailedDueToRequestTimeout(e,t){return this.log(1,1102,m.from("TIMEOUT")`Request timed out while trying to fetch config JSON. Timeout value: ${e}ms`,t)}fetchFailedDueToUnexpectedError(e){return this.log(1,1103,"Unexpected error occurred while trying to fetch config JSON. It is most likely due to a local network issue. Please make sure your application can reach the ConfigCat CDN servers (or your proxy server) over HTTP.",e)}fetchFailedDueToRedirectLoop(e){return this.log(1,1104,e==null?"Redirection loop encountered while trying to fetch config JSON. Please contact us at https://configcat.com/support/":m.from("RAY_ID")`Redirection loop encountered while trying to fetch config JSON. Please contact us at https://configcat.com/support/ (Ray ID: ${e})`)}fetchReceived200WithInvalidBody(e,t){return this.log(1,1105,e==null?"Fetching config JSON was successful but the HTTP response content was invalid.":m.from("RAY_ID")`Fetching config JSON was successful but the HTTP response content was invalid. (Ray ID: ${e})`,t)}fetchReceived304WhenLocalCacheIsEmpty(e,t,i){return this.log(1,1106,i==null?m.from("STATUS_CODE","REASON_PHRASE")`Unexpected HTTP response was received when no config JSON is cached locally: ${e} ${t}`:m.from("STATUS_CODE","REASON_PHRASE","RAY_ID")`Unexpected HTTP response was received when no config JSON is cached locally: ${e} ${t} (Ray ID: ${i})`)}autoPollConfigServiceErrorDuringPolling(e){return this.log(1,1200,"Error occurred during auto polling.",e)}settingForVariationIdIsNotPresent(e){return this.log(1,2011,m.from("VARIATION_ID")`Could not find the setting for the specified variation ID: '${e}'.`)}configServiceCacheReadError(e){return this.log(1,2200,"Error occurred while reading the cache.",e)}configServiceCacheWriteError(e){return this.log(1,2201,"Error occurred while writing the cache.",e)}clientIsAlreadyCreated(e){return e=Ht(e),this.log(2,3e3,m.from("SDK_KEY")`There is an existing client instance for the specified SDK Key. No new client instance will be created and the specified options are ignored. Returning the existing client instance. SDK Key: '${e}'.`)}userObjectIsMissing(e){return this.log(2,3001,m.from("KEY")`Cannot evaluate targeting rules and % options for setting '${e}' (User Object is missing). You should pass a User Object to the evaluation methods like \`getValueAsync()\` in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/`)}dataGovernanceIsOutOfSync(){return this.log(2,3002,"The `dataGovernance` parameter specified at the client initialization is not in sync with the preferences on the ConfigCat Dashboard. Read more: https://configcat.com/docs/advanced/data-governance/")}userObjectAttributeIsMissingPercentage(e,t){return this.log(2,3003,m.from("KEY","ATTRIBUTE_NAME","ATTRIBUTE_NAME")`Cannot evaluate % options for setting '${e}' (the User.${t} attribute is missing). You should set the User.${t} attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/`)}userObjectAttributeIsMissingCondition(e,t,i){return this.log(2,3003,m.from("CONDITION","KEY","ATTRIBUTE_NAME","ATTRIBUTE_NAME")`Cannot evaluate condition (${e}) for setting '${t}' (the User.${i} attribute is missing). You should set the User.${i} attribute in order to make targeting work properly. Read more: https://configcat.com/docs/advanced/user-object/`)}userObjectAttributeIsInvalid(e,t,i,s){return this.log(2,3004,m.from("CONDITION","KEY","REASON","ATTRIBUTE_NAME")`Cannot evaluate condition (${e}) for setting '${t}' (${i}). Please check the User.${s} attribute and make sure that its value corresponds to the comparison operator.`)}userObjectAttributeIsAutoConverted(e,t,i,s){return this.log(2,3005,m.from("CONDITION","KEY","ATTRIBUTE_NAME","ATTRIBUTE_VALUE")`Evaluation of condition (${e}) for setting '${t}' may not produce the expected result (the User.${i} attribute is not a string value, thus it was automatically converted to the string value '${s}'). Please make sure that using a non-string value was intended.`)}configServiceCannotInitiateHttpCalls(){return this.log(2,3200,"Client is in offline mode, it cannot initiate HTTP calls.")}configServiceMethodHasNoEffectDueToDisposedClient(e){return this.log(2,3201,m.from("METHOD_NAME")`The client object is already disposed, thus \`${e}()\` has no effect.`)}configServiceMethodHasNoEffectDueToOverrideBehavior(e,t){return this.log(2,3202,m.from("OVERRIDE_BEHAVIOR","METHOD_NAME")`Client is configured to use the \`${e}\` override behavior, thus \`${t}()\` has no effect.`)}settingEvaluated(e){return this.log(3,5e3,m.from("EVALUATE_LOG")`${e}`)}configServiceStatusChanged(e){return this.log(3,5200,m.from("MODE")`Switched to ${e.toUpperCase()} mode.`)}}class qt{constructor(e=2,t=`
`){this.level=e,this.eol=t,this.SOURCE="ConfigCat"}log(e,t,i,s){const[r,o]=e===4?[console.info,"DEBUG"]:e===3?[console.info,"INFO"]:e===2?[console.warn,"WARN"]:e===1?[console.error,"ERROR"]:[console.log,_t(e).toUpperCase()],a=s!==void 0?this.eol+G(s,!0):"";r(`${this.SOURCE} - ${o} - [${t}] ${i}${a}`)}}function Ht(n){return n.substring(0,n.length-6).replace(/[^/]/g,"*")+n.substring(n.length-6)}var xt;(function(n){n[n.Fetched=0]="Fetched",n[n.NotModified=1]="NotModified",n[n.Errored=2]="Errored"})(xt||(xt={}));function Jn(n){return{status:0,config:n,errorCode:0}}function Gn(n){return{status:1,config:n,errorCode:0}}function ce(n,e,t,i){return{status:2,config:n,errorCode:e,errorMessage:t,errorException:i}}class jt{constructor(e,t,i,s){this.url=e,this.lastETag=t,this.headers=i,this.timeoutMs=s}}class ot{constructor(e,t,i,s){this.statusCode=e,this.reasonPhrase=t,this.body=s,this.eTag=void 0,this.rayId=void 0;let r,o;for(const[a,l]of i){const c=a.toLowerCase();if(r==null&&c==="etag"){if(this.eTag=r=l,o!=null)break}else if(o==null&&c==="cf-ray"&&(this.rayId=o=l,r!=null))break}}}class H extends Error{constructor(e,...t){super(((i,s)=>{switch(i){case"abort":return"Request was aborted.";case"timeout":const[r]=s;return`Request timed out. Timeout value: ${r}ms`;case"failure":const[o]=s,a="Request failed due to a network or protocol error.";return o?a+" "+(o instanceof Error?o.message:L(o)):a}})(e,t)),this.cause=e,this.name=H.name,je(this,H),this.args=t}}h.RefreshErrorCode=void 0,(function(n){n[n.UnexpectedError=-1]="UnexpectedError",n[n.None=0]="None",n[n.LocalOnlyClient=1]="LocalOnlyClient",n[n.OfflineClient=3200]="OfflineClient",n[n.InvalidSdkKey=1100]="InvalidSdkKey",n[n.UnexpectedHttpResponse=1101]="UnexpectedHttpResponse",n[n.HttpRequestTimeout=1102]="HttpRequestTimeout",n[n.HttpRequestFailure=1103]="HttpRequestFailure",n[n.InvalidHttpResponseContent=1105]="InvalidHttpResponseContent",n[n.InvalidHttpResponseWhenLocalCacheIsEmpty=1106]="InvalidHttpResponseWhenLocalCacheIsEmpty"})(h.RefreshErrorCode||(h.RefreshErrorCode={}));function Vt(){return{isSuccess:!0,errorCode:0}}function Te(n,e,t){return{isSuccess:!1,errorCode:n,_errorMessage:e,get errorMessage(){var i;return(i=this._errorMessage)===null||i===void 0?void 0:i.toString()},errorException:t}}function Bt(n){return n.status!==2?Vt():Te(n.errorCode,n.errorMessage,n.errorException)}h.ClientCacheState=void 0,(function(n){n[n.NoFlagData=0]="NoFlagData",n[n.HasLocalOverrideFlagDataOnly=1]="HasLocalOverrideFlagDataOnly",n[n.HasCachedFlagDataOnly=2]="HasCachedFlagDataOnly",n[n.HasUpToDateFlagData=3]="HasUpToDateFlagData"})(h.ClientCacheState||(h.ClientCacheState={}));var at;(function(n){n[n.Online=0]="Online",n[n.Offline=1]="Offline",n[n.Disposed=2]="Disposed"})(at||(at={}));function Kt(n){return at[n]}class lt{constructor(e){this.options=e,this.pendingCacheSyncUp=null,this.pendingConfigRefresh=null,this.cacheKey=e.getCacheKey(),this.configFetcher=e.configFetcher,this.requestHeaders=[["User-Agent",e.clientVersion],["X-ConfigCat-UserAgent",e.clientVersion]],this.status=e.offline?1:0}prepareClientForEvents(){var e;const t=(e=this.options.hooks.unwrap())===null||e===void 0?void 0:e.configCatClient,i=t==null?void 0:t.initConfigService;P(i)&&i.call(t,this)}dispose(){this.status=2}get disposed(){return this.status===2}async refreshConfigAsync(){const e=await this.syncUpWithCache();if(this.isOffline){if(this.options.cache instanceof Ce)return[Vt(),e];{const t=this.options.logger.configServiceCannotInitiateHttpCalls();return[Te(3200,B(t)),e]}}else{const[t,i]=await this.refreshConfigCoreAsync(e,!0);return[Bt(t),i]}}refreshConfigCoreAsync(e,t){if(this.pendingConfigRefresh)return this.pendingConfigRefresh;const i=(async s=>{const r=await this.fetchAsync(s);return(r.status===0||r.status===1||r.config.timestamp>s.timestamp&&(!r.config.isEmpty||this.options.cache.getInMemory().isEmpty))&&(await this.options.cache.set(this.cacheKey,r.config),s=r.config),this.onConfigFetched(r,t),r.status===0&&this.onConfigChanged(r.config),[r,s]})(e);this.pendingConfigRefresh=i;try{i.finally(()=>this.pendingConfigRefresh=null)}catch(s){throw this.pendingConfigRefresh=null,s}return i}onConfigFetched(e,t){this.options.logger.debug("config fetched"),this.options.hooks.emit("configFetched",Bt(e),t)}onConfigChanged(e){var t;this.options.logger.debug("config changed"),this.options.hooks.emit("configChanged",(t=e.config)!==null&&t!==void 0?t:Qe({}))}async fetchAsync(e){const t=this.options;t.logger.debug("ConfigServiceBase.fetchAsync() called.");let i;try{const[s,r,o]=await this.fetchRequestAsync(e.httpETag);switch(s.statusCode){case 200:return r?(t.logger.debug("ConfigServiceBase.fetchAsync(): fetch was successful. Returning new config."),Jn(new b(s.body,r,b.generateTimestamp(),s.eTag))):(i=t.logger.fetchReceived200WithInvalidBody(s.rayId,o),t.logger.debug(`ConfigServiceBase.fetchAsync(): ${s.statusCode} ${s.reasonPhrase} was received but the HTTP response content was invalid. Returning null.`),ce(e,1105,B(i),o));case 304:return e.isEmpty?(i=t.logger.fetchReceived304WhenLocalCacheIsEmpty(s.statusCode,s.reasonPhrase,s.rayId),t.logger.debug(`ConfigServiceBase.fetchAsync(): ${s.statusCode} ${s.reasonPhrase} was received when no config is cached locally. Returning null.`),ce(e,1106,B(i))):(t.logger.debug("ConfigServiceBase.fetchAsync(): content was not modified. Returning last config with updated timestamp."),Gn(e.with(b.generateTimestamp())));case 403:case 404:return i=t.logger.fetchFailedDueToInvalidSdkKey(t.sdkKey,s.rayId),t.logger.debug("ConfigServiceBase.fetchAsync(): fetch was unsuccessful. Returning last config (if any) with updated timestamp."),ce(e.with(b.generateTimestamp()),1100,B(i));default:return i=t.logger.fetchFailedDueToUnexpectedHttpResponse(s.statusCode,s.reasonPhrase,s.rayId),t.logger.debug("ConfigServiceBase.fetchAsync(): fetch was unsuccessful. Returning null."),ce(e,1101,B(i))}}catch(s){let r;return[r,i]=s instanceof H&&s.cause==="timeout"?[1102,t.logger.fetchFailedDueToRequestTimeout(s.args[0],s)]:[1103,t.logger.fetchFailedDueToUnexpectedError(s)],t.logger.debug("ConfigServiceBase.fetchAsync(): fetch was unsuccessful. Returning null."),ce(e,r,B(i),s)}}async fetchRequestAsync(e,t=2){const i=this.options;i.logger.debug("ConfigServiceBase.fetchRequestAsync() called.");for(let s=0;;s++){i.logger.debug(`ConfigServiceBase.fetchRequestAsync(): calling fetchLogic()${s>0?`, retry ${s}/${t}`:""}.`);const r=new jt(i.getUrl(),e,this.requestHeaders,i.requestTimeoutMs),o=await this.configFetcher.fetchAsync(r);if(o.statusCode!==200)return[o];if(!o.body)return i.logger.debug("ConfigServiceBase.fetchRequestAsync(): no response body."),[o,void 0,Error("No response body.")];let a;try{a=Ye(o.body)}catch(u){return i.logger.debug("ConfigServiceBase.fetchRequestAsync(): invalid response body."),[o,void 0,u]}const l=a.p;if(!l)return i.logger.debug("ConfigServiceBase.fetchRequestAsync(): preferences are missing or invalid."),[o,a];const c=l.u;if(c==null||c===i.baseUrl)return i.logger.debug("ConfigServiceBase.fetchRequestAsync(): baseUrl OK."),[o,a];const f=l.r;if(i.baseUrlOverriden&&f!==2)return i.logger.debug("ConfigServiceBase.fetchRequestAsync(): options.baseUrlOverriden && redirect !== 2."),[o,a];if(i.baseUrl=c,f===0)return[o,a];if(f===1&&i.logger.dataGovernanceIsOutOfSync(),s>=t)return i.logger.fetchFailedDueToRedirectLoop(o.rayId),[o,a]}}get isOfflineExactly(){return this.status===1}get isOffline(){return this.status!==0}goOnline(){}setOnline(){this.status===1?(this.goOnline(),this.status=0,this.options.logger.configServiceStatusChanged(Kt(this.status))):this.disposed&&this.options.logger.configServiceMethodHasNoEffectDueToDisposedClient("setOnline")}setOffline(){this.status===0?(this.status=1,this.options.logger.configServiceStatusChanged(Kt(this.status))):this.disposed&&this.options.logger.configServiceMethodHasNoEffectDueToDisposedClient("setOffline")}syncUpWithCache(){const{cache:e}=this.options;if(e instanceof Pt)return e.get(this.cacheKey);if(this.pendingCacheSyncUp)return this.pendingCacheSyncUp;const t=e.get(this.cacheKey);if(!Rt(t))return this.onCacheSynced(t);const i=t.then(s=>this.onCacheSynced(s));this.pendingCacheSyncUp=i;try{i.finally(()=>this.pendingCacheSyncUp=null)}catch(s){throw this.pendingCacheSyncUp=null,s}return i}onCacheSynced(e){if(!M(e))return e;const[t]=e;return t.isEmpty||this.onConfigChanged(t),t}async waitForReadyAsync(e){return this.getCacheState(await e)}getReadyPromise(e){return this.waitForReadyAsync(e).then(t=>(this.options.hooks.emit("clientReady",t),t))}}const Yn=500;class Qn extends lt{constructor(e){super(e),this.signalInitialization=()=>{},this.stopToken=new xe,this.pollIntervalMs=e.pollIntervalSeconds*1e3,this.pollExpirationMs=this.pollIntervalMs-Yn,this.prepareClientForEvents();const t=this.syncUpWithCache();if(e.maxInitWaitTimeSeconds!==0){this.initialized=!1;const i=new Promise(s=>this.signalInitialization=s);this.initializationPromise=this.waitForInitializationAsync(i).then(s=>(this.initialized=!0,s))}else this.initialized=!0,this.initializationPromise=Promise.resolve(!1);this.readyPromise=this.getReadyPromise(t),this.startRefreshWorker(t,this.stopToken)}async waitForInitializationAsync(e){if(this.options.maxInitWaitTimeSeconds<0)return await e,!0;const t=new xe,i=await Promise.race([e.then(()=>!0),Ot(this.options.maxInitWaitTimeSeconds*1e3,t).then(()=>!1)]);return t.abort(),i}async waitForReadyAsync(){return await this.initializationPromise,this.getCacheState(this.options.cache.getInMemory())}async getConfigAsync(){this.options.logger.debug("AutoPollConfigService.getConfigAsync() called.");let e=await this.syncUpWithCache();if(!e.isExpired(this.pollIntervalMs))this.signalInitialization();else if(!this.isOffline&&!this.initialized)this.options.logger.debug("AutoPollConfigService.getConfigAsync() - cache is empty or expired, waiting for initialization."),await this.initializationPromise,e=this.options.cache.getInMemory();else return this.options.logger.debug("AutoPollConfigService.getConfigAsync() - cache is empty or expired."),e;return this.options.logger.debug("AutoPollConfigService.getConfigAsync() - returning value from cache."),e}refreshConfigAsync(){return this.options.logger.debug("AutoPollConfigService.refreshConfigAsync() called."),super.refreshConfigAsync()}dispose(){this.options.logger.debug("AutoPollConfigService.dispose() called."),super.dispose(),this.stopToken.aborted||this.stopRefreshWorker()}onConfigFetched(e,t){this.signalInitialization(),super.onConfigFetched(e,t)}goOnline(){this.stopRefreshWorker(),this.stopToken=new xe,this.startRefreshWorker(null,this.stopToken)}async startRefreshWorker(e,t){for(this.options.logger.debug("AutoPollConfigService.startRefreshWorker() called.");!t.aborted;){try{const i=Ct()+this.pollIntervalMs;try{await this.refreshWorkerLogic(e)}catch(r){this.options.logger.autoPollConfigServiceErrorDuringPolling(r)}const s=i-Ct();s>0&&await Ot(s,t)}catch(i){this.options.logger.autoPollConfigServiceErrorDuringPolling(i)}e=null}}stopRefreshWorker(){this.options.logger.debug("AutoPollConfigService.stopRefreshWorker() called."),this.stopToken.abort()}async refreshWorkerLogic(e){this.options.logger.debug("AutoPollConfigService.refreshWorkerLogic() called.");const t=await(e??this.syncUpWithCache());if(t.isExpired(this.pollExpirationMs)&&(e?!this.isOfflineExactly:!this.isOffline)){await this.refreshConfigCoreAsync(t,!1);return}this.signalInitialization()}getCacheState(e){return e.isEmpty?0:e.isExpired(this.pollIntervalMs)?2:3}}class be{on(){return this}once(){return this}removeListener(){return this}removeAllListeners(){return this}listeners(){return[]}listenerCount(){return 0}eventNames(){return[]}emit(){return!1}}const Ie=be.prototype;Ie.addListener=Ie.on,Ie.off=Ie.removeListener,h.OverrideBehaviour=void 0,(function(n){n[n.LocalOnly=0]="LocalOnly",n[n.LocalOverRemote=1]="LocalOverRemote",n[n.RemoteOverLocal=2]="RemoteOverLocal"})(h.OverrideBehaviour||(h.OverrideBehaviour={}));function we(n){return h.OverrideBehaviour[n]}class Xn{constructor(e,t){this.initialSettings=Wt(e),this.map=t?e:null}getOverrides(){return this.map?Wt(this.map):this.initialSettings}}function Wt(n){const e={};for(const t in n)D(n,t)&&(e[t]=Xe(n[t]));return e}const Zn="cc-",Re=";str";class ei{get currentValue(){if(!(typeof location>"u"||location===null))return location.search}}let Ne;class ti{constructor(e,t,i){this.watchChanges=!!e,this.paramPrefix=t??Zn,i??(i=Ne??(Ne=new ei)),this.queryStringProvider=i;const s=i.currentValue;this.settings=Jt(s,this.paramPrefix),this.queryString=zt(s)}getOverrides(){if(this.watchChanges){const e=this.queryStringProvider.currentValue,t=zt(e);this.queryString!==t&&(this.settings=Jt(e,this.paramPrefix),this.queryString=t)}return this.settings}}function zt(n){if(n==null)return"";if(S(n))return n;let e="",t="?";for(const i in n){if(!D(n,i))continue;const s=n[i];let r,o;if(!M(s))r=s,o=1;else if(s.length)r=s[0],o=s.length;else continue;for(let a=0;e+=t+encodeURIComponent(i)+"="+encodeURIComponent(r),!(++a>=o);)t="&",r=s[a]}return e}function Jt(n,e){const t={};return S(n)?ii(n,e,t):n!=null&&ni(n,e,t),t}function ni(n,e,t){for(const i in n){if(!D(n,i))continue;const s=n[i];let r,o;if(!M(s))r=s,o=1;else if(s.length)r=s[0],o=s.length;else continue;for(let a=0;Gt(i,r,e,t),!(++a>=o);)r=s[a]}}function ii(n,e,t){if(!n||n.lastIndexOf("?",0)<0)return;const i=n.substring(1).split("&");for(let s of i){s=s.replace(/\+/g," ");const r=s.indexOf("="),o=decodeURIComponent(r>=0?s.substring(0,r):s),a=r>=0?decodeURIComponent(s.substring(r+1)):"";Gt(o,a,e,t)}}function Gt(n,e,t,i){if(!n||n.length<=t.length||n.lastIndexOf(t,0)<0)return;n=n.substring(t.length),n.length>Re.length&&n.indexOf(Re,n.length-Re.length)>=0?n=n.substring(0,n.length-Re.length):e=si(e),i[n]=Xe(e)}function si(n){switch(n.toLowerCase()){case"false":return!1;case"true":return!0;default:const e=Je(n);return isNaN(e)?n:e}}function Yt(n){function e(N,j){var He=N<<j|N>>>32-j;return He}var t,i,s,r=new Array(80),o=1732584193,a=4023233417,l=2562383102,c=271733878,f=3285377520,u,g,d,v,A,O;n=oe(n);var y=n.length,T=new Array;for(i=0;i<y-3;i+=4)s=n.charCodeAt(i)<<24|n.charCodeAt(i+1)<<16|n.charCodeAt(i+2)<<8|n.charCodeAt(i+3),T.push(s);switch(y%4){case 0:i=2147483648;break;case 1:i=n.charCodeAt(y-1)<<24|8388608;break;case 2:i=n.charCodeAt(y-2)<<24|n.charCodeAt(y-1)<<16|32768;break;case 3:i=n.charCodeAt(y-3)<<24|n.charCodeAt(y-2)<<16|n.charCodeAt(y-1)<<8|128;break}for(T.push(i);T.length%16!=14;)T.push(0);for(T.push(y>>>29),T.push(y<<3&4294967295),t=0;t<T.length;t+=16){for(i=0;i<16;i++)r[i]=T[t+i];for(i=16;i<=79;i++)r[i]=e(r[i-3]^r[i-8]^r[i-14]^r[i-16],1);for(u=o,g=a,d=l,v=c,A=f,i=0;i<=19;i++)O=e(u,5)+(g&d|~g&v)+A+r[i]+1518500249&4294967295,A=v,v=d,d=e(g,30),g=u,u=O;for(i=20;i<=39;i++)O=e(u,5)+(g^d^v)+A+r[i]+1859775393&4294967295,A=v,v=d,d=e(g,30),g=u,u=O;for(i=40;i<=59;i++)O=e(u,5)+(g&d|g&v|d&v)+A+r[i]+2400959708&4294967295,A=v,v=d,d=e(g,30),g=u,u=O;for(i=60;i<=79;i++)O=e(u,5)+(g^d^v)+A+r[i]+3395469782&4294967295,A=v,v=d,d=e(g,30),g=u,u=O;o=o+u&4294967295,a=a+g&4294967295,l=l+d&4294967295,c=c+v&4294967295,f=f+A&4294967295}return Qt([o,a,l,c,f])}const ri=Object.create(null);function oi(n){function e(An,On){return An>>>On|An<<32-On}const t="length";var i=Math.pow,s=i(2,32),r,o,a=ri,l=a.h,c=a.k;if(!c){l=[],c=[];for(var f=F(),u=2,g=0;g<64;u++)if(!f[u]){for(r=0;r<313;r+=u)f[r]=u;l[g]=i(u,.5)*s|0,c[g++]=i(u,1/3)*s|0}a.h=l=l.slice(0,8),a.k=c}var d=n[t]*8;n+="";for(var v=[];n[t]%64-56;)n+="\0";for(r=0;r<n[t];r++)o=n.charCodeAt(r),v[r>>2]|=o<<(3-r)%4*8;for(v[v[t]]=d/s|0,v[v[t]]=d,o=0;o<v[t];){var A=v.slice(o,o+=16),O=l;for(l=l.slice(0,8),r=0;r<64;r++){var y=A[r-15],T=A[r-2],N=l[0],j=l[4],He=l[7]+(e(j,6)^e(j,11)^e(j,25))+(j&l[5]^~j&l[6])+c[r]+(A[r]=r<16?A[r]:A[r-16]+(e(y,7)^e(y,18)^y>>>3)+A[r-7]+(e(T,17)^e(T,19)^T>>>10)|0),ji=(e(N,2)^e(N,13)^e(N,22))+(N&l[1]^N&l[2]^l[1]&l[2]);l=[He+ji|0].concat(l),l[4]=l[4]+He|0}for(r=0;r<8;r++)l[r]=l[r]+O[r]|0}return Qt(l,8)}function Qt(n,e){const t="0123456789abcdef";var i="";e??(e=n.length);for(let s=0;s<e;s++)for(let r=3;r>=0;r--){const o=n[s]>>(r<<3)&255;i+=t[o>>4],i+=t[o&15]}return i}const Xt=new be;class ct{constructor(e){this.eventEmitter=e;const t=Object.create(null);t.get=()=>this.configCatClient,t.enumerable=!0,Object.defineProperty(e,"configCatClient",t)}tryDisconnect(){const e=this.eventEmitter;return this.eventEmitter=Xt,e!==Xt}on(e,t){return this.eventEmitter.on(e,t),this}once(e,t){return this.eventEmitter.once(e,t),this}removeListener(e,t){return this.eventEmitter.removeListener(e,t),this}removeAllListeners(e){return this.eventEmitter.removeAllListeners(e),this}listeners(e){return this.eventEmitter.listeners(e)}listenerCount(e){return this.eventEmitter.listenerCount(e)}eventNames(){return this.eventEmitter.eventNames()}emit(e,...t){return this.eventEmitter.emit(e,...t)}}const Fe=ct.prototype;Fe.addListener=Fe.on,Fe.off=Fe.removeListener;class ai extends lt{constructor(e){super(e),this.cacheTimeToLiveMs=e.cacheTimeToLiveSeconds*1e3,this.prepareClientForEvents();const t=this.syncUpWithCache();this.readyPromise=this.getReadyPromise(t)}async getConfigAsync(){this.options.logger.debug("LazyLoadConfigService.getConfigAsync() called.");function e(i,s=""){i.debug(`LazyLoadConfigService.getConfigAsync(): cache is empty or expired${s}.`)}let t=await this.syncUpWithCache();return t.isExpired(this.cacheTimeToLiveMs)?(this.isOffline?e(this.options.logger):(e(this.options.logger,", calling refreshConfigCoreAsync()"),[,t]=await this.refreshConfigCoreAsync(t,!1)),t):(this.options.logger.debug("LazyLoadConfigService.getConfigAsync(): cache is valid, returning from cache."),t)}refreshConfigAsync(){return this.options.logger.debug("LazyLoadConfigService.refreshConfigAsync() called."),super.refreshConfigAsync()}getCacheState(e){return e.isEmpty?0:e.isExpired(this.cacheTimeToLiveMs)?2:3}}class li extends lt{constructor(e){super(e),this.prepareClientForEvents();const t=this.syncUpWithCache();this.readyPromise=this.getReadyPromise(t)}getCacheState(e){return e.isEmpty?0:2}async getConfigAsync(){return this.options.logger.debug("ManualPollService.getConfigAsync() called."),await this.syncUpWithCache()}refreshConfigAsync(){return this.options.logger.debug("ManualPollService.refreshConfigAsync() called."),super.refreshConfigAsync()}}const ut="configcat-proxy/";h.PollingMode=void 0,(function(n){n[n.AutoPoll=0]="AutoPoll",n[n.LazyLoad=1]="LazyLoad",n[n.ManualPoll=2]="ManualPoll"})(h.PollingMode||(h.PollingMode={})),h.DataGovernance=void 0,(function(n){n[n.Global=0]="Global",n[n.EuOnly=1]="EuOnly"})(h.DataGovernance||(h.DataGovernance={}));function ci(n){return h.DataGovernance[n]}class X{constructor(e,t,i,s){var r,o,a,l;this.requestTimeoutMs=3e4,this.dataGovernance=0,this.flagOverrides=null,this.defaultUser=void 0,this.offline=!1,this.sdkKey=e,this.clientVersion=i;const c=(o=(r=t.eventEmitterFactory)===null||r===void 0?void 0:r.call(t))!==null&&o!==void 0?o:new be,f=new ct(c);this.hooks={hooks:f,unwrap(){return this.hooks},emit(O,...y){var T,N;return(N=(T=this.unwrap())===null||T===void 0?void 0:T.emit(O,...y))!==null&&N!==void 0?N:!1}};let u,g,d,v,A;if(s){const O="options";if(s.logFilter!=null&&(u=Ft(s.logFilter,O,".logFilter")),s.logger!=null){const y=F();y.log=!0,g=_(s.logger,O,y,".logger")}if(s.cache!=null){const y=F();y.get=y.set=!0,d=_(s.cache,O,y,".cache")}if(s.configFetcher!=null){const y=F();y.fetchAsync=!0,v=_(s.configFetcher,O,y,".configFetcher")}if(s.requestTimeoutMs!=null&&(this.requestTimeoutMs=Ae(s.requestTimeoutMs,O,"greater than 0",y=>y>0,".requestTimeoutMs")),s.dataGovernance!=null&&(this.dataGovernance=ee(s.dataGovernance,O,"DataGovernance",y=>ci(y)!==void 0,".dataGovernance")),s.baseUrl!=null&&(A=Y(s.baseUrl,O,!0,".baseUrl")),s.flagOverrides!=null){const y=F();y.behaviour=y.dataSource=!1;const T=_(s.flagOverrides,O,y,".flagOverrides");ee(T.behaviour,O,"OverrideBehaviour",j=>we(j)!==void 0,".flagOverrides.behaviour");const N=F();N.getOverrides=!0,_(T.dataSource,O,N,".flagOverrides.dataSource"),this.flagOverrides=T}s.defaultUser!=null&&(this.defaultUser=_(s.defaultUser,O,void 0,".defaultUser")),s.offline!=null&&(this.offline=We(s.offline,O,".offline")),s.setupHooks!=null&&Ft(s.setupHooks,O,".setupHooks")(f)}(this.baseUrlOverriden=A!=null)?this.baseUrl=A:this.baseUrl=this.dataGovernance===1?"https://cdn-eu.configcat.com":"https://cdn-global.configcat.com",this.logger=new zn(g??new qt,u,this.hooks),this.cache=d?new Ce(d,this.logger):(l=(a=t.defaultCacheFactory)===null||a===void 0?void 0:a.call(t,this))!==null&&l!==void 0?l:new Pt,this.configFetcher=v??t.configFetcherFactory(this)}yieldHooks(){var e;const t=this.hooks,i=(e=t.unwrap())!==null&&e!==void 0?e:new ct(new be);return t.hooks=Tt(i),t.unwrap=function(){return this.hooks.deref()},i}getUrl(){const{baseUrl:e}=this;return e+(e.charCodeAt(e.length-1)!==47?"/":"")+"configuration-files/"+this.sdkKey+"/"+X.configFileName+"?sdk="+this.clientVersion}getCacheKey(){return Yt(`${this.sdkKey}_${X.configFileName}_${b.serializationFormatVersion}`)}}X.configFileName="config_v6.json";const Zt="/"+ut,ui=/^https?:\/\/(?:[a-z0-9-]+\.)+configcat\.com\.?(?:[:/]|$)/i;function en(n){if(!ui.test(n))return!1;let e=n.indexOf("?");return e=n.lastIndexOf(Zt,(e>=0?e:n.length)-Zt.length),e<0}class fi extends X{constructor(e,t,i){if(super(e,t,t.sdkType+"/a-"+t.sdkVersion,i),this.pollIntervalSeconds=60,this.maxInitWaitTimeSeconds=5,i){const s="options";i.pollIntervalSeconds!=null&&(this.pollIntervalSeconds=Ae(i.pollIntervalSeconds,s,"between 1 and 2147483",l=>It(l,1,2147483),".pollIntervalSeconds")),i.maxInitWaitTimeSeconds!=null&&(this.maxInitWaitTimeSeconds=Ae(i.maxInitWaitTimeSeconds,s,"less than or equal to 2147483",a=>a<=2147483,".maxInitWaitTimeSeconds"))}}createConfigService(){return new Qn(this)}}class hi extends X{constructor(e,t,i){super(e,t,t.sdkType+"/m-"+t.sdkVersion,i)}createConfigService(){return new li(this)}}class gi extends X{constructor(e,t,i){if(super(e,t,t.sdkType+"/l-"+t.sdkVersion,i),this.cacheTimeToLiveSeconds=60,i){const s="options";i.cacheTimeToLiveSeconds!=null&&(this.cacheTimeToLiveSeconds=Ae(i.cacheTimeToLiveSeconds,s,"between 1 and 2147483647",a=>It(a,1,2147483647),".cacheTimeToLiveSeconds")),i.cacheTimeToLiveSeconds!=null&&(this.cacheTimeToLiveSeconds=i.cacheTimeToLiveSeconds)}}createConfigService(){return new ai(this)}}const tn="<invalid value>",di="<invalid name>",ft="<invalid operator>",nn="<invalid reference>",vi=10;class sn{constructor(e){this.eol=e,this.log="",this.indent=""}resetIndent(){return this.indent="",this}increaseIndent(){return this.indent+=" ",this}decreaseIndent(){return this.indent=this.indent.slice(0,-2),this}newLine(e){return this.log+=this.eol+this.indent+(e??""),this}append(e){return this.log+=e,this}toString(){return this.log}appendUserConditionCore(e,t,i){return this.append(`User.${e} ${ht(t)} '${i??tn}'`)}appendUserConditionString(e,t,i,s){return i==null?this.appendUserConditionCore(e,t):this.appendUserConditionCore(e,t,s?"<hashed value>":i)}appendUserConditionStringList(e,t,i,s){if(i==null)return this.appendUserConditionCore(e,t);const r="value",o="values",a=ht(t);if(s)return this.append(`User.${e} ${a} [<${i.length} hashed ${i.length===1?r:o}>]`);{const l=ze(i,vi,c=>`, ... <${c} more ${c===1?r:o}>`);return this.append(`User.${e} ${a} [${l}]`)}}appendUserConditionNumber(e,t,i,s){if(i==null)return this.appendUserConditionCore(e,t);const r=ht(t);let o;return s&&!isNaN(o=new Date(i*1e3))?this.append(`User.${e} ${r} '${i}' (${o.toISOString()} UTC)`):this.append(`User.${e} ${r} '${i}'`)}appendUserCondition(e){const t=e.a,i=e.c;switch(i){case 0:case 1:case 2:case 3:case 4:case 5:case 30:case 31:case 32:case 33:case 34:case 35:return this.appendUserConditionStringList(t,i,e.l,!1);case 6:case 7:case 8:case 9:case 28:case 29:return this.appendUserConditionString(t,i,e.s,!1);case 10:case 11:case 12:case 13:case 14:case 15:return this.appendUserConditionNumber(t,i,e.d);case 16:case 17:case 22:case 23:case 24:case 25:case 26:case 27:return this.appendUserConditionStringList(t,i,e.l,!0);case 18:case 19:return this.appendUserConditionNumber(t,i,e.d,!0);case 20:case 21:return this.appendUserConditionString(t,i,e.s,!0);default:{const s=yi(e);return S(s)?this.appendUserConditionString(t,i,s,!1):W(s)?this.appendUserConditionNumber(t,i,s):s?this.appendUserConditionCore(t,i):this.appendUserConditionStringList(t,i,s,!1)}}}appendPrerequisiteFlagCondition(e,t){const i=D(t,e.f)?e.f:nn,s=e.c,r=on(e.v);return this.append(`Flag '${i}' ${pi(s)} '${ue(r)}'`)}appendSegmentCondition(e,t){const i=e.s;let s;t&&Ke(i,0,t.length-1)?(s=t[i].n,s.length||(s=di)):s=nn;const r=e.c;return this.append(`User ${rn(r)} '${s}'`)}appendConditionResult(e){return this.append(`${e}`)}appendConditionConsequence(e){return this.append(" => ").appendConditionResult(e),e?this:this.append(", skipping the remaining AND conditions")}appendTargetingRuleThenPart(e,t,i){if((i?this.newLine():this.append(" ")).append("THEN"),!rt(e,!0)){const s=e.s,r=q(s.v,t,!0);return this.append(` '${ue(r)}'`)}return this.append(" % options")}appendTargetingRuleConsequence(e,t,i,s){return this.increaseIndent(),this.appendTargetingRuleThenPart(e,t,s).append(" => ").append(i===!0?"MATCH, applying rule":i===!1?"no match":i),this.decreaseIndent()}}function ht(n){switch(n){case 0:case 16:case 4:return"IS ONE OF";case 1:case 17:case 5:return"IS NOT ONE OF";case 2:return"CONTAINS ANY OF";case 3:return"NOT CONTAINS ANY OF";case 6:case 12:return"<";case 7:case 13:return"<=";case 8:case 14:return">";case 9:case 15:return">=";case 10:return"=";case 11:return"!=";case 18:return"BEFORE";case 19:return"AFTER";case 28:case 20:return"EQUALS";case 29:case 21:return"NOT EQUALS";case 30:case 22:return"STARTS WITH ANY OF";case 31:case 23:return"NOT STARTS WITH ANY OF";case 32:case 24:return"ENDS WITH ANY OF";case 33:case 25:return"NOT ENDS WITH ANY OF";case 34:case 26:return"ARRAY CONTAINS ANY OF";case 35:case 27:return"ARRAY NOT CONTAINS ANY OF";default:return ft}}function gt(n){return new sn("").appendUserCondition(n).toString()}function pi(n){switch(n){case 0:return"EQUALS";case 1:return"NOT EQUALS";default:return ft}}function rn(n){switch(n){case 0:return"IS IN SEGMENT";case 1:return"IS NOT IN SEGMENT";default:return ft}}function ue(n){return st(n)?n.toString():tn}function on(n){let e,t;if(e=n.b,t=n.s,t!=null){if(e!=null)return;e=t}if(t=n.i,t!=null){if(e!=null)return;e=t}if(t=n.d,t!=null){if(e!=null)return;e=t}return e??void 0}function yi(n){let e,t;if(e=n.s,t=n.d,t!=null){if(e!=null)return;e=t}if(t=n.l,t!=null){if(e!=null)return;e=t}return e??void 0}const an=/^[0-9]+$/,fe=(n,e)=>{const t=an.test(n),i=an.test(e);return t&&i&&(n=+n,e=+e),n===e?0:t&&!i?-1:i&&!t?1:n<e?-1:1},dt=256,Le=Number.MAX_SAFE_INTEGER||9007199254740991,he=[],C=[],E={};let mi=0;const w=(n,e)=>{const t=mi++;E[n]=t,C[t]=e,he[t]=new RegExp(e)};w("NUMERICIDENTIFIER","0|[1-9]\\d*"),w("NUMERICIDENTIFIERLOOSE","[0-9]+"),w("NONNUMERICIDENTIFIER","\\d*[a-zA-Z-][a-zA-Z0-9-]*"),w("MAINVERSION",`(${C[E.NUMERICIDENTIFIER]})\\.(${C[E.NUMERICIDENTIFIER]})\\.(