New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@featurevisor/sdk

Package Overview
Dependencies
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@featurevisor/sdk - npm Package Compare versions

Comparing version 1.3.0 to 1.11.1

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [1.11.1](https://github.com/featurevisor/featurevisor/compare/v1.11.0...v1.11.1) (2024-03-14)
### Bug Fixes
* move to next condition if parsing fails ([#279](https://github.com/featurevisor/featurevisor/issues/279)) ([9f198e2](https://github.com/featurevisor/featurevisor/commit/9f198e2303498c2c74fb2a9a2fcfa5c320acf93f))
# [1.3.0](https://github.com/featurevisor/featurevisor/compare/v1.2.4...v1.3.0) (2024-01-23)

@@ -8,0 +19,0 @@

2

dist/index.js

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FeaturevisorSDK=t():e.FeaturevisorSDK=t()}(this,(()=>(()=>{var e={480:(e,t,r)=>{"use strict";r.r(t),r.d(t,{compare:()=>n,compareVersions:()=>i,satisfies:()=>o,validate:()=>a});const i=(e,t)=>{const r=u(e),i=u(t),a=r.pop(),n=i.pop(),o=d(r,i);return 0!==o?o:a&&n?d(a.split("."),n.split(".")):a||n?a?-1:1:0},a=e=>"string"==typeof e&&/^[v\d]/.test(e)&&s.test(e),n=(e,t,r)=>{v(r);const a=i(e,t);return h[r].includes(a)},o=(e,t)=>{if(t.includes("||"))return t.split("||").some((t=>o(e,t)));if(t.includes(" "))return t.trim().replace(/\s{2,}/g," ").split(" ").every((t=>o(e,t)));const r=t.match(/^([<>=~^]+)/),i=r?r[1]:"=";if("^"!==i&&"~"!==i)return n(e,t,i);const[a,s,l,,f]=u(e),[c,h,g,,v]=u(t),y=[a,s,l],p=[c,null!=h?h:"x",null!=g?g:"x"];if(v){if(!f)return!1;if(0!==d(y,p))return!1;if(-1===d(f.split("."),v.split(".")))return!1}const b=p.findIndex((e=>"0"!==e))+1,m="~"===i?2:b>1?b:1;return 0===d(y.slice(0,m),p.slice(0,m))&&-1!==d(y.slice(m),p.slice(m))},s=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,u=e=>{if("string"!=typeof e)throw new TypeError("Invalid argument expected string");const t=e.match(s);if(!t)throw new Error(`Invalid argument not valid semver ('${e}' received)`);return t.shift(),t},l=e=>"*"===e||"x"===e||"X"===e,f=e=>{const t=parseInt(e,10);return isNaN(t)?e:t},c=(e,t)=>{if(l(e)||l(t))return 0;const[r,i]=((e,t)=>typeof e!=typeof t?[String(e),String(t)]:[e,t])(f(e),f(t));return r>i?1:r<i?-1:0},d=(e,t)=>{for(let r=0;r<Math.max(e.length,t.length);r++){const i=c(e[r]||"0",t[r]||"0");if(0!==i)return i}return 0},h={">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]},g=Object.keys(h),v=e=>{if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===g.indexOf(e))throw new Error(`Invalid operator, expected one of ${g.join("|")}`)}},77:e=>{!function(){const t=e=>(new TextEncoder).encode(e);function r(e,r){let i,a,n,o,s,u,l,f;for("string"==typeof e&&(e=t(e)),i=3&e.length,a=e.length-i,n=r,s=3432918353,u=461845907,f=0;f<a;)l=255&e[f]|(255&e[++f])<<8|(255&e[++f])<<16|(255&e[++f])<<24,++f,l=(65535&l)*s+(((l>>>16)*s&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,o=5*(65535&n)+((5*(n>>>16)&65535)<<16)&4294967295,n=27492+(65535&o)+((58964+(o>>>16)&65535)<<16);switch(l=0,i){case 3:l^=(255&e[f+2])<<16;case 2:l^=(255&e[f+1])<<8;case 1:l^=255&e[f],l=(65535&l)*s+(((l>>>16)*s&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 i=r;i.v2=function(e,r){"string"==typeof e&&(e=t(e));let i,a=e.length,n=r^a,o=0;for(;a>=4;)i=255&e[o]|(255&e[++o])<<8|(255&e[++o])<<16|(255&e[++o])<<24,i=1540483477*(65535&i)+((1540483477*(i>>>16)&65535)<<16),i^=i>>>24,i=1540483477*(65535&i)+((1540483477*(i>>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^i,a-=4,++o;switch(a){case 3:n^=(255&e[o+2])<<16;case 2:n^=(255&e[o+1])<<8;case 1:n^=255&e[o],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},i.v3=r,e.exports=i}()},725:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getBucketedNumber=t.MAX_BUCKETED_NUMBER=void 0;var i=r(77),a=Math.pow(2,32);t.MAX_BUCKETED_NUMBER=1e5,t.getBucketedNumber=function(e){var r=i.v3(e,1)/a;return Math.floor(r*t.MAX_BUCKETED_NUMBER)}},243:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.allConditionsAreMatched=t.conditionIsMatched=void 0;var i=r(480);function a(e,t){var r=e.attribute,a=e.operator,n=e.value;if("equals"===a)return t[r]===n;if("notEquals"===a)return t[r]!==n;if("before"===a||"after"===a){var o=(u=t[r])instanceof Date?u:new Date(u),s=n instanceof Date?n:new Date(n);return"before"===a?o<s:o>s}if("string"==typeof t[r]&&Array.isArray(n)){var u=t[r];if("in"===a)return-1!==n.indexOf(u);if("notIn"===a)return-1===n.indexOf(u)}else if("string"==typeof t[r]&&"string"==typeof n){if(u=t[r],"contains"===a)return-1!==u.indexOf(n);if("notContains"===a)return-1===u.indexOf(n);if("startsWith"===a)return u.startsWith(n);if("endsWith"===a)return u.endsWith(n);if("semverEquals"===a)return 0===(0,i.compareVersions)(u,n);if("semverNotEquals"===a)return 0!==(0,i.compareVersions)(u,n);if("semverGreaterThan"===a)return 1===(0,i.compareVersions)(u,n);if("semverGreaterThanOrEquals"===a)return(0,i.compareVersions)(u,n)>=0;if("semverLessThan"===a)return-1===(0,i.compareVersions)(u,n);if("semverLessThanOrEquals"===a)return(0,i.compareVersions)(u,n)<=0}else if("number"==typeof t[r]&&"number"==typeof n){if(u=t[r],"greaterThan"===a)return u>n;if("greaterThanOrEquals"===a)return u>=n;if("lessThan"===a)return u<n;if("lessThanOrEquals"===a)return u<=n}return!1}t.conditionIsMatched=a,t.allConditionsAreMatched=function e(t,r){return"attribute"in t?a(t,r):"and"in t&&Array.isArray(t.and)?t.and.every((function(t){return e(t,r)})):"or"in t&&Array.isArray(t.or)?t.or.some((function(t){return e(t,r)})):"not"in t&&Array.isArray(t.not)?t.not.every((function(){return!1===e({and:t.not},r)})):!!Array.isArray(t)&&t.every((function(t){return e(t,r)}))}},913:(e,t)=>{"use strict";function r(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}Object.defineProperty(t,"__esModule",{value:!0}),t.DatafileReader=t.parseJsonConditionsIfStringified=void 0,t.parseJsonConditionsIfStringified=r;var i=function(){function e(e){this.schemaVersion=e.schemaVersion,this.revision=e.revision,this.segments=e.segments,this.attributes=e.attributes,this.features=e.features}return e.prototype.getRevision=function(){return this.revision},e.prototype.getSchemaVersion=function(){return this.schemaVersion},e.prototype.getAllAttributes=function(){return this.attributes},e.prototype.getAttribute=function(e){return this.attributes.find((function(t){return t.key===e}))},e.prototype.getSegment=function(e){var t=this.segments.find((function(t){return t.key===e}));if(t)return r(t,"conditions")},e.prototype.getFeature=function(e){var t=this.features.find((function(t){return t.key===e}));if(t)return t},e}();t.DatafileReader=i},186:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Emitter=void 0;var r=function(){function e(){this._listeners={}}return e.prototype.addListener=function(e,t){void 0===this._listeners[e]&&(this._listeners[e]=[]),this._listeners[e].push(t)},e.prototype.removeListener=function(e,t){if(void 0!==this._listeners[e]){var r=this._listeners[e].indexOf(t);-1!==r&&this._listeners[e].splice(r,1)}},e.prototype.removeAllListeners=function(e){var t=this;e?this._listeners[e]=[]:Object.keys(this._listeners).forEach((function(e){t._listeners[e]=[]}))},e.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];void 0!==this._listeners[e]&&this._listeners[e].forEach((function(e){e.apply(void 0,t)}))},e}();t.Emitter=r},522:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.findForceFromFeature=t.getMatchedTrafficAndAllocation=t.getMatchedTraffic=t.parseFromStringifiedSegments=t.getMatchedAllocation=void 0;var i=r(590),a=r(243);function n(e,t){for(var r=0,i=e.allocation;r<i.length;r++){var a=i[r],n=a.range,o=n[0],s=n[1];if(a.range&&o<=t&&s>=t)return a}}function o(e){return"string"==typeof e&&(e.startsWith("{")||e.startsWith("["))?JSON.parse(e):e}t.getMatchedAllocation=n,t.parseFromStringifiedSegments=o,t.getMatchedTraffic=function(e,t,r){return e.find((function(e){return!!(0,i.allGroupSegmentsAreMatched)(o(e.segments),t,r)}))},t.getMatchedTrafficAndAllocation=function(e,t,r,a){var s=e.find((function(e){return(0,i.allGroupSegmentsAreMatched)(o(e.segments),t,a)}));return s?{matchedTraffic:s,matchedAllocation:n(s,r)}:{matchedTraffic:void 0,matchedAllocation:void 0}},t.findForceFromFeature=function(e,t,r){if(e.force)return e.force.find((function(e){return e.conditions?(0,a.allConditionsAreMatched)(e.conditions,t):!!e.segments&&(0,i.allGroupSegmentsAreMatched)(e.segments,t,r)}))}},97:function(e,t,r){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,a)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),a=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||i(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),a(r(725),t),a(r(681),t),a(r(687),t),a(r(243),t)},681:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createInstance=t.FeaturevisorInstance=t.getValueByType=t.EvaluationReason=void 0;var i,a=r(687),n=r(913),o=r(186),s=r(725),u=r(522),l=r(243),f=r(590),c=".",d={schemaVersion:"1",revision:"unknown",attributes:[],segments:[],features:[]};function h(e,t){return t?t(e):fetch(e).then((function(e){return e.json()}))}function g(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}}!function(e){e.NOT_FOUND="not_found",e.NO_VARIATIONS="no_variations",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"}(i=t.EvaluationReason||(t.EvaluationReason={})),t.getValueByType=g;var v=function(){function e(e){var t=this;this.bucketKeySeparator=e.bucketKeySeparator||c,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||(0,a.createLogger)(),this.refreshInterval=e.refreshInterval,this.stickyFeatures=e.stickyFeatures,this.emitter=new o.Emitter,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);var r=this.emitter.addListener.bind(this.emitter);this.on=r,this.addListener=r;var i=this.emitter.removeListener.bind(this.emitter);if(this.off=i,this.removeListener=i,this.removeAllListeners=this.emitter.removeAllListeners.bind(this.emitter),e.datafileUrl)this.setDatafile(e.datafile||d),h(e.datafileUrl,e.handleDatafileFetch).then((function(e){t.setDatafile(e),t.statuses.ready=!0,t.emitter.emit("ready"),t.refreshInterval&&t.startRefreshing()})).catch((function(e){t.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((function(){t.emitter.emit("ready")}),0)}}return e.prototype.setLogLevels=function(e){this.logger.setLevels(e)},e.prototype.onReady=function(){var e=this;return new Promise((function(t){if(e.statuses.ready)return t(e);var r=function(){e.emitter.removeListener("ready",r),t(e)};e.emitter.addListener("ready",r)}))},e.prototype.setDatafile=function(e){try{this.datafileReader=new n.DatafileReader("string"==typeof e?JSON.parse(e):e)}catch(e){this.logger.error("could not parse datafile",{error:e})}},e.prototype.setStickyFeatures=function(e){this.stickyFeatures=e},e.prototype.getRevision=function(){return this.datafileReader.getRevision()},e.prototype.getFeature=function(e){return"string"==typeof e?this.datafileReader.getFeature(e):e},e.prototype.getBucketKey=function(e,t){var r,i,a=e.key;if("string"==typeof e.bucketBy)r="plain",i=[e.bucketBy];else if(Array.isArray(e.bucketBy))r="and",i=e.bucketBy;else{if("object"!=typeof e.bucketBy||!Array.isArray(e.bucketBy.or))throw this.logger.error("invalid bucketBy",{featureKey:a,bucketBy:e.bucketBy}),new Error("invalid bucketBy");r="or",i=e.bucketBy.or}var n=[];i.forEach((function(e){var i=t[e];void 0!==i&&("plain"===r||"and"===r||0===n.length)&&n.push(i)})),n.push(a);var o=n.join(this.bucketKeySeparator);return this.configureBucketKey?this.configureBucketKey(e,t,o):o},e.prototype.getBucketValue=function(e,t){var r=this.getBucketKey(e,t),i=(0,s.getBucketedNumber)(r);return this.configureBucketValue?this.configureBucketValue(e,t,i):i},e.prototype.isReady=function(){return this.statuses.ready},e.prototype.refresh=function(){var e=this;return this.logger.debug("refreshing datafile"),this.statuses.refreshInProgress?this.logger.warn("refresh in progress, skipping"):this.datafileUrl?(this.statuses.refreshInProgress=!0,void h(this.datafileUrl,this.handleDatafileFetch).then((function(t){var r=e.getRevision()!==t.revision;e.setDatafile(t),e.logger.info("refreshed datafile"),e.emitter.emit("refresh"),r&&e.emitter.emit("update"),e.statuses.refreshInProgress=!1})).catch((function(t){e.logger.error("failed to refresh datafile",{error:t}),e.statuses.refreshInProgress=!1}))):this.logger.error("cannot refresh since `datafileUrl` is not provided")},e.prototype.startRefreshing=function(){var e=this;return this.datafileUrl?this.intervalId?this.logger.warn("refreshing has already started"):this.refreshInterval?void(this.intervalId=setInterval((function(){e.refresh()}),1e3*this.refreshInterval)):this.logger.warn("no `refreshInterval` option provided"):this.logger.error("cannot start refreshing since `datafileUrl` is not provided")},e.prototype.stopRefreshing=function(){if(!this.intervalId)return this.logger.warn("refreshing has not started yet");clearInterval(this.intervalId)},e.prototype.evaluateFlag=function(e,t){var r,a=this;void 0===t&&(t={});try{var n="string"==typeof e?e:e.key;if(this.stickyFeatures&&this.stickyFeatures[n]&&void 0!==this.stickyFeatures[n].enabled)return r={featureKey:n,reason:i.STICKY,enabled:this.stickyFeatures[n].enabled,sticky:this.stickyFeatures[n]},this.logger.debug("using sticky enabled",r),r;if(this.statuses&&!this.statuses.ready&&this.initialFeatures&&this.initialFeatures[n]&&void 0!==this.initialFeatures[n].enabled)return r={featureKey:n,reason:i.INITIAL,enabled:this.initialFeatures[n].enabled,initial:this.initialFeatures[n]},this.logger.debug("using initial enabled",r),r;var o=this.getFeature(e);if(!o)return r={featureKey:n,reason:i.NOT_FOUND},this.logger.warn("feature not found",r),r;o.deprecated&&this.logger.warn("feature is deprecated",{featureKey:o.key});var s=this.interceptContext?this.interceptContext(t):t,l=(0,u.findForceFromFeature)(o,t,this.datafileReader);if(l&&void 0!==l.enabled)return r={featureKey:o.key,reason:i.FORCED,enabled:l.enabled},this.logger.debug("forced enabled found",r),r;if(o.required&&o.required.length>0){var f=o.required.every((function(e){var t,r;return"string"==typeof e?t=e:(t=e.key,r=e.variation),!!a.isEnabled(t,s)&&(void 0===r||a.getVariation(t,s)===r)}));if(!f)return r={featureKey:o.key,reason:i.REQUIRED,enabled:f},this.logger.debug("required features not enabled",r),r}var c=this.getBucketValue(o,s),d=(0,u.getMatchedTraffic)(o.traffic,s,this.datafileReader);if(d){if(o.ranges&&o.ranges.length>0)return o.ranges.find((function(e){return c>=e[0]&&c<e[1]}))?(r={featureKey:o.key,reason:i.ALLOCATED,enabled:void 0===d.enabled||d.enabled,bucketValue:c},this.logger.debug("matched",r),r):(r={featureKey:o.key,reason:i.OUT_OF_RANGE,enabled:!1,bucketValue:c},this.logger.debug("not matched",r),r);if(void 0!==d.enabled)return r={featureKey:o.key,reason:i.OVERRIDE,enabled:d.enabled,bucketValue:c,ruleKey:d.key,traffic:d},this.logger.debug("override from rule",r),r;if(c<=d.percentage)return r={featureKey:o.key,reason:i.RULE,enabled:!0,bucketValue:c,ruleKey:d.key,traffic:d},this.logger.debug("matched traffic",r),r}return r={featureKey:o.key,reason:i.ERROR,enabled:!1,bucketValue:c},this.logger.debug("nothing matched",r),r}catch(t){return r={featureKey:"string"==typeof e?e:e.key,reason:i.ERROR,error:t},this.logger.error("error",r),r}},e.prototype.isEnabled=function(e,t){void 0===t&&(t={});try{return!0===this.evaluateFlag(e,t).enabled}catch(t){return this.logger.error("isEnabled",{featureKey:e,error:t}),!1}},e.prototype.evaluateVariation=function(e,t){var r;void 0===t&&(t={});try{var a="string"==typeof e?e:e.key;if(!1===this.evaluateFlag(e,t).enabled)return r={featureKey:a,reason:i.DISABLED},this.logger.debug("feature is disabled",r),r;if(this.stickyFeatures&&this.stickyFeatures[a]&&void 0!==(n=this.stickyFeatures[a].variation))return r={featureKey:a,reason:i.STICKY,variationValue:n},this.logger.debug("using sticky variation",r),r;if(this.statuses&&!this.statuses.ready&&this.initialFeatures&&this.initialFeatures[a]&&void 0!==this.initialFeatures[a].variation){var n=this.initialFeatures[a].variation;return r={featureKey:a,reason:i.INITIAL,variationValue:n},this.logger.debug("using initial variation",r),r}var o=this.getFeature(e);if(!o)return r={featureKey:a,reason:i.NOT_FOUND},this.logger.warn("feature not found",r),r;if(!o.variations||0===o.variations.length)return r={featureKey:a,reason:i.NO_VARIATIONS},this.logger.warn("no variations",r),r;var s=this.interceptContext?this.interceptContext(t):t,l=(0,u.findForceFromFeature)(o,t,this.datafileReader);if(l&&l.variation&&(g=o.variations.find((function(e){return e.value===l.variation}))))return r={featureKey:o.key,reason:i.FORCED,variation:g},this.logger.debug("forced variation found",r),r;var f=this.getBucketValue(o,s),c=(0,u.getMatchedTrafficAndAllocation)(o.traffic,s,f,this.datafileReader),d=c.matchedTraffic,h=c.matchedAllocation;if(d){var g;if(d.variation&&(g=o.variations.find((function(e){return e.value===d.variation}))))return r={featureKey:o.key,reason:i.RULE,variation:g,bucketValue:f,ruleKey:d.key},this.logger.debug("override from rule",r),r;if(h&&h.variation&&(g=o.variations.find((function(e){return e.value===h.variation}))))return r={featureKey:o.key,reason:i.ALLOCATED,bucketValue:f,variation:g},this.logger.debug("allocated variation",r),r}return r={featureKey:o.key,reason:i.ERROR,bucketValue:f},this.logger.debug("no matched variation",r),r}catch(t){return r={featureKey:"string"==typeof e?e:e.key,reason:i.ERROR,error:t},this.logger.error("error",r),r}},e.prototype.getVariation=function(e,t){void 0===t&&(t={});try{var 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})}},e.prototype.activate=function(e,t){void 0===t&&(t={});try{var r=this.evaluateVariation(e,t),i=r.variation?r.variation.value:r.variationValue;if(void 0===i)return;var a=this.interceptContext?this.interceptContext(t):t,n={};return this.datafileReader.getAllAttributes().filter((function(e){return!0===e.capture})).forEach((function(e){void 0!==a[e.key]&&(n[e.key]=t[e.key])})),this.emitter.emit("activation",e,i,a,n,r),i}catch(t){return void this.logger.error("activate",{featureKey:e,error:t})}},e.prototype.evaluateVariable=function(e,t,r){var a,n=this;void 0===r&&(r={});try{var o,s="string"==typeof e?e:e.key;if(!1===this.evaluateFlag(e,r).enabled)return a={featureKey:s,reason:i.DISABLED},this.logger.debug("feature is disabled",a),a;if(this.stickyFeatures&&this.stickyFeatures[s]&&(o=this.stickyFeatures[s].variables)){var c=o[t];if(void 0!==c)return a={featureKey:s,reason:i.STICKY,variableKey:t,variableValue:c},this.logger.debug("using sticky variable",a),a}if(this.statuses&&!this.statuses.ready&&this.initialFeatures&&this.initialFeatures[s]&&(o=this.initialFeatures[s].variables)&&void 0!==o[t])return a={featureKey:s,reason:i.INITIAL,variableKey:t,variableValue:o[t]},this.logger.debug("using initial variable",a),a;var d=this.getFeature(e);if(!d)return a={featureKey:s,reason:i.NOT_FOUND,variableKey:t},this.logger.warn("feature not found in datafile",a),a;var h=Array.isArray(d.variablesSchema)?d.variablesSchema.find((function(e){return e.key===t})):void 0;if(!h)return a={featureKey:s,reason:i.NOT_FOUND,variableKey:t},this.logger.warn("variable schema not found",a),a;var g=this.interceptContext?this.interceptContext(r):r,v=(0,u.findForceFromFeature)(d,r,this.datafileReader);if(v&&v.variables&&void 0!==v.variables[t])return a={featureKey:d.key,reason:i.FORCED,variableKey:t,variableSchema:h,variableValue:v.variables[t]},this.logger.debug("forced variable",a),a;var y=this.getBucketValue(d,g),p=(0,u.getMatchedTrafficAndAllocation)(d.traffic,g,y,this.datafileReader),b=p.matchedTraffic,m=p.matchedAllocation;if(b){if(b.variables&&void 0!==b.variables[t])return a={featureKey:d.key,reason:i.RULE,variableKey:t,variableSchema:h,variableValue:b.variables[t],bucketValue:y,ruleKey:b.key},this.logger.debug("override from rule",a),a;var k;if(v&&v.variation?k=v.variation:m&&m.variation&&(k=m.variation),k&&Array.isArray(d.variations)){var A=d.variations.find((function(e){return e.value===k}));if(A&&A.variables){var F=A.variables.find((function(e){return e.key===t}));if(F){if(F.overrides){var V=F.overrides.find((function(e){return e.conditions?(0,l.allConditionsAreMatched)("string"==typeof e.conditions?JSON.parse(e.conditions):e.conditions,g):!!e.segments&&(0,f.allGroupSegmentsAreMatched)((0,u.parseFromStringifiedSegments)(e.segments),g,n.datafileReader)}));if(V)return a={featureKey:d.key,reason:i.OVERRIDE,variableKey:t,variableSchema:h,variableValue:V.value,bucketValue:y,ruleKey:b.key},this.logger.debug("variable override",a),a}if(void 0!==F.value)return a={featureKey:d.key,reason:i.ALLOCATED,variableKey:t,variableSchema:h,variableValue:F.value,bucketValue:y,ruleKey:b.key},this.logger.debug("allocated variable",a),a}}}}return a={featureKey:d.key,reason:i.DEFAULTED,variableKey:t,variableSchema:h,variableValue:h.defaultValue,bucketValue:y},this.logger.debug("using default value",a),a}catch(r){return a={featureKey:"string"==typeof e?e:e.key,reason:i.ERROR,variableKey:t,error:r},this.logger.error("error",a),a}},e.prototype.getVariable=function(e,t,r){void 0===r&&(r={});try{var i=this.evaluateVariable(e,t,r);return void 0!==i.variableValue?i.variableSchema&&"json"===i.variableSchema.type&&"string"==typeof i.variableValue?JSON.parse(i.variableValue):i.variableValue:void 0}catch(r){return void this.logger.error("getVariable",{featureKey:e,variableKey:t,error:r})}},e.prototype.getVariableBoolean=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"boolean")},e.prototype.getVariableString=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"string")},e.prototype.getVariableInteger=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"integer")},e.prototype.getVariableDouble=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"double")},e.prototype.getVariableArray=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"array")},e.prototype.getVariableObject=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"object")},e.prototype.getVariableJSON=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"json")},e}();t.FeaturevisorInstance=v,t.createInstance=function(e){return new v(e)}},687:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createLogger=t.Logger=t.defaultLogHandler=t.defaultLogLevels=t.loggerPrefix=void 0,t.loggerPrefix="[Featurevisor]",t.defaultLogLevels=["warn","error"],t.defaultLogHandler=function(e,r,i){switch(void 0===i&&(i={}),e){case"debug":console.log(t.loggerPrefix,r,i);break;case"info":console.info(t.loggerPrefix,r,i);break;case"warn":console.warn(t.loggerPrefix,r,i);break;case"error":console.error(t.loggerPrefix,r,i)}};var r=function(){function e(e){this.levels=e.levels,this.handle=e.handler}return e.prototype.setLevels=function(e){this.levels=e},e.prototype.log=function(e,t,r){-1!==this.levels.indexOf(e)&&this.handle(e,t,r)},e.prototype.debug=function(e,t){this.log("debug",e,t)},e.prototype.info=function(e,t){this.log("info",e,t)},e.prototype.warn=function(e,t){this.log("warn",e,t)},e.prototype.error=function(e,t){this.log("error",e,t)},e}();t.Logger=r,t.createLogger=function(e){void 0===e&&(e={});var i=e.levels||t.defaultLogLevels,a=e.handler||t.defaultLogHandler;return new r({levels:i,handler:a})}},590:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.allGroupSegmentsAreMatched=t.segmentIsMatched=void 0;var i=r(243);function a(e,t){return(0,i.allConditionsAreMatched)(e.conditions,t)}t.segmentIsMatched=a,t.allGroupSegmentsAreMatched=function e(t,r,i){if("*"===t)return!0;if("string"==typeof t){var n=i.getSegment(t);return!!n&&a(n,r)}if("object"==typeof t){if("and"in t&&Array.isArray(t.and))return t.and.every((function(t){return e(t,r,i)}));if("or"in t&&Array.isArray(t.or))return t.or.some((function(t){return e(t,r,i)}));if("not"in t&&Array.isArray(t.not))return t.not.every((function(t){return!1===e(t,r,i)}))}return!!Array.isArray(t)&&t.every((function(t){return e(t,r,i)}))}}},t={};function r(i){var a=t[i];if(void 0!==a)return a.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,r),n.exports}return r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(97)})()));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FeaturevisorSDK=t():e.FeaturevisorSDK=t()}(this,(()=>(()=>{var e={480:(e,t,r)=>{"use strict";r.r(t),r.d(t,{compare:()=>n,compareVersions:()=>i,satisfies:()=>o,validate:()=>a});const i=(e,t)=>{const r=u(e),i=u(t),a=r.pop(),n=i.pop(),o=d(r,i);return 0!==o?o:a&&n?d(a.split("."),n.split(".")):a||n?a?-1:1:0},a=e=>"string"==typeof e&&/^[v\d]/.test(e)&&s.test(e),n=(e,t,r)=>{v(r);const a=i(e,t);return h[r].includes(a)},o=(e,t)=>{if(t.includes("||"))return t.split("||").some((t=>o(e,t)));if(t.includes(" "))return t.trim().replace(/\s{2,}/g," ").split(" ").every((t=>o(e,t)));const r=t.match(/^([<>=~^]+)/),i=r?r[1]:"=";if("^"!==i&&"~"!==i)return n(e,t,i);const[a,s,l,,f]=u(e),[c,h,g,,v]=u(t),y=[a,s,l],p=[c,null!=h?h:"x",null!=g?g:"x"];if(v){if(!f)return!1;if(0!==d(y,p))return!1;if(-1===d(f.split("."),v.split(".")))return!1}const b=p.findIndex((e=>"0"!==e))+1,m="~"===i?2:b>1?b:1;return 0===d(y.slice(0,m),p.slice(0,m))&&-1!==d(y.slice(m),p.slice(m))},s=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,u=e=>{if("string"!=typeof e)throw new TypeError("Invalid argument expected string");const t=e.match(s);if(!t)throw new Error(`Invalid argument not valid semver ('${e}' received)`);return t.shift(),t},l=e=>"*"===e||"x"===e||"X"===e,f=e=>{const t=parseInt(e,10);return isNaN(t)?e:t},c=(e,t)=>{if(l(e)||l(t))return 0;const[r,i]=((e,t)=>typeof e!=typeof t?[String(e),String(t)]:[e,t])(f(e),f(t));return r>i?1:r<i?-1:0},d=(e,t)=>{for(let r=0;r<Math.max(e.length,t.length);r++){const i=c(e[r]||"0",t[r]||"0");if(0!==i)return i}return 0},h={">":[1],">=":[0,1],"=":[0],"<=":[-1,0],"<":[-1]},g=Object.keys(h),v=e=>{if("string"!=typeof e)throw new TypeError("Invalid operator type, expected string but got "+typeof e);if(-1===g.indexOf(e))throw new Error(`Invalid operator, expected one of ${g.join("|")}`)}},77:e=>{!function(){const t=e=>(new TextEncoder).encode(e);function r(e,r){let i,a,n,o,s,u,l,f;for("string"==typeof e&&(e=t(e)),i=3&e.length,a=e.length-i,n=r,s=3432918353,u=461845907,f=0;f<a;)l=255&e[f]|(255&e[++f])<<8|(255&e[++f])<<16|(255&e[++f])<<24,++f,l=(65535&l)*s+(((l>>>16)*s&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,o=5*(65535&n)+((5*(n>>>16)&65535)<<16)&4294967295,n=27492+(65535&o)+((58964+(o>>>16)&65535)<<16);switch(l=0,i){case 3:l^=(255&e[f+2])<<16;case 2:l^=(255&e[f+1])<<8;case 1:l^=255&e[f],l=(65535&l)*s+(((l>>>16)*s&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 i=r;i.v2=function(e,r){"string"==typeof e&&(e=t(e));let i,a=e.length,n=r^a,o=0;for(;a>=4;)i=255&e[o]|(255&e[++o])<<8|(255&e[++o])<<16|(255&e[++o])<<24,i=1540483477*(65535&i)+((1540483477*(i>>>16)&65535)<<16),i^=i>>>24,i=1540483477*(65535&i)+((1540483477*(i>>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^i,a-=4,++o;switch(a){case 3:n^=(255&e[o+2])<<16;case 2:n^=(255&e[o+1])<<8;case 1:n^=255&e[o],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},i.v3=r,e.exports=i}()},725:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getBucketedNumber=t.MAX_BUCKETED_NUMBER=void 0;var i=r(77),a=Math.pow(2,32);t.MAX_BUCKETED_NUMBER=1e5,t.getBucketedNumber=function(e){var r=i.v3(e,1)/a;return Math.floor(r*t.MAX_BUCKETED_NUMBER)}},243:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.allConditionsAreMatched=t.conditionIsMatched=void 0;var i=r(480);function a(e,t){var r=e.attribute,a=e.operator,n=e.value;if("equals"===a)return t[r]===n;if("notEquals"===a)return t[r]!==n;if("before"===a||"after"===a){var o=(u=t[r])instanceof Date?u:new Date(u),s=n instanceof Date?n:new Date(n);return"before"===a?o<s:o>s}if("string"==typeof t[r]&&Array.isArray(n)){var u=t[r];if("in"===a)return-1!==n.indexOf(u);if("notIn"===a)return-1===n.indexOf(u)}else if("string"==typeof t[r]&&"string"==typeof n){if(u=t[r],"contains"===a)return-1!==u.indexOf(n);if("notContains"===a)return-1===u.indexOf(n);if("startsWith"===a)return u.startsWith(n);if("endsWith"===a)return u.endsWith(n);if("semverEquals"===a)return 0===(0,i.compareVersions)(u,n);if("semverNotEquals"===a)return 0!==(0,i.compareVersions)(u,n);if("semverGreaterThan"===a)return 1===(0,i.compareVersions)(u,n);if("semverGreaterThanOrEquals"===a)return(0,i.compareVersions)(u,n)>=0;if("semverLessThan"===a)return-1===(0,i.compareVersions)(u,n);if("semverLessThanOrEquals"===a)return(0,i.compareVersions)(u,n)<=0}else if("number"==typeof t[r]&&"number"==typeof n){if(u=t[r],"greaterThan"===a)return u>n;if("greaterThanOrEquals"===a)return u>=n;if("lessThan"===a)return u<n;if("lessThanOrEquals"===a)return u<=n}return!1}t.conditionIsMatched=a,t.allConditionsAreMatched=function e(t,r,i){if("attribute"in t)try{return a(t,r)}catch(e){return i.warn(e.message,{error:e,details:{condition:t,context:r}}),!1}return"and"in t&&Array.isArray(t.and)?t.and.every((function(t){return e(t,r,i)})):"or"in t&&Array.isArray(t.or)?t.or.some((function(t){return e(t,r,i)})):"not"in t&&Array.isArray(t.not)?t.not.every((function(){return!1===e({and:t.not},r,i)})):!!Array.isArray(t)&&t.every((function(t){return e(t,r,i)}))}},913:(e,t)=>{"use strict";function r(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}Object.defineProperty(t,"__esModule",{value:!0}),t.DatafileReader=t.parseJsonConditionsIfStringified=void 0,t.parseJsonConditionsIfStringified=r;var i=function(){function e(e){this.schemaVersion=e.schemaVersion,this.revision=e.revision,this.segments=e.segments,this.attributes=e.attributes,this.features=e.features}return e.prototype.getRevision=function(){return this.revision},e.prototype.getSchemaVersion=function(){return this.schemaVersion},e.prototype.getAllAttributes=function(){return this.attributes},e.prototype.getAttribute=function(e){return this.attributes.find((function(t){return t.key===e}))},e.prototype.getSegment=function(e){var t=this.segments.find((function(t){return t.key===e}));if(t)return r(t,"conditions")},e.prototype.getFeature=function(e){var t=this.features.find((function(t){return t.key===e}));if(t)return t},e}();t.DatafileReader=i},186:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Emitter=void 0;var r=function(){function e(){this._listeners={}}return e.prototype.addListener=function(e,t){void 0===this._listeners[e]&&(this._listeners[e]=[]),this._listeners[e].push(t)},e.prototype.removeListener=function(e,t){if(void 0!==this._listeners[e]){var r=this._listeners[e].indexOf(t);-1!==r&&this._listeners[e].splice(r,1)}},e.prototype.removeAllListeners=function(e){var t=this;e?this._listeners[e]=[]:Object.keys(this._listeners).forEach((function(e){t._listeners[e]=[]}))},e.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];void 0!==this._listeners[e]&&this._listeners[e].forEach((function(e){e.apply(void 0,t)}))},e}();t.Emitter=r},522:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.findForceFromFeature=t.getMatchedTrafficAndAllocation=t.getMatchedTraffic=t.parseFromStringifiedSegments=t.getMatchedAllocation=void 0;var i=r(590),a=r(243);function n(e,t){for(var r=0,i=e.allocation;r<i.length;r++){var a=i[r],n=a.range,o=n[0],s=n[1];if(a.range&&o<=t&&s>=t)return a}}function o(e){return"string"==typeof e&&(e.startsWith("{")||e.startsWith("["))?JSON.parse(e):e}t.getMatchedAllocation=n,t.parseFromStringifiedSegments=o,t.getMatchedTraffic=function(e,t,r,a){return e.find((function(e){return!!(0,i.allGroupSegmentsAreMatched)(o(e.segments),t,r,a)}))},t.getMatchedTrafficAndAllocation=function(e,t,r,a,s){var u=e.find((function(e){return(0,i.allGroupSegmentsAreMatched)(o(e.segments),t,a,s)}));return u?{matchedTraffic:u,matchedAllocation:n(u,r)}:{matchedTraffic:void 0,matchedAllocation:void 0}},t.findForceFromFeature=function(e,t,r,n){if(e.force)return e.force.find((function(e){return e.conditions?(0,a.allConditionsAreMatched)(e.conditions,t,n):!!e.segments&&(0,i.allGroupSegmentsAreMatched)(e.segments,t,r,n)}))}},97:function(e,t,r){"use strict";var i=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,a)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),a=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||i(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),a(r(725),t),a(r(681),t),a(r(687),t),a(r(243),t)},681:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createInstance=t.FeaturevisorInstance=t.getValueByType=t.EvaluationReason=void 0;var i,a=r(687),n=r(913),o=r(186),s=r(725),u=r(522),l=r(243),f=r(590),c=".",d={schemaVersion:"1",revision:"unknown",attributes:[],segments:[],features:[]};function h(e,t){return t?t(e):fetch(e).then((function(e){return e.json()}))}function g(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}}!function(e){e.NOT_FOUND="not_found",e.NO_VARIATIONS="no_variations",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"}(i=t.EvaluationReason||(t.EvaluationReason={})),t.getValueByType=g;var v=function(){function e(e){var t=this;this.bucketKeySeparator=e.bucketKeySeparator||c,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||(0,a.createLogger)(),this.refreshInterval=e.refreshInterval,this.stickyFeatures=e.stickyFeatures,this.emitter=new o.Emitter,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);var r=this.emitter.addListener.bind(this.emitter);this.on=r,this.addListener=r;var i=this.emitter.removeListener.bind(this.emitter);if(this.off=i,this.removeListener=i,this.removeAllListeners=this.emitter.removeAllListeners.bind(this.emitter),e.datafileUrl)this.setDatafile(e.datafile||d),h(e.datafileUrl,e.handleDatafileFetch).then((function(e){t.setDatafile(e),t.statuses.ready=!0,t.emitter.emit("ready"),t.refreshInterval&&t.startRefreshing()})).catch((function(e){t.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((function(){t.emitter.emit("ready")}),0)}}return e.prototype.setLogLevels=function(e){this.logger.setLevels(e)},e.prototype.onReady=function(){var e=this;return new Promise((function(t){if(e.statuses.ready)return t(e);var r=function(){e.emitter.removeListener("ready",r),t(e)};e.emitter.addListener("ready",r)}))},e.prototype.setDatafile=function(e){try{this.datafileReader=new n.DatafileReader("string"==typeof e?JSON.parse(e):e)}catch(e){this.logger.error("could not parse datafile",{error:e})}},e.prototype.setStickyFeatures=function(e){this.stickyFeatures=e},e.prototype.getRevision=function(){return this.datafileReader.getRevision()},e.prototype.getFeature=function(e){return"string"==typeof e?this.datafileReader.getFeature(e):e},e.prototype.getBucketKey=function(e,t){var r,i,a=e.key;if("string"==typeof e.bucketBy)r="plain",i=[e.bucketBy];else if(Array.isArray(e.bucketBy))r="and",i=e.bucketBy;else{if("object"!=typeof e.bucketBy||!Array.isArray(e.bucketBy.or))throw this.logger.error("invalid bucketBy",{featureKey:a,bucketBy:e.bucketBy}),new Error("invalid bucketBy");r="or",i=e.bucketBy.or}var n=[];i.forEach((function(e){var i=t[e];void 0!==i&&("plain"===r||"and"===r||0===n.length)&&n.push(i)})),n.push(a);var o=n.join(this.bucketKeySeparator);return this.configureBucketKey?this.configureBucketKey(e,t,o):o},e.prototype.getBucketValue=function(e,t){var r=this.getBucketKey(e,t),i=(0,s.getBucketedNumber)(r);return this.configureBucketValue?this.configureBucketValue(e,t,i):i},e.prototype.isReady=function(){return this.statuses.ready},e.prototype.refresh=function(){var e=this;return this.logger.debug("refreshing datafile"),this.statuses.refreshInProgress?this.logger.warn("refresh in progress, skipping"):this.datafileUrl?(this.statuses.refreshInProgress=!0,void h(this.datafileUrl,this.handleDatafileFetch).then((function(t){var r=e.getRevision()!==t.revision;e.setDatafile(t),e.logger.info("refreshed datafile"),e.emitter.emit("refresh"),r&&e.emitter.emit("update"),e.statuses.refreshInProgress=!1})).catch((function(t){e.logger.error("failed to refresh datafile",{error:t}),e.statuses.refreshInProgress=!1}))):this.logger.error("cannot refresh since `datafileUrl` is not provided")},e.prototype.startRefreshing=function(){var e=this;return this.datafileUrl?this.intervalId?this.logger.warn("refreshing has already started"):this.refreshInterval?void(this.intervalId=setInterval((function(){e.refresh()}),1e3*this.refreshInterval)):this.logger.warn("no `refreshInterval` option provided"):this.logger.error("cannot start refreshing since `datafileUrl` is not provided")},e.prototype.stopRefreshing=function(){if(!this.intervalId)return this.logger.warn("refreshing has not started yet");clearInterval(this.intervalId)},e.prototype.evaluateFlag=function(e,t){var r,a=this;void 0===t&&(t={});try{var n="string"==typeof e?e:e.key;if(this.stickyFeatures&&this.stickyFeatures[n]&&void 0!==this.stickyFeatures[n].enabled)return r={featureKey:n,reason:i.STICKY,enabled:this.stickyFeatures[n].enabled,sticky:this.stickyFeatures[n]},this.logger.debug("using sticky enabled",r),r;if(this.statuses&&!this.statuses.ready&&this.initialFeatures&&this.initialFeatures[n]&&void 0!==this.initialFeatures[n].enabled)return r={featureKey:n,reason:i.INITIAL,enabled:this.initialFeatures[n].enabled,initial:this.initialFeatures[n]},this.logger.debug("using initial enabled",r),r;var o=this.getFeature(e);if(!o)return r={featureKey:n,reason:i.NOT_FOUND},this.logger.warn("feature not found",r),r;o.deprecated&&this.logger.warn("feature is deprecated",{featureKey:o.key});var s=this.interceptContext?this.interceptContext(t):t,l=(0,u.findForceFromFeature)(o,t,this.datafileReader,this.logger);if(l&&void 0!==l.enabled)return r={featureKey:o.key,reason:i.FORCED,enabled:l.enabled},this.logger.debug("forced enabled found",r),r;if(o.required&&o.required.length>0){var f=o.required.every((function(e){var t,r;return"string"==typeof e?t=e:(t=e.key,r=e.variation),!!a.isEnabled(t,s)&&(void 0===r||a.getVariation(t,s)===r)}));if(!f)return r={featureKey:o.key,reason:i.REQUIRED,enabled:f},this.logger.debug("required features not enabled",r),r}var c=this.getBucketValue(o,s),d=(0,u.getMatchedTraffic)(o.traffic,s,this.datafileReader,this.logger);if(d){if(o.ranges&&o.ranges.length>0)return o.ranges.find((function(e){return c>=e[0]&&c<e[1]}))?(r={featureKey:o.key,reason:i.ALLOCATED,enabled:void 0===d.enabled||d.enabled,bucketValue:c},this.logger.debug("matched",r),r):(r={featureKey:o.key,reason:i.OUT_OF_RANGE,enabled:!1,bucketValue:c},this.logger.debug("not matched",r),r);if(void 0!==d.enabled)return r={featureKey:o.key,reason:i.OVERRIDE,enabled:d.enabled,bucketValue:c,ruleKey:d.key,traffic:d},this.logger.debug("override from rule",r),r;if(c<=d.percentage)return r={featureKey:o.key,reason:i.RULE,enabled:!0,bucketValue:c,ruleKey:d.key,traffic:d},this.logger.debug("matched traffic",r),r}return r={featureKey:o.key,reason:i.ERROR,enabled:!1,bucketValue:c},this.logger.debug("nothing matched",r),r}catch(t){return r={featureKey:"string"==typeof e?e:e.key,reason:i.ERROR,error:t},this.logger.error("error",r),r}},e.prototype.isEnabled=function(e,t){void 0===t&&(t={});try{return!0===this.evaluateFlag(e,t).enabled}catch(t){return this.logger.error("isEnabled",{featureKey:e,error:t}),!1}},e.prototype.evaluateVariation=function(e,t){var r;void 0===t&&(t={});try{var a="string"==typeof e?e:e.key;if(!1===this.evaluateFlag(e,t).enabled)return r={featureKey:a,reason:i.DISABLED},this.logger.debug("feature is disabled",r),r;if(this.stickyFeatures&&this.stickyFeatures[a]&&void 0!==(n=this.stickyFeatures[a].variation))return r={featureKey:a,reason:i.STICKY,variationValue:n},this.logger.debug("using sticky variation",r),r;if(this.statuses&&!this.statuses.ready&&this.initialFeatures&&this.initialFeatures[a]&&void 0!==this.initialFeatures[a].variation){var n=this.initialFeatures[a].variation;return r={featureKey:a,reason:i.INITIAL,variationValue:n},this.logger.debug("using initial variation",r),r}var o=this.getFeature(e);if(!o)return r={featureKey:a,reason:i.NOT_FOUND},this.logger.warn("feature not found",r),r;if(!o.variations||0===o.variations.length)return r={featureKey:a,reason:i.NO_VARIATIONS},this.logger.warn("no variations",r),r;var s=this.interceptContext?this.interceptContext(t):t,l=(0,u.findForceFromFeature)(o,t,this.datafileReader,this.logger);if(l&&l.variation&&(g=o.variations.find((function(e){return e.value===l.variation}))))return r={featureKey:o.key,reason:i.FORCED,variation:g},this.logger.debug("forced variation found",r),r;var f=this.getBucketValue(o,s),c=(0,u.getMatchedTrafficAndAllocation)(o.traffic,s,f,this.datafileReader,this.logger),d=c.matchedTraffic,h=c.matchedAllocation;if(d){var g;if(d.variation&&(g=o.variations.find((function(e){return e.value===d.variation}))))return r={featureKey:o.key,reason:i.RULE,variation:g,bucketValue:f,ruleKey:d.key},this.logger.debug("override from rule",r),r;if(h&&h.variation&&(g=o.variations.find((function(e){return e.value===h.variation}))))return r={featureKey:o.key,reason:i.ALLOCATED,bucketValue:f,variation:g},this.logger.debug("allocated variation",r),r}return r={featureKey:o.key,reason:i.ERROR,bucketValue:f},this.logger.debug("no matched variation",r),r}catch(t){return r={featureKey:"string"==typeof e?e:e.key,reason:i.ERROR,error:t},this.logger.error("error",r),r}},e.prototype.getVariation=function(e,t){void 0===t&&(t={});try{var 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})}},e.prototype.activate=function(e,t){void 0===t&&(t={});try{var r=this.evaluateVariation(e,t),i=r.variation?r.variation.value:r.variationValue;if(void 0===i)return;var a=this.interceptContext?this.interceptContext(t):t,n={};return this.datafileReader.getAllAttributes().filter((function(e){return!0===e.capture})).forEach((function(e){void 0!==a[e.key]&&(n[e.key]=t[e.key])})),this.emitter.emit("activation",e,i,a,n,r),i}catch(t){return void this.logger.error("activate",{featureKey:e,error:t})}},e.prototype.evaluateVariable=function(e,t,r){var a,n=this;void 0===r&&(r={});try{var o,s="string"==typeof e?e:e.key;if(!1===this.evaluateFlag(e,r).enabled)return a={featureKey:s,reason:i.DISABLED},this.logger.debug("feature is disabled",a),a;if(this.stickyFeatures&&this.stickyFeatures[s]&&(o=this.stickyFeatures[s].variables)){var c=o[t];if(void 0!==c)return a={featureKey:s,reason:i.STICKY,variableKey:t,variableValue:c},this.logger.debug("using sticky variable",a),a}if(this.statuses&&!this.statuses.ready&&this.initialFeatures&&this.initialFeatures[s]&&(o=this.initialFeatures[s].variables)&&void 0!==o[t])return a={featureKey:s,reason:i.INITIAL,variableKey:t,variableValue:o[t]},this.logger.debug("using initial variable",a),a;var d=this.getFeature(e);if(!d)return a={featureKey:s,reason:i.NOT_FOUND,variableKey:t},this.logger.warn("feature not found in datafile",a),a;var h=Array.isArray(d.variablesSchema)?d.variablesSchema.find((function(e){return e.key===t})):void 0;if(!h)return a={featureKey:s,reason:i.NOT_FOUND,variableKey:t},this.logger.warn("variable schema not found",a),a;var g=this.interceptContext?this.interceptContext(r):r,v=(0,u.findForceFromFeature)(d,r,this.datafileReader,this.logger);if(v&&v.variables&&void 0!==v.variables[t])return a={featureKey:d.key,reason:i.FORCED,variableKey:t,variableSchema:h,variableValue:v.variables[t]},this.logger.debug("forced variable",a),a;var y=this.getBucketValue(d,g),p=(0,u.getMatchedTrafficAndAllocation)(d.traffic,g,y,this.datafileReader,this.logger),b=p.matchedTraffic,m=p.matchedAllocation;if(b){if(b.variables&&void 0!==b.variables[t])return a={featureKey:d.key,reason:i.RULE,variableKey:t,variableSchema:h,variableValue:b.variables[t],bucketValue:y,ruleKey:b.key},this.logger.debug("override from rule",a),a;var k;if(v&&v.variation?k=v.variation:m&&m.variation&&(k=m.variation),k&&Array.isArray(d.variations)){var A=d.variations.find((function(e){return e.value===k}));if(A&&A.variables){var F=A.variables.find((function(e){return e.key===t}));if(F){if(F.overrides){var V=F.overrides.find((function(e){return e.conditions?(0,l.allConditionsAreMatched)("string"==typeof e.conditions?JSON.parse(e.conditions):e.conditions,g,n.logger):!!e.segments&&(0,f.allGroupSegmentsAreMatched)((0,u.parseFromStringifiedSegments)(e.segments),g,n.datafileReader,n.logger)}));if(V)return a={featureKey:d.key,reason:i.OVERRIDE,variableKey:t,variableSchema:h,variableValue:V.value,bucketValue:y,ruleKey:b.key},this.logger.debug("variable override",a),a}if(void 0!==F.value)return a={featureKey:d.key,reason:i.ALLOCATED,variableKey:t,variableSchema:h,variableValue:F.value,bucketValue:y,ruleKey:b.key},this.logger.debug("allocated variable",a),a}}}}return a={featureKey:d.key,reason:i.DEFAULTED,variableKey:t,variableSchema:h,variableValue:h.defaultValue,bucketValue:y},this.logger.debug("using default value",a),a}catch(r){return a={featureKey:"string"==typeof e?e:e.key,reason:i.ERROR,variableKey:t,error:r},this.logger.error("error",a),a}},e.prototype.getVariable=function(e,t,r){void 0===r&&(r={});try{var i=this.evaluateVariable(e,t,r);return void 0!==i.variableValue?i.variableSchema&&"json"===i.variableSchema.type&&"string"==typeof i.variableValue?JSON.parse(i.variableValue):i.variableValue:void 0}catch(r){return void this.logger.error("getVariable",{featureKey:e,variableKey:t,error:r})}},e.prototype.getVariableBoolean=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"boolean")},e.prototype.getVariableString=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"string")},e.prototype.getVariableInteger=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"integer")},e.prototype.getVariableDouble=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"double")},e.prototype.getVariableArray=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"array")},e.prototype.getVariableObject=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"object")},e.prototype.getVariableJSON=function(e,t,r){return void 0===r&&(r={}),g(this.getVariable(e,t,r),"json")},e}();t.FeaturevisorInstance=v,t.createInstance=function(e){return new v(e)}},687:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createLogger=t.Logger=t.defaultLogHandler=t.defaultLogLevels=t.loggerPrefix=void 0,t.loggerPrefix="[Featurevisor]",t.defaultLogLevels=["warn","error"],t.defaultLogHandler=function(e,r,i){switch(void 0===i&&(i={}),e){case"debug":console.log(t.loggerPrefix,r,i);break;case"info":console.info(t.loggerPrefix,r,i);break;case"warn":console.warn(t.loggerPrefix,r,i);break;case"error":console.error(t.loggerPrefix,r,i)}};var r=function(){function e(e){this.levels=e.levels,this.handle=e.handler}return e.prototype.setLevels=function(e){this.levels=e},e.prototype.log=function(e,t,r){-1!==this.levels.indexOf(e)&&this.handle(e,t,r)},e.prototype.debug=function(e,t){this.log("debug",e,t)},e.prototype.info=function(e,t){this.log("info",e,t)},e.prototype.warn=function(e,t){this.log("warn",e,t)},e.prototype.error=function(e,t){this.log("error",e,t)},e}();t.Logger=r,t.createLogger=function(e){void 0===e&&(e={});var i=e.levels||t.defaultLogLevels,a=e.handler||t.defaultLogHandler;return new r({levels:i,handler:a})}},590:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.allGroupSegmentsAreMatched=t.segmentIsMatched=void 0;var i=r(243);function a(e,t,r){return(0,i.allConditionsAreMatched)(e.conditions,t,r)}t.segmentIsMatched=a,t.allGroupSegmentsAreMatched=function e(t,r,i,n){if("*"===t)return!0;if("string"==typeof t){var o=i.getSegment(t);return!!o&&a(o,r,n)}if("object"==typeof t){if("and"in t&&Array.isArray(t.and))return t.and.every((function(t){return e(t,r,i,n)}));if("or"in t&&Array.isArray(t.or))return t.or.some((function(t){return e(t,r,i,n)}));if("not"in t&&Array.isArray(t.not))return t.not.every((function(t){return!1===e(t,r,i,n)}))}return!!Array.isArray(t)&&t.every((function(t){return e(t,r,i,n)}))}}},t={};function r(i){var a=t[i];if(void 0!==a)return a.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,r),n.exports}return r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(97)})()));
//# sourceMappingURL=index.js.map
import { Context, Condition, PlainCondition } from "@featurevisor/types";
import { Logger } from "./logger";
export declare function conditionIsMatched(condition: PlainCondition, context: Context): boolean;
export declare function allConditionsAreMatched(conditions: Condition[] | Condition, context: Context): boolean;
export declare function allConditionsAreMatched(conditions: Condition[] | Condition, context: Context, logger: Logger): boolean;

@@ -81,11 +81,23 @@ import { compareVersions } from "compare-versions";

}
export function allConditionsAreMatched(conditions, context) {
export function allConditionsAreMatched(conditions, context, logger) {
if ("attribute" in conditions) {
return conditionIsMatched(conditions, context);
try {
return conditionIsMatched(conditions, context);
}
catch (e) {
logger.warn(e.message, {
error: e,
details: {
condition: conditions,
context: context,
},
});
return false;
}
}
if ("and" in conditions && Array.isArray(conditions.and)) {
return conditions.and.every(function (c) { return allConditionsAreMatched(c, context); });
return conditions.and.every(function (c) { return allConditionsAreMatched(c, context, logger); });
}
if ("or" in conditions && Array.isArray(conditions.or)) {
return conditions.or.some(function (c) { return allConditionsAreMatched(c, context); });
return conditions.or.some(function (c) { return allConditionsAreMatched(c, context, logger); });
}

@@ -96,7 +108,7 @@ if ("not" in conditions && Array.isArray(conditions.not)) {

and: conditions.not,
}, context) === false;
}, context, logger) === false;
});
}
if (Array.isArray(conditions)) {
return conditions.every(function (c) { return allConditionsAreMatched(c, context); });
return conditions.every(function (c) { return allConditionsAreMatched(c, context, logger); });
}

@@ -103,0 +115,0 @@ return false;

import { Allocation, Context, Traffic, Feature, Force } from "@featurevisor/types";
import { DatafileReader } from "./datafileReader";
import { Logger } from "./logger";
export declare function getMatchedAllocation(traffic: Traffic, bucketValue: number): Allocation | undefined;
export declare function parseFromStringifiedSegments(value: any): any;
export declare function getMatchedTraffic(traffic: Traffic[], context: Context, datafileReader: DatafileReader): Traffic | undefined;
export declare function getMatchedTraffic(traffic: Traffic[], context: Context, datafileReader: DatafileReader, logger: Logger): Traffic | undefined;
export interface MatchedTrafficAndAllocation {

@@ -10,3 +11,3 @@ matchedTraffic: Traffic | undefined;

}
export declare function getMatchedTrafficAndAllocation(traffic: Traffic[], context: Context, bucketValue: number, datafileReader: DatafileReader): MatchedTrafficAndAllocation;
export declare function findForceFromFeature(feature: Feature, context: Context, datafileReader: DatafileReader): Force | undefined;
export declare function getMatchedTrafficAndAllocation(traffic: Traffic[], context: Context, bucketValue: number, datafileReader: DatafileReader, logger: Logger): MatchedTrafficAndAllocation;
export declare function findForceFromFeature(feature: Feature, context: Context, datafileReader: DatafileReader, logger: Logger): Force | undefined;

@@ -19,5 +19,5 @@ import { allGroupSegmentsAreMatched } from "./segments";

}
export function getMatchedTraffic(traffic, context, datafileReader) {
export function getMatchedTraffic(traffic, context, datafileReader, logger) {
return traffic.find(function (t) {
if (!allGroupSegmentsAreMatched(parseFromStringifiedSegments(t.segments), context, datafileReader)) {
if (!allGroupSegmentsAreMatched(parseFromStringifiedSegments(t.segments), context, datafileReader, logger)) {
return false;

@@ -28,5 +28,5 @@ }

}
export function getMatchedTrafficAndAllocation(traffic, context, bucketValue, datafileReader) {
export function getMatchedTrafficAndAllocation(traffic, context, bucketValue, datafileReader, logger) {
var matchedTraffic = traffic.find(function (t) {
return allGroupSegmentsAreMatched(parseFromStringifiedSegments(t.segments), context, datafileReader);
return allGroupSegmentsAreMatched(parseFromStringifiedSegments(t.segments), context, datafileReader, logger);
});

@@ -45,3 +45,3 @@ if (!matchedTraffic) {

}
export function findForceFromFeature(feature, context, datafileReader) {
export function findForceFromFeature(feature, context, datafileReader, logger) {
if (!feature.force) {

@@ -52,6 +52,6 @@ return undefined;

if (f.conditions) {
return allConditionsAreMatched(f.conditions, context);
return allConditionsAreMatched(f.conditions, context, logger);
}
if (f.segments) {
return allGroupSegmentsAreMatched(f.segments, context, datafileReader);
return allGroupSegmentsAreMatched(f.segments, context, datafileReader, logger);
}

@@ -58,0 +58,0 @@ return false;

@@ -333,3 +333,3 @@ import { createLogger } from "./logger";

// forced
var force = findForceFromFeature(feature, context, this.datafileReader);
var force = findForceFromFeature(feature, context, this.datafileReader, this.logger);
if (force && typeof force.enabled !== "undefined") {

@@ -378,3 +378,3 @@ evaluation = {

var bucketValue_1 = this.getBucketValue(feature, finalContext_1);
var matchedTraffic = getMatchedTraffic(feature.traffic, finalContext_1, this.datafileReader);
var matchedTraffic = getMatchedTraffic(feature.traffic, finalContext_1, this.datafileReader, this.logger);
if (matchedTraffic) {

@@ -531,3 +531,3 @@ // check if mutually exclusive

// forced
var force_1 = findForceFromFeature(feature, context, this.datafileReader);
var force_1 = findForceFromFeature(feature, context, this.datafileReader, this.logger);
if (force_1 && force_1.variation) {

@@ -547,3 +547,3 @@ var variation = feature.variations.find(function (v) { return v.value === force_1.variation; });

var bucketValue = this.getBucketValue(feature, finalContext);
var _a = getMatchedTrafficAndAllocation(feature.traffic, finalContext, bucketValue, this.datafileReader), matchedTraffic_1 = _a.matchedTraffic, matchedAllocation_1 = _a.matchedAllocation;
var _a = getMatchedTrafficAndAllocation(feature.traffic, finalContext, bucketValue, this.datafileReader, this.logger), matchedTraffic_1 = _a.matchedTraffic, matchedAllocation_1 = _a.matchedAllocation;
if (matchedTraffic_1) {

@@ -727,3 +727,3 @@ // override from rule

// forced
var force = findForceFromFeature(feature, context, this.datafileReader);
var force = findForceFromFeature(feature, context, this.datafileReader, this.logger);
if (force && force.variables && typeof force.variables[variableKey] !== "undefined") {

@@ -742,3 +742,3 @@ evaluation = {

var bucketValue = this.getBucketValue(feature, finalContext_3);
var _a = getMatchedTrafficAndAllocation(feature.traffic, finalContext_3, bucketValue, this.datafileReader), matchedTraffic = _a.matchedTraffic, matchedAllocation = _a.matchedAllocation;
var _a = getMatchedTrafficAndAllocation(feature.traffic, finalContext_3, bucketValue, this.datafileReader, this.logger), matchedTraffic = _a.matchedTraffic, matchedAllocation = _a.matchedAllocation;
if (matchedTraffic) {

@@ -776,6 +776,6 @@ // override from rule

if (o.conditions) {
return allConditionsAreMatched(typeof o.conditions === "string" ? JSON.parse(o.conditions) : o.conditions, finalContext_3);
return allConditionsAreMatched(typeof o.conditions === "string" ? JSON.parse(o.conditions) : o.conditions, finalContext_3, _this.logger);
}
if (o.segments) {
return allGroupSegmentsAreMatched(parseFromStringifiedSegments(o.segments), finalContext_3, _this.datafileReader);
return allGroupSegmentsAreMatched(parseFromStringifiedSegments(o.segments), finalContext_3, _this.datafileReader, _this.logger);
}

@@ -782,0 +782,0 @@ return false;

import { Context, GroupSegment, Segment } from "@featurevisor/types";
import { DatafileReader } from "./datafileReader";
export declare function segmentIsMatched(segment: Segment, context: Context): boolean;
export declare function allGroupSegmentsAreMatched(groupSegments: GroupSegment | GroupSegment[] | "*", context: Context, datafileReader: DatafileReader): boolean;
import { Logger } from "./logger";
export declare function segmentIsMatched(segment: Segment, context: Context, logger: Logger): boolean;
export declare function allGroupSegmentsAreMatched(groupSegments: GroupSegment | GroupSegment[] | "*", context: Context, datafileReader: DatafileReader, logger: Logger): boolean;
import { allConditionsAreMatched } from "./conditions";
export function segmentIsMatched(segment, context) {
return allConditionsAreMatched(segment.conditions, context);
export function segmentIsMatched(segment, context, logger) {
return allConditionsAreMatched(segment.conditions, context, logger);
}
export function allGroupSegmentsAreMatched(groupSegments, context, datafileReader) {
export function allGroupSegmentsAreMatched(groupSegments, context, datafileReader, logger) {
if (groupSegments === "*") {

@@ -12,3 +12,3 @@ return true;

if (segment) {
return segmentIsMatched(segment, context);
return segmentIsMatched(segment, context, logger);
}

@@ -20,3 +20,3 @@ return false;

return groupSegments.and.every(function (groupSegment) {
return allGroupSegmentsAreMatched(groupSegment, context, datafileReader);
return allGroupSegmentsAreMatched(groupSegment, context, datafileReader, logger);
});

@@ -26,3 +26,3 @@ }

return groupSegments.or.some(function (groupSegment) {
return allGroupSegmentsAreMatched(groupSegment, context, datafileReader);
return allGroupSegmentsAreMatched(groupSegment, context, datafileReader, logger);
});

@@ -32,3 +32,3 @@ }

return groupSegments.not.every(function (groupSegment) {
return allGroupSegmentsAreMatched(groupSegment, context, datafileReader) === false;
return allGroupSegmentsAreMatched(groupSegment, context, datafileReader, logger) === false;
});

@@ -39,3 +39,3 @@ }

return groupSegments.every(function (groupSegment) {
return allGroupSegmentsAreMatched(groupSegment, context, datafileReader);
return allGroupSegmentsAreMatched(groupSegment, context, datafileReader, logger);
});

@@ -42,0 +42,0 @@ }

{
"name": "@featurevisor/sdk",
"version": "1.3.0",
"version": "1.11.1",
"description": "Featurevisor SDK for Node.js and the browser",

@@ -52,3 +52,3 @@ "main": "dist/index.js",

},
"gitHead": "92829e94ab09474433695d29577bd3eb22490f97"
"gitHead": "b0de54112d2af4ba4af13dc7a554b18a60b2a574"
}

@@ -1,5 +0,9 @@

import { allConditionsAreMatched } from "./conditions";
import { Condition } from "@featurevisor/types";
import { allConditionsAreMatched } from "./conditions";
import { createLogger } from "./logger";
describe("sdk: Conditions", function () {
const logger = createLogger();
it("should be a function", function () {

@@ -20,6 +24,8 @@ expect(typeof allConditionsAreMatched).toEqual("function");

// match
expect(allConditionsAreMatched(conditions, { browser_type: "chrome" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { browser_type: "chrome" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { browser_type: "firefox" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { browser_type: "firefox" }, logger)).toEqual(
false,
);
});

@@ -37,6 +43,10 @@

// match
expect(allConditionsAreMatched(conditions, { browser_type: "firefox" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { browser_type: "firefox" }, logger)).toEqual(
true,
);
// not match
expect(allConditionsAreMatched(conditions, { browser_type: "chrome" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { browser_type: "chrome" }, logger)).toEqual(
false,
);
});

@@ -54,7 +64,7 @@

// match
expect(allConditionsAreMatched(conditions, { name: "Hello World" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Hello Universe" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Hello World" }, logger)).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Hello Universe" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { name: "Hi World" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { name: "Hi World" }, logger)).toEqual(false);
});

@@ -72,7 +82,7 @@

// match
expect(allConditionsAreMatched(conditions, { name: "Hello World" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Hi World" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Hello World" }, logger)).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Hi World" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { name: "Hi Universe" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { name: "Hi Universe" }, logger)).toEqual(false);
});

@@ -90,7 +100,7 @@

// match
expect(allConditionsAreMatched(conditions, { name: "Hello World" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Yo! Hello!" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Hello World" }, logger)).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Yo! Hello!" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { name: "Hi World" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { name: "Hi World" }, logger)).toEqual(false);
});

@@ -108,7 +118,7 @@

// match
expect(allConditionsAreMatched(conditions, { name: "Hi World" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { name: "Hi World" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { name: "Hello World" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { name: "Yo! Hello!" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { name: "Hello World" }, logger)).toEqual(false);
expect(allConditionsAreMatched(conditions, { name: "Yo! Hello!" }, logger)).toEqual(false);
});

@@ -126,8 +136,12 @@

// match
expect(allConditionsAreMatched(conditions, { browser_type: "chrome" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { browser_type: "firefox" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { browser_type: "chrome" }, logger)).toEqual(true);
expect(allConditionsAreMatched(conditions, { browser_type: "firefox" }, logger)).toEqual(
true,
);
// not match
expect(allConditionsAreMatched(conditions, { browser_type: "edge" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { browser_type: "safari" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { browser_type: "edge" }, logger)).toEqual(false);
expect(allConditionsAreMatched(conditions, { browser_type: "safari" }, logger)).toEqual(
false,
);
});

@@ -145,8 +159,12 @@

// match
expect(allConditionsAreMatched(conditions, { browser_type: "edge" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { browser_type: "safari" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { browser_type: "edge" }, logger)).toEqual(true);
expect(allConditionsAreMatched(conditions, { browser_type: "safari" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { browser_type: "chrome" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { browser_type: "firefox" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { browser_type: "chrome" }, logger)).toEqual(
false,
);
expect(allConditionsAreMatched(conditions, { browser_type: "firefox" }, logger)).toEqual(
false,
);
});

@@ -164,6 +182,6 @@

// match
expect(allConditionsAreMatched(conditions, { age: 19 })).toEqual(true);
expect(allConditionsAreMatched(conditions, { age: 19 }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { age: 17 })).toEqual(false);
expect(allConditionsAreMatched(conditions, { age: 17 }, logger)).toEqual(false);
});

@@ -181,8 +199,8 @@

// match
expect(allConditionsAreMatched(conditions, { age: 18 })).toEqual(true);
expect(allConditionsAreMatched(conditions, { age: 19 })).toEqual(true);
expect(allConditionsAreMatched(conditions, { age: 18 }, logger)).toEqual(true);
expect(allConditionsAreMatched(conditions, { age: 19 }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { age: 17 })).toEqual(false);
expect(allConditionsAreMatched(conditions, { age: 16 })).toEqual(false);
expect(allConditionsAreMatched(conditions, { age: 17 }, logger)).toEqual(false);
expect(allConditionsAreMatched(conditions, { age: 16 }, logger)).toEqual(false);
});

@@ -200,6 +218,6 @@

// match
expect(allConditionsAreMatched(conditions, { age: 17 })).toEqual(true);
expect(allConditionsAreMatched(conditions, { age: 17 }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { age: 19 })).toEqual(false);
expect(allConditionsAreMatched(conditions, { age: 19 }, logger)).toEqual(false);
});

@@ -217,8 +235,8 @@

// match
expect(allConditionsAreMatched(conditions, { age: 17 })).toEqual(true);
expect(allConditionsAreMatched(conditions, { age: 18 })).toEqual(true);
expect(allConditionsAreMatched(conditions, { age: 17 }, logger)).toEqual(true);
expect(allConditionsAreMatched(conditions, { age: 18 }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { age: 19 })).toEqual(false);
expect(allConditionsAreMatched(conditions, { age: 20 })).toEqual(false);
expect(allConditionsAreMatched(conditions, { age: 19 }, logger)).toEqual(false);
expect(allConditionsAreMatched(conditions, { age: 20 }, logger)).toEqual(false);
});

@@ -236,6 +254,6 @@

// match
expect(allConditionsAreMatched(conditions, { version: "1.0.0" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { version: "1.0.0" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { version: "2.0.0" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { version: "2.0.0" }, logger)).toEqual(false);
});

@@ -253,6 +271,6 @@

// match
expect(allConditionsAreMatched(conditions, { version: "2.0.0" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { version: "2.0.0" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { version: "1.0.0" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { version: "1.0.0" }, logger)).toEqual(false);
});

@@ -270,6 +288,6 @@

// match
expect(allConditionsAreMatched(conditions, { version: "2.0.0" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { version: "2.0.0" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { version: "0.9.0" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { version: "0.9.0" }, logger)).toEqual(false);
});

@@ -287,7 +305,7 @@

// match
expect(allConditionsAreMatched(conditions, { version: "1.0.0" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { version: "2.0.0" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { version: "1.0.0" }, logger)).toEqual(true);
expect(allConditionsAreMatched(conditions, { version: "2.0.0" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { version: "0.9.0" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { version: "0.9.0" }, logger)).toEqual(false);
});

@@ -305,6 +323,6 @@

// match
expect(allConditionsAreMatched(conditions, { version: "0.9.0" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { version: "0.9.0" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { version: "1.1.0" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { version: "1.1.0" }, logger)).toEqual(false);
});

@@ -322,6 +340,6 @@

// match
expect(allConditionsAreMatched(conditions, { version: "1.0.0" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { version: "1.0.0" }, logger)).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { version: "1.1.0" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { version: "1.1.0" }, logger)).toEqual(false);
});

@@ -339,11 +357,15 @@

// match
expect(allConditionsAreMatched(conditions, { date: "2023-05-12T00:00:00Z" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { date: "2023-05-12T00:00:00Z" }, logger)).toEqual(
true,
);
expect(
allConditionsAreMatched(conditions, { date: new Date("2023-05-12T00:00:00Z") }),
allConditionsAreMatched(conditions, { date: new Date("2023-05-12T00:00:00Z") }, logger),
).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { date: "2023-05-14T00:00:00Z" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { date: "2023-05-14T00:00:00Z" }, logger)).toEqual(
false,
);
expect(
allConditionsAreMatched(conditions, { date: new Date("2023-05-14T00:00:00Z") }),
allConditionsAreMatched(conditions, { date: new Date("2023-05-14T00:00:00Z") }, logger),
).toEqual(false);

@@ -362,11 +384,15 @@ });

// match
expect(allConditionsAreMatched(conditions, { date: "2023-05-14T00:00:00Z" })).toEqual(true);
expect(allConditionsAreMatched(conditions, { date: "2023-05-14T00:00:00Z" }, logger)).toEqual(
true,
);
expect(
allConditionsAreMatched(conditions, { date: new Date("2023-05-14T00:00:00Z") }),
allConditionsAreMatched(conditions, { date: new Date("2023-05-14T00:00:00Z") }, logger),
).toEqual(true);
// not match
expect(allConditionsAreMatched(conditions, { date: "2023-05-12T00:00:00Z" })).toEqual(false);
expect(allConditionsAreMatched(conditions, { date: "2023-05-12T00:00:00Z" }, logger)).toEqual(
false,
);
expect(
allConditionsAreMatched(conditions, { date: new Date("2023-05-12T00:00:00Z") }),
allConditionsAreMatched(conditions, { date: new Date("2023-05-12T00:00:00Z") }, logger),
).toEqual(false);

@@ -388,5 +414,9 @@ });

expect(
allConditionsAreMatched(conditions[0], {
browser_type: "chrome",
}),
allConditionsAreMatched(
conditions[0],
{
browser_type: "chrome",
},
logger,
),
).toEqual(true);

@@ -406,5 +436,9 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
},
logger,
),
).toEqual(true);

@@ -418,5 +452,9 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
},
logger,
),
).toEqual(true);

@@ -426,5 +464,9 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
},
logger,
),
).toEqual(true);

@@ -444,6 +486,10 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "1.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "1.0",
},
logger,
),
).toEqual(true);

@@ -468,7 +514,11 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "1.0",
foo: "bar",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "1.0",
foo: "bar",
},
logger,
),
).toEqual(true);

