UNPKG

@featurevisor/sdk

Version:

Featurevisor SDK for Node.js and the browser

2 lines 22.4 kB
var e={784:e=>{!function(){const t=e=>(new TextEncoder).encode(e);function r(e,r){let a,i,n,s,o,u,l,c;for("string"==typeof e&&(e=t(e)),a=3&e.length,i=e.length-a,n=r,o=3432918353,u=461845907,c=0;c<i;)l=255&e[c]|(255&e[++c])<<8|(255&e[++c])<<16|(255&e[++c])<<24,++c,l=(65535&l)*o+(((l>>>16)*o&65535)<<16)&4294967295,l=l<<15|l>>>17,l=(65535&l)*u+(((l>>>16)*u&65535)<<16)&4294967295,n^=l,n=n<<13|n>>>19,s=5*(65535&n)+((5*(n>>>16)&65535)<<16)&4294967295,n=27492+(65535&s)+((58964+(s>>>16)&65535)<<16);switch(l=0,a){case 3:l^=(255&e[c+2])<<16;case 2:l^=(255&e[c+1])<<8;case 1:l^=255&e[c],l=(65535&l)*o+(((l>>>16)*o&65535)<<16)&4294967295,l=l<<15|l>>>17,l=(65535&l)*u+(((l>>>16)*u&65535)<<16)&4294967295,n^=l}return n^=e.length,n^=n>>>16,n=2246822507*(65535&n)+((2246822507*(n>>>16)&65535)<<16)&4294967295,n^=n>>>13,n=3266489909*(65535&n)+((3266489909*(n>>>16)&65535)<<16)&4294967295,n^=n>>>16,n>>>0}const a=r;a.v2=function(e,r){"string"==typeof e&&(e=t(e));let a,i=e.length,n=r^i,s=0;for(;i>=4;)a=255&e[s]|(255&e[++s])<<8|(255&e[++s])<<16|(255&e[++s])<<24,a=1540483477*(65535&a)+((1540483477*(a>>>16)&65535)<<16),a^=a>>>24,a=1540483477*(65535&a)+((1540483477*(a>>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^a,i-=4,++s;switch(i){case 3:n^=(255&e[s+2])<<16;case 2:n^=(255&e[s+1])<<8;case 1:n^=255&e[s],n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)}return n^=n>>>13,n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16),n^=n>>>15,n>>>0},a.v3=r,e.exports=a}()}},t={};function r(a){var i=t[a];if(void 0!==i)return i.exports;var n=t[a]={exports:{}};return e[a](n,n.exports,r),n.exports}r.d=(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var a={};r.d(a,{vl:()=>b,f6:()=>S,Jr:()=>T,Vy:()=>y,lb:()=>o,i4:()=>R,mx:()=>I,Q_:()=>w,h:()=>g,K_:()=>h,DU:()=>d,_3:()=>F,bT:()=>c,eG:()=>l,dg:()=>u,Zy:()=>D,xE:()=>f});var i=r(784);const n=1,s=Math.pow(2,32),o=1e5;function u(e){const t=i.v3(e,n)/s;return Math.floor(t*o)}function l(e){const{feature:t,context:r,logger:a,bucketKeySeparator:i=".",configureBucketKey:n}=e,s=t.key;let o,u;if("string"==typeof t.bucketBy)o="plain",u=[t.bucketBy];else if(Array.isArray(t.bucketBy))o="and",u=t.bucketBy;else{if("object"!=typeof t.bucketBy||!Array.isArray(t.bucketBy.or))throw a.error("invalid bucketBy",{featureKey:s,bucketBy:t.bucketBy}),new Error("invalid bucketBy");o="or",u=t.bucketBy.or}const l=[];u.forEach((e=>{const t=r[e];void 0!==t&&("plain"===o||"and"===o||0===l.length)&&l.push(t)})),l.push(s);const c=l.join(i);return n?n(t,r,c):c}function c(e){const{feature:t,context:r,logger:a,bucketKeySeparator:i,configureBucketKey:n,configureBucketValue:s}=e,o=l({feature:t,context:r,logger:a,bucketKeySeparator:i,configureBucketKey:n}),c=u(o);return s?{bucketKey:o,bucketValue:s(t,r,c)}:{bucketKey:o,bucketValue:c}}const f="[Featurevisor]",d=["warn","error"],h=function(e,t,r={}){switch(e){case"debug":console.log(f,t,r);break;case"info":console.info(f,t,r);break;case"warn":console.warn(f,t,r);break;case"error":console.error(f,t,r)}};class y{constructor(e){this.levels=e.levels,this.handle=e.handler}setLevels(e){this.levels=e}log(e,t,r){-1!==this.levels.indexOf(e)&&this.handle(e,t,r)}debug(e,t){this.log("debug",e,t)}info(e,t){this.log("info",e,t)}warn(e,t){this.log("warn",e,t)}error(e,t){this.log("error",e,t)}}function g(e={}){const t=e.levels||d,r=e.handler||h;return new y({levels:t,handler:r})}class v{constructor(e){if(this.schemaVersion=e.schemaVersion,this.revision=e.revision,"2"===this.schemaVersion){const t=e;this.attributes=t.attributes,this.segments=t.segments,this.features=t.features}else{const t=e;this.attributes={},t.attributes.forEach((e=>{this.attributes[e.key]=e})),this.segments={},t.segments.forEach((e=>{this.segments[e.key]=e})),this.features={},t.features.forEach((e=>{Array.isArray(e.variablesSchema)&&(e.variablesSchema=e.variablesSchema.reduce(((e,t)=>(e[t.key]=t,e)),{})),this.features[e.key]=e}))}}getRevision(){return this.revision}getSchemaVersion(){return this.schemaVersion}getAllAttributes(){const e=[];return Object.keys(this.attributes).forEach((t=>{e.push(this.attributes[t])})),e}getAttribute(e){return this.attributes[e]}getSegment(e){const t=this.segments[e];if(t)return function(e,t){if("string"==typeof e[t]&&"*"!==e[t])try{e[t]=JSON.parse(e[t])}catch(e){console.error("Error parsing JSON",e)}return e}(t,"conditions")}getFeature(e){return this.features[e]}}class b{constructor(){this._listeners={}}addListener(e,t){void 0===this._listeners[e]&&(this._listeners[e]=[]),this._listeners[e].push(t)}removeListener(e,t){if(void 0===this._listeners[e])return;const r=this._listeners[e].indexOf(t);-1!==r&&this._listeners[e].splice(r,1)}removeAllListeners(e){e?this._listeners[e]=[]:Object.keys(this._listeners).forEach((e=>{this._listeners[e]=[]}))}emit(e,...t){void 0!==this._listeners[e]&&this._listeners[e].forEach((e=>{e(...t)}))}}const k=(e,t)=>{const r=K(e),a=K(t),i=r.pop(),n=a.pop(),s=E(r,a);return 0!==s?s:i&&n?E(i.split("."),n.split(".")):i||n?i?-1:1:0},p=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,K=e=>{if("string"!=typeof e)throw new TypeError("Invalid argument expected string");const t=e.match(p);if(!t)throw new Error(`Invalid argument not valid semver ('${e}' received)`);return t.shift(),t},m=e=>"*"===e||"x"===e||"X"===e,V=e=>{const t=parseInt(e,10);return isNaN(t)?e:t},A=(e,t)=>{if(m(e)||m(t))return 0;const[r,a]=((e,t)=>typeof e!=typeof t?[String(e),String(t)]:[e,t])(V(e),V(t));return r>a?1:r<a?-1:0},E=(e,t)=>{for(let r=0;r<Math.max(e.length,t.length);r++){const a=A(e[r]||"0",t[r]||"0");if(0!==a)return a}return 0};function I(e,t){const{attribute:r,operator:a,value:i}=e;if("equals"===a)return t[r]===i;if("notEquals"===a)return t[r]!==i;if("before"===a||"after"===a){const e=t[r],n=e instanceof Date?e:new Date(e),s=i instanceof Date?i:new Date(i);return"before"===a?n<s:n>s}if(!Array.isArray(i)||-1===["string","number"].indexOf(typeof t[r])&&null!==t[r]){if("string"==typeof t[r]&&"string"==typeof i){const e=t[r];if("contains"===a)return-1!==e.indexOf(i);if("notContains"===a)return-1===e.indexOf(i);if("startsWith"===a)return e.startsWith(i);if("endsWith"===a)return e.endsWith(i);if("semverEquals"===a)return 0===k(e,i);if("semverNotEquals"===a)return 0!==k(e,i);if("semverGreaterThan"===a)return 1===k(e,i);if("semverGreaterThanOrEquals"===a)return k(e,i)>=0;if("semverLessThan"===a)return-1===k(e,i);if("semverLessThanOrEquals"===a)return k(e,i)<=0}else if("number"==typeof t[r]&&"number"==typeof i){const e=t[r];if("greaterThan"===a)return e>i;if("greaterThanOrEquals"===a)return e>=i;if("lessThan"===a)return e<i;if("lessThanOrEquals"===a)return e<=i}}else{const e=t[r];if("in"===a)return-1!==i.indexOf(e);if("notIn"===a)return-1===i.indexOf(e)}return!1}function R(e,t,r){if("attribute"in e)try{return I(e,t)}catch(a){return r.warn(a.message,{error:a,details:{condition:e,context:t}}),!1}return"and"in e&&Array.isArray(e.and)?e.and.every((e=>R(e,t,r))):"or"in e&&Array.isArray(e.or)?e.or.some((e=>R(e,t,r))):"not"in e&&Array.isArray(e.not)?e.not.every((()=>!1===R({and:e.not},t,r))):!!Array.isArray(e)&&e.every((e=>R(e,t,r)))}function x(e,t,r,a){if("*"===e)return!0;if("string"==typeof e){const i=r.getSegment(e);return!!i&&function(e,t,r){return R(e.conditions,t,r)}(i,t,a)}if("object"==typeof e){if("and"in e&&Array.isArray(e.and))return e.and.every((e=>x(e,t,r,a)));if("or"in e&&Array.isArray(e.or))return e.or.some((e=>x(e,t,r,a)));if("not"in e&&Array.isArray(e.not))return e.not.every((e=>!1===x(e,t,r,a)))}return!!Array.isArray(e)&&e.every((e=>x(e,t,r,a)))}function O(e){return"string"==typeof e&&(e.startsWith("{")||e.startsWith("["))?JSON.parse(e):e}var S;function F(e){let t;const{type:r,featureKey:a,variableKey:i,context:n,logger:s,datafileReader:o,statuses:u,stickyFeatures:l,initialFeatures:f,interceptContext:d,bucketKeySeparator:h,configureBucketKey:y,configureBucketValue:g}=e;try{const e="string"==typeof a?a:a.key;let v;if("flag"!==r&&(v=F({type:"flag",featureKey:e,context:n,logger:s,datafileReader:o,statuses:u,stickyFeatures:l,initialFeatures:f,bucketKeySeparator:h,configureBucketKey:y,configureBucketValue:g}),!1===v.enabled))return t={featureKey:e,reason:S.DISABLED},s.debug("feature is disabled",t),t;if(l&&l[e]){if("flag"===r&&void 0!==l[e].enabled)return t={featureKey:e,reason:S.STICKY,sticky:l[e],enabled:l[e].enabled},s.debug("using sticky enabled",t),t;if("variation"===r){const r=l[e].variation;if(void 0!==r)return t={featureKey:e,reason:S.STICKY,variationValue:r},s.debug("using sticky variation",t),t}if(i){const r=l[e].variables;if(r){const a=r[i];if(void 0!==a)return t={featureKey:e,reason:S.STICKY,variableKey:i,variableValue:a},s.debug("using sticky variable",t),t}}}if(u&&!u.ready&&f&&f[e]){if("flag"===r&&void 0!==f[e].enabled)return t={featureKey:e,reason:S.INITIAL,initial:f[e],enabled:f[e].enabled},s.debug("using initial enabled",t),t;if("variation"===r&&void 0!==f[e].variation){const r=f[e].variation;return t={featureKey:e,reason:S.INITIAL,variationValue:r},s.debug("using initial variation",t),t}if(i){const r=f[e].variables;if(r&&void 0!==r[i])return t={featureKey:e,reason:S.INITIAL,variableKey:i,variableValue:r[i]},s.debug("using initial variable",t),t}}const b="string"==typeof a?o.getFeature(a):a;if(!b)return t={featureKey:e,reason:S.NOT_FOUND},s.warn("feature not found",t),t;let k;if("flag"===r&&b.deprecated&&s.warn("feature is deprecated",{featureKey:b.key}),i){if(b.variablesSchema&&b.variablesSchema[i]&&(k=b.variablesSchema[i]),!k)return t={featureKey:e,reason:S.NOT_FOUND,variableKey:i},s.warn("variable schema not found",t),t;k.deprecated&&s.warn("variable is deprecated",{featureKey:b.key,variableKey:i})}if("variation"===r&&(!b.variations||0===b.variations.length))return t={featureKey:e,reason:S.NO_VARIATIONS},s.warn("no variations",t),t;const p=d?d(n):n,{force:K,forceIndex:m}=function(e,t,r,a){const i={force:void 0,forceIndex:void 0};if(!e.force)return i;for(let n=0;n<e.force.length;n++){const s=e.force[n];if(s.conditions&&R(s.conditions,t,a)){i.force=s,i.forceIndex=n;break}if(s.segments&&x(s.segments,t,r,a)){i.force=s,i.forceIndex=n;break}}return i}(b,n,o,s);if(K){if("flag"===r&&void 0!==K.enabled)return t={featureKey:b.key,reason:S.FORCED,forceIndex:m,force:K,enabled:K.enabled},s.debug("forced enabled found",t),t;if("variation"===r&&K.variation&&b.variations){const e=b.variations.find((e=>e.value===K.variation));if(e)return t={featureKey:b.key,reason:S.FORCED,forceIndex:m,force:K,variation:e},s.debug("forced variation found",t),t}if(i&&K.variables&&void 0!==K.variables[i])return t={featureKey:b.key,reason:S.FORCED,forceIndex:m,force:K,variableKey:i,variableSchema:k,variableValue:K.variables[i]},s.debug("forced variable",t),t}if("flag"===r&&b.required&&b.required.length>0){const e=b.required.every((e=>{let t,r;if("string"==typeof e?t=e:(t=e.key,r=e.variation),!F({type:"flag",featureKey:t,context:p,logger:s,datafileReader:o,statuses:u,stickyFeatures:l,initialFeatures:f,bucketKeySeparator:h,configureBucketKey:y,configureBucketValue:g}).enabled)return!1;if(void 0!==r){const e=F({type:"variation",featureKey:t,context:p,logger:s,datafileReader:o,statuses:u,stickyFeatures:l,initialFeatures:f,bucketKeySeparator:h,configureBucketKey:y,configureBucketValue:g});let a;return e.variationValue?a=e.variationValue:e.variation&&(a=e.variation.value),a===r}return!0}));if(!e)return t={featureKey:b.key,reason:S.REQUIRED,required:b.required,enabled:e},s.debug("required features not enabled",t),t}const{bucketKey:V,bucketValue:A}=c({feature:b,context:p,logger:s,bucketKeySeparator:h,configureBucketKey:y,configureBucketValue:g});let E,I;if("flag"!==r){const e=function(e,t,r,a,i){const n=e.find((e=>x(O(e.segments),t,a,i)));if(!n)return{matchedTraffic:void 0,matchedAllocation:void 0};const s=function(e,t){if(e.allocation)for(const r of e.allocation){const[e,a]=r.range;if(r.range&&e<=t&&a>=t)return r}}(n,r);return{matchedTraffic:n,matchedAllocation:s}}(b.traffic,p,A,o,s);E=e.matchedTraffic,I=e.matchedAllocation}else E=function(e,t,r,a){const i=e.find((e=>!!x(O(e.segments),t,r,a)));if(i&&i.percentage>0)return i}(b.traffic,p,o,s);if(E){if("flag"===r){if(b.ranges&&b.ranges.length>0)return b.ranges.find((e=>A>=e[0]&&A<e[1]))?(t={featureKey:b.key,reason:S.ALLOCATED,bucketKey:V,bucketValue:A,ruleKey:E.key,traffic:E,enabled:void 0===E.enabled||E.enabled},s.debug("matched",t),t):(t={featureKey:b.key,reason:S.OUT_OF_RANGE,bucketKey:V,bucketValue:A,enabled:!1},s.debug("not matched",t),t);if(void 0!==E.enabled)return t={featureKey:b.key,reason:S.OVERRIDE,bucketKey:V,bucketValue:A,ruleKey:E.key,traffic:E,enabled:E.enabled},s.debug("override from rule",t),t;if(A<=E.percentage)return t={featureKey:b.key,reason:S.RULE,bucketKey:V,bucketValue:A,ruleKey:E.key,traffic:E,enabled:!0},s.debug("matched traffic",t),t}if("variation"===r&&b.variations){if(E.variation){const e=b.variations.find((e=>e.value===E.variation));if(e)return t={featureKey:b.key,reason:S.RULE,bucketKey:V,bucketValue:A,ruleKey:E.key,traffic:E,variation:e},s.debug("override from rule",t),t}if(I&&I.variation){const e=b.variations.find((e=>e.value===I.variation));if(e)return t={featureKey:b.key,reason:S.ALLOCATED,bucketKey:V,bucketValue:A,ruleKey:E.key,traffic:E,variation:e},s.debug("allocated variation",t),t}}}if("variable"===r&&i){if(E&&E.variables&&void 0!==E.variables[i])return t={featureKey:b.key,reason:S.RULE,bucketKey:V,bucketValue:A,ruleKey:E.key,traffic:E,variableKey:i,variableSchema:k,variableValue:E.variables[i]},s.debug("override from rule",t),t;let e;if(K&&K.variation?e=K.variation:E&&E.variation?e=E.variation:I&&I.variation&&(e=I.variation),e&&Array.isArray(b.variations)){const r=b.variations.find((t=>t.value===e));if(r&&r.variables){const e=r.variables.find((e=>e.key===i));if(e){if(e.overrides){const r=e.overrides.find((e=>e.conditions?R("string"==typeof e.conditions?JSON.parse(e.conditions):e.conditions,p,s):!!e.segments&&x(O(e.segments),p,o,s)));if(r)return t={featureKey:b.key,reason:S.OVERRIDE,bucketKey:V,bucketValue:A,ruleKey:null==E?void 0:E.key,traffic:E,variableKey:i,variableSchema:k,variableValue:r.value},s.debug("variable override",t),t}if(void 0!==e.value)return t={featureKey:b.key,reason:S.ALLOCATED,bucketKey:V,bucketValue:A,ruleKey:null==E?void 0:E.key,traffic:E,variableKey:i,variableSchema:k,variableValue:e.value},s.debug("allocated variable",t),t}}}}return"variation"===r?(t={featureKey:b.key,reason:S.NO_MATCH,bucketKey:V,bucketValue:A},s.debug("no matched variation",t),t):"variable"===r&&k?(t={featureKey:b.key,reason:S.DEFAULTED,bucketKey:V,bucketValue:A,variableKey:i,variableSchema:k,variableValue:k.defaultValue},s.debug("using default value",t),t):(t={featureKey:b.key,reason:S.NO_MATCH,bucketKey:V,bucketValue:A,enabled:!1},s.debug("nothing matched",t),t)}catch(e){return t={featureKey:"string"==typeof a?a:a.key,reason:S.ERROR,error:e},s.error("error",t),t}}Object.keys({">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]}),function(e){e.NOT_FOUND="not_found",e.NO_VARIATIONS="no_variations",e.NO_MATCH="no_match",e.DISABLED="disabled",e.REQUIRED="required",e.OUT_OF_RANGE="out_of_range",e.FORCED="forced",e.INITIAL="initial",e.STICKY="sticky",e.RULE="rule",e.ALLOCATED="allocated",e.DEFAULTED="defaulted",e.OVERRIDE="override",e.ERROR="error"}(S||(S={}));const B={schemaVersion:"1",revision:"unknown",attributes:[],segments:[],features:[]};function L(e,t){return t?t(e):fetch(e).then((e=>e.json()))}function D(e,t){try{if(void 0===e)return;switch(t){case"string":return"string"==typeof e?e:void 0;case"integer":return parseInt(e,10);case"double":return parseFloat(e);case"boolean":return!0===e;case"array":return Array.isArray(e)?e:void 0;case"object":return"object"==typeof e?e:void 0;default:return e}}catch(e){return}}class T{constructor(e){this.bucketKeySeparator=e.bucketKeySeparator||".",this.configureBucketKey=e.configureBucketKey,this.configureBucketValue=e.configureBucketValue,this.datafileUrl=e.datafileUrl,this.handleDatafileFetch=e.handleDatafileFetch,this.initialFeatures=e.initialFeatures,this.interceptContext=e.interceptContext,this.logger=e.logger||g(),this.refreshInterval=e.refreshInterval,this.stickyFeatures=e.stickyFeatures,this.emitter=new b,this.statuses={ready:!1,refreshInProgress:!1},e.onReady&&this.emitter.addListener("ready",e.onReady),e.onRefresh&&this.emitter.addListener("refresh",e.onRefresh),e.onUpdate&&this.emitter.addListener("update",e.onUpdate),e.onActivation&&this.emitter.addListener("activation",e.onActivation);const t=this.emitter.addListener.bind(this.emitter);this.on=t,this.addListener=t;const r=this.emitter.removeListener.bind(this.emitter);if(this.off=r,this.removeListener=r,this.removeAllListeners=this.emitter.removeAllListeners.bind(this.emitter),e.datafileUrl)this.setDatafile(e.datafile||B),L(e.datafileUrl,e.handleDatafileFetch).then((e=>{this.setDatafile(e),this.statuses.ready=!0,this.emitter.emit("ready"),this.refreshInterval&&this.startRefreshing()})).catch((e=>{this.logger.error("failed to fetch datafile",{error:e})}));else{if(!e.datafile)throw new Error("Featurevisor SDK instance cannot be created without both `datafile` and `datafileUrl` options");this.setDatafile(e.datafile),this.statuses.ready=!0,setTimeout((()=>{this.emitter.emit("ready")}),0)}}setLogLevels(e){this.logger.setLevels(e)}onReady(){return new Promise((e=>{if(this.statuses.ready)return e(this);const t=()=>{this.emitter.removeListener("ready",t),e(this)};this.emitter.addListener("ready",t)}))}setDatafile(e){try{this.datafileReader=new v("string"==typeof e?JSON.parse(e):e)}catch(e){this.logger.error("could not parse datafile",{error:e})}}setStickyFeatures(e){this.stickyFeatures=e}getRevision(){return this.datafileReader.getRevision()}getFeature(e){return"string"==typeof e?this.datafileReader.getFeature(e):e}isReady(){return this.statuses.ready}refresh(){return this.logger.debug("refreshing datafile"),this.statuses.refreshInProgress?this.logger.warn("refresh in progress, skipping"):this.datafileUrl?(this.statuses.refreshInProgress=!0,void L(this.datafileUrl,this.handleDatafileFetch).then((e=>{const t=this.getRevision()!==e.revision;this.setDatafile(e),this.logger.info("refreshed datafile"),this.emitter.emit("refresh"),t&&this.emitter.emit("update"),this.statuses.refreshInProgress=!1})).catch((e=>{this.logger.error("failed to refresh datafile",{error:e}),this.statuses.refreshInProgress=!1}))):this.logger.error("cannot refresh since `datafileUrl` is not provided")}startRefreshing(){return this.datafileUrl?this.intervalId?this.logger.warn("refreshing has already started"):this.refreshInterval?void(this.intervalId=setInterval((()=>{this.refresh()}),1e3*this.refreshInterval)):this.logger.warn("no `refreshInterval` option provided"):this.logger.error("cannot start refreshing since `datafileUrl` is not provided")}stopRefreshing(){if(!this.intervalId)return this.logger.warn("refreshing has not started yet");clearInterval(this.intervalId)}evaluateFlag(e,t={}){return F({type:"flag",featureKey:e,context:t,logger:this.logger,datafileReader:this.datafileReader,statuses:this.statuses,interceptContext:this.interceptContext,stickyFeatures:this.stickyFeatures,initialFeatures:this.initialFeatures,bucketKeySeparator:this.bucketKeySeparator,configureBucketKey:this.configureBucketKey,configureBucketValue:this.configureBucketValue})}isEnabled(e,t={}){try{return!0===this.evaluateFlag(e,t).enabled}catch(t){return this.logger.error("isEnabled",{featureKey:e,error:t}),!1}}evaluateVariation(e,t={}){return F({type:"variation",featureKey:e,context:t,logger:this.logger,datafileReader:this.datafileReader,statuses:this.statuses,interceptContext:this.interceptContext,stickyFeatures:this.stickyFeatures,initialFeatures:this.initialFeatures,bucketKeySeparator:this.bucketKeySeparator,configureBucketKey:this.configureBucketKey,configureBucketValue:this.configureBucketValue})}getVariation(e,t={}){try{const r=this.evaluateVariation(e,t);return void 0!==r.variationValue?r.variationValue:r.variation?r.variation.value:void 0}catch(t){return void this.logger.error("getVariation",{featureKey:e,error:t})}}activate(e,t={}){try{const r=this.evaluateVariation(e,t),a=r.variation?r.variation.value:r.variationValue;if(void 0===a)return;const i=this.interceptContext?this.interceptContext(t):t,n={};return this.datafileReader.getAllAttributes().filter((e=>!0===e.capture)).forEach((e=>{void 0!==i[e.key]&&(n[e.key]=t[e.key])})),this.emitter.emit("activation",e,a,i,n,r),a}catch(t){return void this.logger.error("activate",{featureKey:e,error:t})}}evaluateVariable(e,t,r={}){return F({type:"variable",featureKey:e,variableKey:t,context:r,logger:this.logger,datafileReader:this.datafileReader,statuses:this.statuses,interceptContext:this.interceptContext,stickyFeatures:this.stickyFeatures,initialFeatures:this.initialFeatures,bucketKeySeparator:this.bucketKeySeparator,configureBucketKey:this.configureBucketKey,configureBucketValue:this.configureBucketValue})}getVariable(e,t,r={}){try{const a=this.evaluateVariable(e,t,r);return void 0!==a.variableValue?a.variableSchema&&"json"===a.variableSchema.type&&"string"==typeof a.variableValue?JSON.parse(a.variableValue):a.variableValue:void 0}catch(r){return void this.logger.error("getVariable",{featureKey:e,variableKey:t,error:r})}}getVariableBoolean(e,t,r={}){return D(this.getVariable(e,t,r),"boolean")}getVariableString(e,t,r={}){return D(this.getVariable(e,t,r),"string")}getVariableInteger(e,t,r={}){return D(this.getVariable(e,t,r),"integer")}getVariableDouble(e,t,r={}){return D(this.getVariable(e,t,r),"double")}getVariableArray(e,t,r={}){return D(this.getVariable(e,t,r),"array")}getVariableObject(e,t,r={}){return D(this.getVariable(e,t,r),"object")}getVariableJSON(e,t,r={}){return D(this.getVariable(e,t,r),"json")}}function w(e){return new T(e)}var _=a.vl,N=a.f6,C=a.Jr,U=a.Vy,j=a.lb,q=a.i4,M=a.mx,J=a.Q_,P=a.h,G=a.K_,W=a.DU,z=a._3,H=a.bT,Q=a.eG,Y=a.dg,X=a.Zy,Z=a.xE;export{_ as Emitter,N as EvaluationReason,C as FeaturevisorInstance,U as Logger,j as MAX_BUCKETED_NUMBER,q as allConditionsAreMatched,M as conditionIsMatched,J as createInstance,P as createLogger,G as defaultLogHandler,W as defaultLogLevels,z as evaluate,H as getBucket,Q as getBucketKey,Y as getBucketedNumber,X as getValueByType,Z as loggerPrefix}; //# sourceMappingURL=index.mjs.map