@featurevisor/sdk
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.4.0](https://github.com/fahad19/featurevisor/compare/v0.3.0...v0.4.0) (2023-03-19) | ||
### Features | ||
* Create SDK instance for fetching datafile ([#19](https://github.com/fahad19/featurevisor/issues/19)) ([4560fb2](https://github.com/fahad19/featurevisor/commit/4560fb24a1989e46b2d18eb342806e0fc3a50af7)) | ||
# [0.3.0](https://github.com/fahad19/featurevisor/compare/v0.2.0...v0.3.0) (2023-03-17) | ||
@@ -8,0 +19,0 @@ |
@@ -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,(()=>{return e={77:e=>{!function(){const t=e=>(new TextEncoder).encode(e);function r(e,r){let n,i,o,a,u,s,c,f;for("string"==typeof e&&(e=t(e)),n=3&e.length,i=e.length-n,o=r,u=3432918353,s=461845907,f=0;f<i;)c=255&e[f]|(255&e[++f])<<8|(255&e[++f])<<16|(255&e[++f])<<24,++f,c=(65535&c)*u+(((c>>>16)*u&65535)<<16)&4294967295,c=c<<15|c>>>17,c=(65535&c)*s+(((c>>>16)*s&65535)<<16)&4294967295,o^=c,o=o<<13|o>>>19,a=5*(65535&o)+((5*(o>>>16)&65535)<<16)&4294967295,o=27492+(65535&a)+((58964+(a>>>16)&65535)<<16);switch(c=0,n){case 3:c^=(255&e[f+2])<<16;case 2:c^=(255&e[f+1])<<8;case 1:c^=255&e[f],c=(65535&c)*u+(((c>>>16)*u&65535)<<16)&4294967295,c=c<<15|c>>>17,c=(65535&c)*s+(((c>>>16)*s&65535)<<16)&4294967295,o^=c}return o^=e.length,o^=o>>>16,o=2246822507*(65535&o)+((2246822507*(o>>>16)&65535)<<16)&4294967295,o^=o>>>13,o=3266489909*(65535&o)+((3266489909*(o>>>16)&65535)<<16)&4294967295,o^=o>>>16,o>>>0}const n=r;n.v2=function(e,r){"string"==typeof e&&(e=t(e));let n,i=e.length,o=r^i,a=0;for(;i>=4;)n=255&e[a]|(255&e[++a])<<8|(255&e[++a])<<16|(255&e[++a])<<24,n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16),n^=n>>>24,n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16),o=1540483477*(65535&o)+((1540483477*(o>>>16)&65535)<<16)^n,i-=4,++a;switch(i){case 3:o^=(255&e[a+2])<<16;case 2:o^=(255&e[a+1])<<8;case 1:o^=255&e[a],o=1540483477*(65535&o)+((1540483477*(o>>>16)&65535)<<16)}return o^=o>>>13,o=1540483477*(65535&o)+((1540483477*(o>>>16)&65535)<<16),o^=o>>>15,o>>>0},n.v3=r,e.exports=n}()},725:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getBucketedNumber=t.MAX_BUCKETED_NUMBER=void 0;var n=r(77),i=Math.pow(2,32);t.MAX_BUCKETED_NUMBER=1e5,t.getBucketedNumber=function(e){var r=n.v3(e,1)/i;return Math.floor(r*t.MAX_BUCKETED_NUMBER)}},352:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FeaturevisorSDK=t.getValueByType=void 0;var n=r(913),i=r(522),o=r(725);function a(e,t){if(void 0!==e)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}}t.getValueByType=a;var u=function(){function e(e){e.onActivation&&(this.onActivation=e.onActivation),e.configureBucketValue&&(this.configureBucketValue=e.configureBucketValue);try{this.datafileReader=new n.DatafileReader("string"==typeof e.datafile?JSON.parse(e.datafile):e.datafile)}catch(e){console.error("Featurevisor could not parse the datafile"),console.error(e)}}return e.prototype.getFeature=function(e){return"string"==typeof e?this.datafileReader.getFeature(e):e},e.prototype.getBucketKey=function(e,t){var r=e.key,n="string"==typeof e.bucketBy?e.bucketBy:e.bucketBy.join("_");return"".concat(n,"_").concat(r)},e.prototype.getBucketValue=function(e,t){var r=this.getBucketKey(e,t),n=(0,o.getBucketedNumber)(r);return this.configureBucketValue?this.configureBucketValue(e,t,n):n},e.prototype.getVariation=function(e,t){void 0===t&&(t={});try{var r=this.getFeature(e);if(!r)return;var n=(0,i.getForcedVariation)(r,t,this.datafileReader);if(n)return n.value;var o=this.getBucketValue(r,t),a=(0,i.getBucketedVariation)(r,t,o,this.datafileReader);if(!a)return;return a.value}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.getVariationBoolean=function(e,t){return void 0===t&&(t={}),a(this.getVariation(e,t),"boolean")},e.prototype.getVariationString=function(e,t){return void 0===t&&(t={}),a(this.getVariation(e,t),"string")},e.prototype.getVariationInteger=function(e,t){return void 0===t&&(t={}),a(this.getVariation(e,t),"integer")},e.prototype.getVariationDouble=function(e,t){return void 0===t&&(t={}),a(this.getVariation(e,t),"double")},e.prototype.activate=function(e,t){void 0===t&&(t={});try{var r=this.getVariation(e,t);if(!r)return;if(this.onActivation){var n={};this.datafileReader.getAllAttributes().filter((function(e){return!0===e.capture})).forEach((function(e){void 0!==t[e.key]&&(n[e.key]=t[e.key])})),this.onActivation(e,r,t,n)}return r}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.activateBoolean=function(e,t){return void 0===t&&(t={}),a(this.activate(e,t),"boolean")},e.prototype.activateString=function(e,t){return void 0===t&&(t={}),a(this.activate(e,t),"string")},e.prototype.activateInteger=function(e,t){return void 0===t&&(t={}),a(this.activate(e,t),"integer")},e.prototype.activateDouble=function(e,t){return void 0===t&&(t={}),a(this.activate(e,t),"double")},e.prototype.getVariable=function(e,t,r){void 0===r&&(r={});try{var n=this.getFeature(e);if(!n)return;var o=(0,i.getForcedVariableValue)(n,t,r,this.datafileReader);if(void 0!==o)return o;var a=this.getBucketValue(n,r);return(0,i.getBucketedVariableValue)(n,t,r,a,this.datafileReader)}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.getVariableBoolean=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"boolean")},e.prototype.getVariableString=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"string")},e.prototype.getVariableInteger=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"integer")},e.prototype.getVariableDouble=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"double")},e.prototype.getVariableArray=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"array")},e.prototype.getVariableObject=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"object")},e}();t.FeaturevisorSDK=u},243:(e,t)=>{"use strict";function r(e,t){var r=e.attribute,n=e.operator,i=e.value;if("equals"===n)return t[r]===i;if("notEquals"===n)return t[r]!==i;if("string"==typeof t[r]&&Array.isArray(i)){var o=t[r];if("in"===n)return-1!==i.indexOf(o);if("notIn"===n)return-1===i.indexOf(o)}else if("string"==typeof t[r]&&"string"==typeof i){if(o=t[r],"contains"===n)return-1!==o.indexOf(i);if("notContains"===n)return-1===o.indexOf(i);if("startsWith"===n)return o.startsWith(i);if("endsWith"===n)return o.endsWith(i)}else if("number"==typeof t[r]&&"number"==typeof i){if(o=t[r],"greaterThan"===n)return o>i;if("greaterThanOrEquals"===n)return o>=i;if("lessThan"===n)return o<i;if("lessThanOrEquals"===n)return o<=i}return!1}Object.defineProperty(t,"__esModule",{value:!0}),t.allConditionsAreMatched=t.conditionIsMatched=void 0,t.conditionIsMatched=r,t.allConditionsAreMatched=function e(t,n){return"attribute"in t?r(t,n):"and"in t&&Array.isArray(t.and)?t.and.every((function(t){return e(t,n)})):"or"in t&&Array.isArray(t.or)?t.or.some((function(t){return e(t,n)})):"not"in t&&Array.isArray(t.not)?t.not.every((function(r){return!1===e({and:t.not},n)})):!!Array.isArray(t)&&t.every((function(t){return e(t,n)}))}},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 n=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=n},522:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getBucketedVariableValue=t.getForcedVariableValue=t.getBucketedVariation=t.getForcedVariation=t.getMatchedAllocation=t.getMatchedTraffic=void 0;var n=r(590),i=r(243);function o(e,t,r,i){return e.find((function(e){return!(r>e.percentage||!(0,n.allGroupSegmentsAreMatched)("string"==typeof e.segments&&"*"!==e.segments?JSON.parse(e.segments):e.segments,t,i))}))}function a(e,t){for(var r=0,n=0,i=e.allocation;n<i.length;n++){var o=i[n];if(t<=(r+=o.percentage))return o}}function u(e,t,r){if(e.force)return e.force.find((function(e){return e.conditions?(0,i.allConditionsAreMatched)(e.conditions,t):!!e.segments&&(0,n.allGroupSegmentsAreMatched)(e.segments,t,r)}))}function s(e,t,r,n){var i=o(e.traffic,t,r,n);if(i){var u=a(i,r);if(u){var s=u.variation,c=e.variations.find((function(e){return e.value===s}));if(c)return c}}}t.getMatchedTraffic=o,t.getMatchedAllocation=a,t.getForcedVariation=function(e,t,r){var n=u(e,t,r);if(n&&n.variation)return e.variations.find((function(e){return e.value===n.variation}))},t.getBucketedVariation=s,t.getForcedVariableValue=function(e,t,r,n){var i=u(e,r,n);if(i&&i.variables)return i.variables[t]},t.getBucketedVariableValue=function(e,t,r,o,a){var u,c=e.variablesSchema;if(c){var f=c.find((function(e){return e.key===t}));if(f){var d=s(e,r,o,a);if(d){var l=null===(u=d.variables)||void 0===u?void 0:u.find((function(e){return e.key===t}));if(!l)return f.defaultValue;if(l.overrides){var v=l.overrides.find((function(e){return e.conditions?(0,i.allConditionsAreMatched)("string"==typeof e.conditions?JSON.parse(e.conditions):e.conditions,r):!!e.segments&&(0,n.allGroupSegmentsAreMatched)("string"==typeof e.segments&&"*"!==e.segments?JSON.parse(e.segments):e.segments,r,a)}));if(v)return v.value}return l.value}}}}},97:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(725),t),i(r(352),t)},590:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.allGroupSegmentsAreMatched=t.segmentIsMatched=void 0;var n=r(243);function i(e,t){return(0,n.allConditionsAreMatched)(e.conditions,t)}t.segmentIsMatched=i,t.allGroupSegmentsAreMatched=function e(t,r,n){if("*"===t)return!0;if("string"==typeof t){var o=n.getSegment(t);return!!o&&i(o,r)}if("object"==typeof t){if("and"in t&&Array.isArray(t.and))return t.and.every((function(t){return e(t,r,n)}));if("or"in t&&Array.isArray(t.or))return t.or.some((function(t){return e(t,r,n)}));if("not"in t&&Array.isArray(t.not))return t.not.every((function(t){return!1===e(t,r,n)}))}return!!Array.isArray(t)&&t.every((function(t){return e(t,r,n)}))}}},t={},function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}(97);var e,t})); | ||
!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,(()=>{return e={77:e=>{!function(){const t=e=>(new TextEncoder).encode(e);function r(e,r){let i,n,a,o,u,c,s,f;for("string"==typeof e&&(e=t(e)),i=3&e.length,n=e.length-i,a=r,u=3432918353,c=461845907,f=0;f<n;)s=255&e[f]|(255&e[++f])<<8|(255&e[++f])<<16|(255&e[++f])<<24,++f,s=(65535&s)*u+(((s>>>16)*u&65535)<<16)&4294967295,s=s<<15|s>>>17,s=(65535&s)*c+(((s>>>16)*c&65535)<<16)&4294967295,a^=s,a=a<<13|a>>>19,o=5*(65535&a)+((5*(a>>>16)&65535)<<16)&4294967295,a=27492+(65535&o)+((58964+(o>>>16)&65535)<<16);switch(s=0,i){case 3:s^=(255&e[f+2])<<16;case 2:s^=(255&e[f+1])<<8;case 1:s^=255&e[f],s=(65535&s)*u+(((s>>>16)*u&65535)<<16)&4294967295,s=s<<15|s>>>17,s=(65535&s)*c+(((s>>>16)*c&65535)<<16)&4294967295,a^=s}return a^=e.length,a^=a>>>16,a=2246822507*(65535&a)+((2246822507*(a>>>16)&65535)<<16)&4294967295,a^=a>>>13,a=3266489909*(65535&a)+((3266489909*(a>>>16)&65535)<<16)&4294967295,a^=a>>>16,a>>>0}const i=r;i.v2=function(e,r){"string"==typeof e&&(e=t(e));let i,n=e.length,a=r^n,o=0;for(;n>=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),a=1540483477*(65535&a)+((1540483477*(a>>>16)&65535)<<16)^i,n-=4,++o;switch(n){case 3:a^=(255&e[o+2])<<16;case 2:a^=(255&e[o+1])<<8;case 1:a^=255&e[o],a=1540483477*(65535&a)+((1540483477*(a>>>16)&65535)<<16)}return a^=a>>>13,a=1540483477*(65535&a)+((1540483477*(a>>>16)&65535)<<16),a^=a>>>15,a>>>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),n=Math.pow(2,32);t.MAX_BUCKETED_NUMBER=1e5,t.getBucketedNumber=function(e){var r=i.v3(e,1)/n;return Math.floor(r*t.MAX_BUCKETED_NUMBER)}},352:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FeaturevisorSDK=t.getValueByType=void 0;var i=r(913),n=r(522),a=r(725);function o(e,t){if(void 0!==e)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}}t.getValueByType=o;var u=function(){function e(e){e.onActivation&&(this.onActivation=e.onActivation),e.configureBucketValue&&(this.configureBucketValue=e.configureBucketValue),this.setDatafile(e.datafile)}return e.prototype.setDatafile=function(e){try{this.datafileReader=new i.DatafileReader("string"==typeof e?JSON.parse(e):e)}catch(e){console.error("Featurevisor could not parse the datafile"),console.error(e)}},e.prototype.getFeature=function(e){return"string"==typeof e?this.datafileReader.getFeature(e):e},e.prototype.getBucketKey=function(e,t){var r=e.key,i="string"==typeof e.bucketBy?e.bucketBy:e.bucketBy.join("_");return"".concat(i,"_").concat(r)},e.prototype.getBucketValue=function(e,t){var r=this.getBucketKey(e,t),i=(0,a.getBucketedNumber)(r);return this.configureBucketValue?this.configureBucketValue(e,t,i):i},e.prototype.getVariation=function(e,t){void 0===t&&(t={});try{var r=this.getFeature(e);if(!r)return;var i=(0,n.getForcedVariation)(r,t,this.datafileReader);if(i)return i.value;var a=this.getBucketValue(r,t),o=(0,n.getBucketedVariation)(r,t,a,this.datafileReader);if(!o)return;return o.value}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.getVariationBoolean=function(e,t){return void 0===t&&(t={}),o(this.getVariation(e,t),"boolean")},e.prototype.getVariationString=function(e,t){return void 0===t&&(t={}),o(this.getVariation(e,t),"string")},e.prototype.getVariationInteger=function(e,t){return void 0===t&&(t={}),o(this.getVariation(e,t),"integer")},e.prototype.getVariationDouble=function(e,t){return void 0===t&&(t={}),o(this.getVariation(e,t),"double")},e.prototype.activate=function(e,t){void 0===t&&(t={});try{var r=this.getVariation(e,t);if(!r)return;if(this.onActivation){var i={};this.datafileReader.getAllAttributes().filter((function(e){return!0===e.capture})).forEach((function(e){void 0!==t[e.key]&&(i[e.key]=t[e.key])})),this.onActivation(e,r,t,i)}return r}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.activateBoolean=function(e,t){return void 0===t&&(t={}),o(this.activate(e,t),"boolean")},e.prototype.activateString=function(e,t){return void 0===t&&(t={}),o(this.activate(e,t),"string")},e.prototype.activateInteger=function(e,t){return void 0===t&&(t={}),o(this.activate(e,t),"integer")},e.prototype.activateDouble=function(e,t){return void 0===t&&(t={}),o(this.activate(e,t),"double")},e.prototype.getVariable=function(e,t,r){void 0===r&&(r={});try{var i=this.getFeature(e);if(!i)return;var a=(0,n.getForcedVariableValue)(i,t,r,this.datafileReader);if(void 0!==a)return a;var o=this.getBucketValue(i,r);return(0,n.getBucketedVariableValue)(i,t,r,o,this.datafileReader)}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.getVariableBoolean=function(e,t,r){return void 0===r&&(r={}),o(this.getVariable(e,t,r),"boolean")},e.prototype.getVariableString=function(e,t,r){return void 0===r&&(r={}),o(this.getVariable(e,t,r),"string")},e.prototype.getVariableInteger=function(e,t,r){return void 0===r&&(r={}),o(this.getVariable(e,t,r),"integer")},e.prototype.getVariableDouble=function(e,t,r){return void 0===r&&(r={}),o(this.getVariable(e,t,r),"double")},e.prototype.getVariableArray=function(e,t,r){return void 0===r&&(r={}),o(this.getVariable(e,t,r),"array")},e.prototype.getVariableObject=function(e,t,r){return void 0===r&&(r={}),o(this.getVariable(e,t,r),"object")},e}();t.FeaturevisorSDK=u},243:(e,t)=>{"use strict";function r(e,t){var r=e.attribute,i=e.operator,n=e.value;if("equals"===i)return t[r]===n;if("notEquals"===i)return t[r]!==n;if("string"==typeof t[r]&&Array.isArray(n)){var a=t[r];if("in"===i)return-1!==n.indexOf(a);if("notIn"===i)return-1===n.indexOf(a)}else if("string"==typeof t[r]&&"string"==typeof n){if(a=t[r],"contains"===i)return-1!==a.indexOf(n);if("notContains"===i)return-1===a.indexOf(n);if("startsWith"===i)return a.startsWith(n);if("endsWith"===i)return a.endsWith(n)}else if("number"==typeof t[r]&&"number"==typeof n){if(a=t[r],"greaterThan"===i)return a>n;if("greaterThanOrEquals"===i)return a>=n;if("lessThan"===i)return a<n;if("lessThanOrEquals"===i)return a<=n}return!1}Object.defineProperty(t,"__esModule",{value:!0}),t.allConditionsAreMatched=t.conditionIsMatched=void 0,t.conditionIsMatched=r,t.allConditionsAreMatched=function e(t,i){return"attribute"in t?r(t,i):"and"in t&&Array.isArray(t.and)?t.and.every((function(t){return e(t,i)})):"or"in t&&Array.isArray(t.or)?t.or.some((function(t){return e(t,i)})):"not"in t&&Array.isArray(t.not)?t.not.every((function(r){return!1===e({and:t.not},i)})):!!Array.isArray(t)&&t.every((function(t){return e(t,i)}))}},292:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createInstance=void 0;var i=r(352);function n(e,t){return{getVariation:e.getVariation.bind(e),getVariationBoolean:e.getVariationBoolean.bind(e),getVariationInteger:e.getVariationInteger.bind(e),getVariationDouble:e.getVariationDouble.bind(e),getVariationString:e.getVariationString.bind(e),activate:e.activate,activateBoolean:e.activateBoolean.bind(e),activateInteger:e.activateInteger.bind(e),activateDouble:e.activateDouble.bind(e),activateString:e.activateString.bind(e),getVariable:e.getVariable.bind(e),getVariableBoolean:e.getVariableBoolean.bind(e),getVariableInteger:e.getVariableInteger.bind(e),getVariableDouble:e.getVariableDouble.bind(e),getVariableString:e.getVariableString.bind(e),getVariableArray:e.getVariableArray.bind(e),getVariableObject:e.getVariableObject.bind(e)}}var a={schemaVersion:"1",revision:"unknown",attributes:[],segments:[],features:[]};t.createInstance=function(e){if(!e.datafile&&!e.datafileUrl)throw new Error("Featurevisor SDK instance cannot be created without `datafile` or `datafileUrl` option");if(e.datafile){var t=new i.FeaturevisorSDK({datafile:e.datafile,onActivation:e.onActivation,configureBucketValue:e.configureBucketValue});if("function"==typeof e.onReady){var r=e.onReady;setTimeout((function(){r()}),0)}return n(t)}var o=new i.FeaturevisorSDK({datafile:a,onActivation:e.onActivation,configureBucketValue:e.configureBucketValue});return e.datafileUrl&&function(e,t){return t.handleDatafileFetch?t.handleDatafileFetch(e):fetch(e).then((function(e){return e.json()}))}(e.datafileUrl,e).then((function(t){o.setDatafile(t),"function"==typeof e.onReady&&e.onReady()})).catch((function(e){console.error("Featurevisor failed to fetch datafile:"),console.error(e)})),n(o)}},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},522:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getBucketedVariableValue=t.getForcedVariableValue=t.getBucketedVariation=t.getForcedVariation=t.getMatchedAllocation=t.getMatchedTraffic=void 0;var i=r(590),n=r(243);function a(e,t,r,n){return e.find((function(e){return!(r>e.percentage||!(0,i.allGroupSegmentsAreMatched)("string"==typeof e.segments&&"*"!==e.segments?JSON.parse(e.segments):e.segments,t,n))}))}function o(e,t){for(var r=0,i=0,n=e.allocation;i<n.length;i++){var a=n[i];if(t<=(r+=a.percentage))return a}}function u(e,t,r){if(e.force)return e.force.find((function(e){return e.conditions?(0,n.allConditionsAreMatched)(e.conditions,t):!!e.segments&&(0,i.allGroupSegmentsAreMatched)(e.segments,t,r)}))}function c(e,t,r,i){var n=a(e.traffic,t,r,i);if(n){var u=o(n,r);if(u){var c=u.variation,s=e.variations.find((function(e){return e.value===c}));if(s)return s}}}t.getMatchedTraffic=a,t.getMatchedAllocation=o,t.getForcedVariation=function(e,t,r){var i=u(e,t,r);if(i&&i.variation)return e.variations.find((function(e){return e.value===i.variation}))},t.getBucketedVariation=c,t.getForcedVariableValue=function(e,t,r,i){var n=u(e,r,i);if(n&&n.variables)return n.variables[t]},t.getBucketedVariableValue=function(e,t,r,a,o){var u,s=e.variablesSchema;if(s){var f=s.find((function(e){return e.key===t}));if(f){var l=c(e,r,a,o);if(l){var d=null===(u=l.variables)||void 0===u?void 0:u.find((function(e){return e.key===t}));if(!d)return f.defaultValue;if(d.overrides){var g=d.overrides.find((function(e){return e.conditions?(0,n.allConditionsAreMatched)("string"==typeof e.conditions?JSON.parse(e.conditions):e.conditions,r):!!e.segments&&(0,i.allGroupSegmentsAreMatched)("string"==typeof e.segments&&"*"!==e.segments?JSON.parse(e.segments):e.segments,r,o)}));if(g)return g.value}return d.value}}}}},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 n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,n)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=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}),n(r(725),t),n(r(352),t),n(r(292),t)},590:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.allGroupSegmentsAreMatched=t.segmentIsMatched=void 0;var i=r(243);function n(e,t){return(0,i.allConditionsAreMatched)(e.conditions,t)}t.segmentIsMatched=n,t.allGroupSegmentsAreMatched=function e(t,r,i){if("*"===t)return!0;if("string"==typeof t){var a=i.getSegment(t);return!!a&&n(a,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 n=t[i];if(void 0!==n)return n.exports;var a=t[i]={exports:{}};return e[i].call(a.exports,a,a.exports,r),a.exports}(97);var e,t})); | ||
//# sourceMappingURL=index.js.map |
@@ -17,2 +17,3 @@ import { Attributes, VariationValue, VariableValue, Feature, DatafileContent, BucketValue, FeatureKey } from "@featurevisor/types"; | ||
constructor(options: SdkOptions); | ||
setDatafile(datafile: DatafileContent | string): void; | ||
private getFeature; | ||
@@ -19,0 +20,0 @@ /** |
@@ -25,2 +25,4 @@ import { DatafileReader } from "./datafileReader"; | ||
} | ||
// @TODO: change it to FeaturevisorEngine in next breaking semver | ||
// @TODO: move activate*() methods to FeaturevisorInstance in next breaking semver | ||
var FeaturevisorSDK = /** @class */ (function () { | ||
@@ -34,4 +36,7 @@ function FeaturevisorSDK(options) { | ||
} | ||
this.setDatafile(options.datafile); | ||
} | ||
FeaturevisorSDK.prototype.setDatafile = function (datafile) { | ||
try { | ||
this.datafileReader = new DatafileReader(typeof options.datafile === "string" ? JSON.parse(options.datafile) : options.datafile); | ||
this.datafileReader = new DatafileReader(typeof datafile === "string" ? JSON.parse(datafile) : datafile); | ||
} | ||
@@ -42,3 +47,3 @@ catch (e) { | ||
} | ||
} | ||
}; | ||
FeaturevisorSDK.prototype.getFeature = function (featureKey) { | ||
@@ -45,0 +50,0 @@ return typeof featureKey === "string" |
export * from "./bucket"; | ||
export * from "./client"; | ||
export * from "./createInstance"; |
export * from "./bucket"; | ||
export * from "./client"; | ||
export * from "./createInstance"; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@featurevisor/sdk", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Featurevisor SDK for Node.js and the browser", | ||
@@ -45,6 +45,6 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@featurevisor/types": "^0.3.0", | ||
"@featurevisor/types": "^0.4.0", | ||
"murmurhash": "^2.0.1" | ||
}, | ||
"gitHead": "fae6cbf61f8b2f7e89b4faf660f63b37676bab29" | ||
"gitHead": "ee0a42f0f544e3bfc209e85f110d04d95c53a8c1" | ||
} |
@@ -18,7 +18,7 @@ # @featurevisor/sdk | ||
```js | ||
import { FeaturevisorSDK } from "@featurevisor/sdk"; | ||
import { createInstance } from "@featurevisor/sdk"; | ||
const datafileContent = fetch(datafileURL).then((res) => res.json()); | ||
const sdk = new FeaturevisorSDK({ | ||
const sdk = createInstance({ | ||
// required | ||
@@ -25,0 +25,0 @@ datafile: datafileContent, |
@@ -10,3 +10,2 @@ import { | ||
FeatureKey, | ||
VariableObjectValue, | ||
} from "@featurevisor/types"; | ||
@@ -30,5 +29,6 @@ import { DatafileReader } from "./datafileReader"; | ||
export type ConfigureBucketValue = (feature, attributes, bucketValue: BucketValue) => BucketValue; | ||
export interface SdkOptions { | ||
datafile: DatafileContent | string; | ||
onActivation?: ActivationCallback; | ||
onActivation?: ActivationCallback; // @TODO: move it to FeaturevisorInstance in next breaking semver | ||
configureBucketValue?: ConfigureBucketValue; | ||
@@ -64,2 +64,4 @@ } | ||
// @TODO: change it to FeaturevisorEngine in next breaking semver | ||
// @TODO: move activate*() methods to FeaturevisorInstance in next breaking semver | ||
export class FeaturevisorSDK { | ||
@@ -79,5 +81,9 @@ private onActivation?: ActivationCallback; | ||
this.setDatafile(options.datafile); | ||
} | ||
setDatafile(datafile: DatafileContent | string) { | ||
try { | ||
this.datafileReader = new DatafileReader( | ||
typeof options.datafile === "string" ? JSON.parse(options.datafile) : options.datafile, | ||
typeof datafile === "string" ? JSON.parse(datafile) : datafile, | ||
); | ||
@@ -84,0 +90,0 @@ } catch (e) { |
export * from "./bucket"; | ||
export * from "./client"; | ||
export * from "./createInstance"; |
{ | ||
"extends": "../../tsconfig.cjs.json", | ||
"compilerOptions": { | ||
"outDir": "./lib" | ||
"outDir": "./lib", | ||
"lib": ["DOM"] | ||
}, | ||
"include": ["./src/**/*.ts"] | ||
} |
{ | ||
"extends": "../../tsconfig.esm.json", | ||
"compilerOptions": { | ||
"outDir": "./lib" | ||
"outDir": "./lib", | ||
"lib": ["DOM"] | ||
}, | ||
"include": ["./src/**/*.ts"] | ||
} |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
165102
49
2319
2
+ Added@featurevisor/types@0.4.0(transitive)
- Removed@featurevisor/types@0.3.0(transitive)
Updated@featurevisor/types@^0.4.0