@@ -494,5 +544,9 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
},
logger,
),
).toEqual(true);

@@ -502,5 +556,9 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
},
logger,
),
).toEqual(false);

@@ -529,6 +587,10 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "1.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "1.0",
},
logger,
),
).toEqual(true);

@@ -538,5 +600,9 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
},
logger,
),
).toEqual(false);

@@ -562,5 +628,9 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
},
logger,
),
).toEqual(true);

@@ -589,5 +659,9 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_version: "1.0",
}),
allConditionsAreMatched(
conditions,
{
browser_version: "1.0",
},
logger,
),
).toEqual(true);

@@ -597,5 +671,9 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
},
logger,
),
).toEqual(false);

@@ -621,5 +699,9 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
},
logger,
),
).toEqual(true);

@@ -629,5 +711,9 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
},
logger,
),
).toEqual(false);

@@ -656,17 +742,29 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
browser_version: "2.0",
},
logger,
),
).toEqual(true);
expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
},
logger,
),
).toEqual(true);
expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "2.0",
},
logger,
),
).toEqual(true);

@@ -676,6 +774,10 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "1.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "1.0",
},
logger,
),
).toEqual(false);

@@ -715,13 +817,21 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "1.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "1.0",
},
logger,
),
).toEqual(true);
expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "2.0",
},
logger,
),
).toEqual(true);

@@ -731,12 +841,20 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "3.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "3.0",
},
logger,
),
).toEqual(false);
expect(
allConditionsAreMatched(conditions, {
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
browser_version: "2.0",
},
logger,
),
).toEqual(false);

@@ -779,15 +897,23 @@ });

expect(
allConditionsAreMatched(conditions, {
country: "nl",
browser_type: "chrome",
browser_version: "1.0",
}),
allConditionsAreMatched(
conditions,
{
country: "nl",
browser_type: "chrome",
browser_version: "1.0",
},
logger,
),
).toEqual(true);
expect(
allConditionsAreMatched(conditions, {
country: "nl",
browser_type: "chrome",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
country: "nl",
browser_type: "chrome",
browser_version: "2.0",
},
logger,
),
).toEqual(true);

@@ -797,13 +923,21 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "3.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "3.0",
},
logger,
),
).toEqual(false);
expect(
allConditionsAreMatched(conditions, {
country: "us",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
country: "us",
browser_version: "2.0",
},
logger,
),
).toEqual(false);

@@ -841,14 +975,22 @@ });

expect(
allConditionsAreMatched(conditions, {
browser_type: "chrome",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "chrome",
browser_version: "2.0",
},
logger,
),
).toEqual(true);
expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
device_type: "mobile",
orientation: "portrait",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
device_type: "mobile",
orientation: "portrait",
},
logger,
),
).toEqual(true);

@@ -858,13 +1000,21 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
browser_version: "2.0",
},
logger,
),
).toEqual(false);
expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
device_type: "desktop",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
device_type: "desktop",
},
logger,
),
).toEqual(false);

@@ -907,16 +1057,24 @@ });

expect(
allConditionsAreMatched(conditions, {
country: "nl",
browser_type: "chrome",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
country: "nl",
browser_type: "chrome",
browser_version: "2.0",
},
logger,
),
).toEqual(true);
expect(
allConditionsAreMatched(conditions, {
country: "nl",
browser_type: "firefox",
device_type: "mobile",
orientation: "portrait",
}),
allConditionsAreMatched(
conditions,
{
country: "nl",
browser_type: "firefox",
device_type: "mobile",
orientation: "portrait",
},
logger,
),
).toEqual(true);

@@ -926,14 +1084,22 @@

expect(
allConditionsAreMatched(conditions, {
browser_type: "firefox",
browser_version: "2.0",
}),
allConditionsAreMatched(
conditions,
{
browser_type: "firefox",
browser_version: "2.0",
},
logger,
),
).toEqual(false);
expect(
allConditionsAreMatched(conditions, {
country: "de",
browser_type: "firefox",
device_type: "desktop",
}),
allConditionsAreMatched(
conditions,
{
country: "de",
browser_type: "firefox",
device_type: "desktop",
},
logger,
),
).toEqual(false);

@@ -940,0 +1106,0 @@ });

@@ -5,2 +5,4 @@ import { compareVersions } from "compare-versions";

import { Logger } from "./logger";
export function conditionIsMatched(condition: PlainCondition, context: Context): boolean {

@@ -79,13 +81,26 @@ const { attribute, operator, value } = condition;

context: Context,
logger: Logger,
): boolean {
if ("attribute" in conditions) {
return conditionIsMatched(conditions, context);
try {
return conditionIsMatched(conditions, context);
} catch (e) {
logger.warn(e.message, {
error: e,
details: {
condition: conditions,
context,
},
});
return false;
}
}
if ("and" in conditions && Array.isArray(conditions.and)) {
return conditions.and.every((c) => allConditionsAreMatched(c, context));
return conditions.and.every((c) => allConditionsAreMatched(c, context, logger));
}
if ("or" in conditions && Array.isArray(conditions.or)) {
return conditions.or.some((c) => allConditionsAreMatched(c, context));
return conditions.or.some((c) => allConditionsAreMatched(c, context, logger));
}

@@ -101,2 +116,3 @@

context,
logger,
) === false,

@@ -107,3 +123,3 @@ );

if (Array.isArray(conditions)) {
return conditions.every((c) => allConditionsAreMatched(c, context));
return conditions.every((c) => allConditionsAreMatched(c, context, logger));
}

@@ -110,0 +126,0 @@

@@ -5,2 +5,3 @@ import { Allocation, Context, Traffic, Feature, Force } from "@featurevisor/types";

import { allConditionsAreMatched } from "./conditions";
import { Logger } from "./logger";

@@ -34,6 +35,12 @@ export function getMatchedAllocation(

datafileReader: DatafileReader,
logger: Logger,
): Traffic | undefined {
return traffic.find((t) => {
if (
!allGroupSegmentsAreMatched(parseFromStringifiedSegments(t.segments), context, datafileReader)
!allGroupSegmentsAreMatched(
parseFromStringifiedSegments(t.segments),
context,
datafileReader,
logger,
)
) {

@@ -57,2 +64,3 @@ return false;

datafileReader: DatafileReader,
logger: Logger,
): MatchedTrafficAndAllocation {

@@ -64,2 +72,3 @@ const matchedTraffic = traffic.find((t) => {

datafileReader,
logger,
);

@@ -87,2 +96,3 @@ });

datafileReader: DatafileReader,
logger: Logger,
): Force | undefined {

@@ -95,7 +105,7 @@ if (!feature.force) {

if (f.conditions) {
return allConditionsAreMatched(f.conditions, context);
return allConditionsAreMatched(f.conditions, context, logger);
}
if (f.segments) {
return allGroupSegmentsAreMatched(f.segments, context, datafileReader);
return allGroupSegmentsAreMatched(f.segments, context, datafileReader, logger);
}

@@ -102,0 +112,0 @@

@@ -524,3 +524,3 @@ import {

// forced
const force = findForceFromFeature(feature, context, this.datafileReader);
const force = findForceFromFeature(feature, context, this.datafileReader, this.logger);

@@ -583,3 +583,8 @@ if (force && typeof force.enabled !== "undefined") {

const matchedTraffic = getMatchedTraffic(feature.traffic, finalContext, this.datafileReader);
const matchedTraffic = getMatchedTraffic(
feature.traffic,
finalContext,
this.datafileReader,
this.logger,
);

@@ -779,3 +784,3 @@ if (matchedTraffic) {

// forced
const force = findForceFromFeature(feature, context, this.datafileReader);
const force = findForceFromFeature(feature, context, this.datafileReader, this.logger);

@@ -806,2 +811,3 @@ if (force && force.variation) {

this.datafileReader,
this.logger,
);

@@ -1047,3 +1053,3 @@

// forced
const force = findForceFromFeature(feature, context, this.datafileReader);
const force = findForceFromFeature(feature, context, this.datafileReader, this.logger);

@@ -1072,2 +1078,3 @@ if (force && force.variables && typeof force.variables[variableKey] !== "undefined") {

this.datafileReader,
this.logger,
);

@@ -1118,2 +1125,3 @@

finalContext,
this.logger,
);

@@ -1127,2 +1135,3 @@ }

this.datafileReader,
this.logger,
);

@@ -1129,0 +1138,0 @@ }

@@ -0,4 +1,6 @@

import { DatafileContent, GroupSegment } from "@featurevisor/types";
import { DatafileReader } from "./datafileReader";
import { allGroupSegmentsAreMatched } from "./segments";
import { DatafileContent, GroupSegment } from "@featurevisor/types";
import { createLogger } from "./logger";

@@ -11,2 +13,4 @@ interface Group {

describe("sdk: Segments", function () {
const logger = createLogger();
it("should be a function", function () {

@@ -182,9 +186,9 @@ expect(typeof allGroupSegmentsAreMatched).toEqual("function");

// match
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(true);
expect(allGroupSegmentsAreMatched(group.segments, { foo: "foo" }, datafileReader)).toEqual(
true,
);
expect(allGroupSegmentsAreMatched(group.segments, { bar: "bar" }, datafileReader)).toEqual(
true,
);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(true);
expect(
allGroupSegmentsAreMatched(group.segments, { foo: "foo" }, datafileReader, logger),
).toEqual(true);
expect(
allGroupSegmentsAreMatched(group.segments, { bar: "bar" }, datafileReader, logger),
).toEqual(true);
});

@@ -201,2 +205,3 @@

datafileReader,
logger,
),

@@ -209,2 +214,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -214,3 +220,3 @@ ).toEqual(true);

// not match
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(false);
expect(

@@ -221,2 +227,3 @@ allGroupSegmentsAreMatched(

datafileReader,
logger,
),

@@ -235,2 +242,3 @@ ).toEqual(false);

datafileReader,
logger,
),

@@ -243,2 +251,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -248,3 +257,3 @@ ).toEqual(true);

// not match
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(false);
expect(

@@ -255,2 +264,3 @@ allGroupSegmentsAreMatched(

datafileReader,
logger,
),

@@ -269,2 +279,3 @@ ).toEqual(false);

datafileReader,
logger,
),

@@ -277,2 +288,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -285,2 +297,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -293,2 +306,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -298,3 +312,3 @@ ).toEqual(true);

// not match
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(false);
expect(

@@ -305,2 +319,3 @@ allGroupSegmentsAreMatched(

datafileReader,
logger,
),

@@ -313,2 +328,3 @@ ).toEqual(false);

datafileReader,
logger,
),

@@ -327,2 +343,3 @@ ).toEqual(false);

datafileReader,
logger,
),

@@ -335,2 +352,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -343,2 +361,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -351,2 +370,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -356,3 +376,3 @@ ).toEqual(true);

// not match
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(false);
expect(

@@ -363,2 +383,3 @@ allGroupSegmentsAreMatched(

datafileReader,
logger,
),

@@ -371,2 +392,3 @@ ).toEqual(false);

datafileReader,
logger,
),

@@ -385,2 +407,3 @@ ).toEqual(false);

datafileReader,
logger,
),

@@ -393,2 +416,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -398,3 +422,3 @@ ).toEqual(true);

// not match
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(false);
expect(

@@ -405,2 +429,3 @@ allGroupSegmentsAreMatched(

datafileReader,
logger,
),

@@ -419,2 +444,3 @@ ).toEqual(false);

datafileReader,
logger,
),

@@ -427,2 +453,3 @@ ).toEqual(true);

datafileReader,
logger,
),

@@ -432,3 +459,3 @@ ).toEqual(true);

// not match
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(false);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(false);
expect(

@@ -439,2 +466,3 @@ allGroupSegmentsAreMatched(

datafileReader,
logger,
),

@@ -448,26 +476,26 @@ ).toEqual(false);

// match
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(true);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader)).toEqual(true);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(true);
expect(allGroupSegmentsAreMatched(group.segments, {}, datafileReader, logger)).toEqual(true);
expect(
allGroupSegmentsAreMatched(group.segments, { version: "5.6" }, datafileReader),
allGroupSegmentsAreMatched(group.segments, { version: "5.6" }, datafileReader, logger),
).toEqual(true);
expect(allGroupSegmentsAreMatched(group.segments, { version: 5.6 }, datafileReader)).toEqual(
true,
);
expect(
allGroupSegmentsAreMatched(group.segments, { version: "5.7" }, datafileReader),
allGroupSegmentsAreMatched(group.segments, { version: 5.6 }, datafileReader, logger),
).toEqual(true);
expect(allGroupSegmentsAreMatched(group.segments, { version: 5.7 }, datafileReader)).toEqual(
true,
);
expect(
allGroupSegmentsAreMatched(group.segments, { version: "5.7" }, datafileReader, logger),
).toEqual(true);
expect(
allGroupSegmentsAreMatched(group.segments, { version: 5.7 }, datafileReader, logger),
).toEqual(true);
// not match
expect(
allGroupSegmentsAreMatched(group.segments, { version: "5.5" }, datafileReader),
allGroupSegmentsAreMatched(group.segments, { version: "5.5" }, datafileReader, logger),
).toEqual(false);
expect(allGroupSegmentsAreMatched(group.segments, { version: 5.5 }, datafileReader)).toEqual(
false,
);
expect(
allGroupSegmentsAreMatched(group.segments, { version: 5.5 }, datafileReader, logger),
).toEqual(false);
});
});
});
import { Context, GroupSegment, Segment, Condition } from "@featurevisor/types";
import { allConditionsAreMatched } from "./conditions";
import { DatafileReader } from "./datafileReader";
import { Logger } from "./logger";
export function segmentIsMatched(segment: Segment, context: Context): boolean {
return allConditionsAreMatched(segment.conditions as Condition | Condition[], context);
export function segmentIsMatched(segment: Segment, context: Context, logger: Logger): boolean {
return allConditionsAreMatched(segment.conditions as Condition | Condition[], context, logger);
}

@@ -13,2 +14,3 @@

datafileReader: DatafileReader,
logger: Logger,
): boolean {

@@ -23,3 +25,3 @@ if (groupSegments === "*") {

if (segment) {
return segmentIsMatched(segment, context);
return segmentIsMatched(segment, context, logger);
}

@@ -33,3 +35,3 @@

return groupSegments.and.every((groupSegment) =>
allGroupSegmentsAreMatched(groupSegment, context, datafileReader),
allGroupSegmentsAreMatched(groupSegment, context, datafileReader, logger),
);

@@ -40,3 +42,3 @@ }

return groupSegments.or.some((groupSegment) =>
allGroupSegmentsAreMatched(groupSegment, context, datafileReader),
allGroupSegmentsAreMatched(groupSegment, context, datafileReader, logger),
);

@@ -48,3 +50,3 @@ }

(groupSegment) =>
allGroupSegmentsAreMatched(groupSegment, context, datafileReader) === false,
allGroupSegmentsAreMatched(groupSegment, context, datafileReader, logger) === false,
);

@@ -56,3 +58,3 @@ }

return groupSegments.every((groupSegment) =>
allGroupSegmentsAreMatched(groupSegment, context, datafileReader),
allGroupSegmentsAreMatched(groupSegment, context, datafileReader, logger),
);

@@ -59,0 +61,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc