@featurevisor/sdk 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/lib/client.d.ts +3 -2
- package/lib/client.js +14 -2
- package/lib/client.js.map +1 -1
- package/lib/feature.d.ts +4 -3
- package/lib/feature.js +17 -15
- package/lib/feature.js.map +1 -1
- package/package.json +3 -3
- package/src/client.ts +25 -4
- package/src/feature.ts +24 -20
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.6.0](https://github.com/fahad19/featurevisor/compare/v0.5.3...v0.6.0) (2023-03-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Introduce new JSON type for variables ([#28](https://github.com/fahad19/featurevisor/issues/28)) ([49ff4cb](https://github.com/fahad19/featurevisor/commit/49ff4cb99f840f29e9ac8fcacfee9a9a961ff776))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [0.5.3](https://github.com/fahad19/featurevisor/compare/v0.5.2...v0.5.3) (2023-03-25)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @featurevisor/sdk
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!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);return o?o.value:r.defaultVariation}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)}))}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=function(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.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,u,c){var s,f=e.variablesSchema;if(f){var l=f.find((function(e){return e.key===t}));if(l){var d=a(e.traffic,r,u,c);if(d){if(d.variables&&void 0!==d.variables[t])return d.variables[t];var g=o(d,u);if(g){var v=g.variation,p=e.variations.find((function(e){return e.value===v}));if(p){var y=null===(s=p.variables)||void 0===s?void 0:s.find((function(e){return e.key===t}));if(!y)return l.defaultValue;if(y.overrides){var b=y.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,c)}));if(b)return b.value}return y.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}));
|
|
1
|
+
!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,s,c,f;for("string"==typeof e&&(e=t(e)),i=3&e.length,n=e.length-i,a=r,u=3432918353,s=461845907,f=0;f<n;)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,a^=c,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(c=0,i){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,a^=c}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);return o?o.value:r.defaultVariation}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=Array.isArray(i.variablesSchema)?i.variablesSchema.find((function(e){return e.key===t})):void 0;if(!a)return;var o=(0,n.getForcedVariableValue)(i,a,r,this.datafileReader);if(void 0!==o)return o;var u=this.getBucketValue(i,r);return(0,n.getBucketedVariableValue)(i,a,r,u,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.prototype.getVariableJSON=function(e,t,r){return void 0===r&&(r={}),o(this.getVariable(e,t,r),"json")},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)}))}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=function(e,t,r,i){var n=a(e.traffic,t,r,i);if(n){var u=o(n,r);if(u){var s=u.variation,c=e.variations.find((function(e){return e.value===s}));if(c)return c}}},t.getForcedVariableValue=function(e,t,r,i){var n=u(e,r,i);if(n&&n.variables){var a=n.variables[t.key];return"string"==typeof a&&"json"===t.type?JSON.parse(a):a}},t.getBucketedVariableValue=function(e,t,r,u,s){var c,f=a(e.traffic,r,u,s);if(f){var l=t.key;if(f.variables&&void 0!==f.variables[l])return f.variables[l];var d=o(f,u);if(d){var g=d.variation,v=e.variations.find((function(e){return e.value===g}));if(v){var p=null===(c=v.variables)||void 0===c?void 0:c.find((function(e){return e.key===l}));if(!p)return"json"===t.type?JSON.parse(t.defaultValue):t.defaultValue;if(p.overrides){var y=p.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,s)}));if(y)return"json"===t.type?JSON.parse(y.value):y.value}return"json"===t.type?JSON.parse(p.value):p.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}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAyB,gBAAID,IAE7BD,EAAsB,gBAAIC,GAC3B,CATD,CASGK,MAAM,KACT,O,WCVC,WACC,MAEMC,EAAgBC,IAAQ,IAAIC,aAAcC,OAAOF,GAiEvD,SAASG,EAAaC,EAAKC,GAGzB,IAAIC,EAAWC,EAAOC,EAAIC,EAAKC,EAASC,EAASC,EAAIC,EASrD,IAXmB,iBAART,IAAkBA,EAAML,EAAaK,IAIhDE,EAAyB,EAAbF,EAAIU,OAChBP,EAAQH,EAAIU,OAASR,EACrBE,EAAKH,EACLK,EAAK,WACLC,EAAK,UACLE,EAAI,EAEGA,EAAIN,GACPK,EACa,IAATR,EAAIS,IACO,IAAXT,IAAMS,KAAc,GACT,IAAXT,IAAMS,KAAc,IACT,IAAXT,IAAMS,KAAc,KACxBA,EAEFD,GAAc,MAALA,GAAeF,KAAUE,IAAO,IAAMF,EAAM,QAAW,IAAQ,WACxEE,EAAMA,GAAM,GAAOA,IAAO,GAC1BA,GAAc,MAALA,GAAeD,KAAUC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AAI,OAAQwH,GAAiB/H,MAAMC,QAAQ8H,EAAcxD,IACvD,OAAOwD,EAAcxD,GAAGC,MAAK,SAACwD,GAC5B,OAAApB,EAA2BoB,EAAc9G,EAAYX,EAArD,IAIJ,GAAI,QAASwH,GAAiB/H,MAAMC,QAAQ8H,EAActD,KACxD,OAAOsD,EAActD,IAAIJ,OACvB,SAAC2D,GACC,OAAyE,IAAzEpB,EAA2BoB,EAAc9G,EAAYX,EAArD,G,CAKR,QAAIP,MAAMC,QAAQ8H,IACTA,EAAc1D,OAAM,SAAC2D,GAC1B,OAAApB,EAA2BoB,EAAc9G,EAAYX,EAArD,GAKN,C,GCtDI0H,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBtI,IAAjBuI,EACH,OAAOA,EAAa9K,QAGrB,IAAIC,EAAS0K,EAAyBE,GAAY,CAGjD7K,QAAS,CAAC,GAOX,OAHA+K,EAAoBF,GAAUG,KAAK/K,EAAOD,QAASC,EAAQA,EAAOD,QAAS4K,GAGpE3K,EAAOD,OACf,CCnB0B4K,CAAoB,I,MDF1CD,C","sources":["webpack://FeaturevisorSDK/webpack/universalModuleDefinition","webpack://FeaturevisorSDK/../../node_modules/murmurhash/murmurhash.js","webpack://FeaturevisorSDK/./src/bucket.ts","webpack://FeaturevisorSDK/./src/client.ts","webpack://FeaturevisorSDK/./src/conditions.ts","webpack://FeaturevisorSDK/./src/createInstance.ts","webpack://FeaturevisorSDK/./src/datafileReader.ts","webpack://FeaturevisorSDK/./src/feature.ts","webpack://FeaturevisorSDK/./src/index.ts","webpack://FeaturevisorSDK/./src/segments.ts","webpack://FeaturevisorSDK/webpack/bootstrap","webpack://FeaturevisorSDK/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"FeaturevisorSDK\"] = factory();\n\telse\n\t\troot[\"FeaturevisorSDK\"] = factory();\n})(this, () => {\nreturn ","(function(){\n const _global = this;\n\n const createBuffer = (val) => new TextEncoder().encode(val)\n\n /**\n * JS Implementation of MurmurHash2\n *\n * @author <a href=\"mailto:gary.court@gmail.com\">Gary Court</a>\n * @see http://github.com/garycourt/murmurhash-js\n * @author <a href=\"mailto:aappleby@gmail.com\">Austin Appleby</a>\n * @see http://sites.google.com/site/murmurhash/\n *\n * @param {Uint8Array | string} str ASCII only\n * @param {number} seed Positive integer only\n * @return {number} 32-bit positive integer hash\n */\n function MurmurHashV2(str, seed) {\n if (typeof str === 'string') str = createBuffer(str);\n let\n l = str.length,\n h = seed ^ l,\n i = 0,\n k;\n\n while (l >= 4) {\n k =\n ((str[i] & 0xff)) |\n ((str[++i] & 0xff) << 8) |\n ((str[++i] & 0xff) << 16) |\n ((str[++i] & 0xff) << 24);\n\n k = (((k & 0xffff) * 0x5bd1e995) + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16));\n k ^= k >>> 24;\n k = (((k & 0xffff) * 0x5bd1e995) + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16));\n\n h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16)) ^ k;\n\n l -= 4;\n ++i;\n }\n\n switch (l) {\n case 3: h ^= (str[i + 2] & 0xff) << 16;\n case 2: h ^= (str[i + 1] & 0xff) << 8;\n case 1: h ^= (str[i] & 0xff);\n h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16));\n }\n\n h ^= h >>> 13;\n h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16));\n h ^= h >>> 15;\n\n return h >>> 0;\n };\n\n /*\n * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)\n *\n * @author <a href=\"mailto:gary.court@gmail.com\">Gary Court</a>\n * @see http://github.com/garycourt/murmurhash-js\n * @author <a href=\"mailto:aappleby@gmail.com\">Austin Appleby</a>\n * @see http://sites.google.com/site/murmurhash/\n *\n * @param {Uint8Array | string} key ASCII only\n * @param {number} seed Positive integer only\n * @return {number} 32-bit positive integer hash\n */\n function MurmurHashV3(key, seed) {\n if (typeof key === 'string') key = createBuffer(key);\n\n let remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i;\n\n remainder = key.length & 3; // key.length % 4\n bytes = key.length - remainder;\n h1 = seed;\n c1 = 0xcc9e2d51;\n c2 = 0x1b873593;\n i = 0;\n\n while (i < bytes) {\n k1 =\n ((key[i] & 0xff)) |\n ((key[++i] & 0xff) << 8) |\n ((key[++i] & 0xff) << 16) |\n ((key[++i] & 0xff) << 24);\n ++i;\n\n k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff;\n k1 = (k1 << 15) | (k1 >>> 17);\n k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff;\n\n h1 ^= k1;\n h1 = (h1 << 13) | (h1 >>> 19);\n h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff;\n h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16));\n }\n\n k1 = 0;\n\n switch (remainder) {\n case 3: k1 ^= (key[i + 2] & 0xff) << 16;\n case 2: k1 ^= (key[i + 1] & 0xff) << 8;\n case 1: k1 ^= (key[i] & 0xff);\n\n k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;\n k1 = (k1 << 15) | (k1 >>> 17);\n k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;\n h1 ^= k1;\n }\n\n h1 ^= key.length;\n\n h1 ^= h1 >>> 16;\n h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;\n h1 ^= h1 >>> 13;\n h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;\n h1 ^= h1 >>> 16;\n\n return h1 >>> 0;\n }\n\n const murmur = MurmurHashV3;\n murmur.v2 = MurmurHashV2;\n murmur.v3 = MurmurHashV3;\n\n if (typeof(module) != 'undefined') {\n module.exports = murmur;\n } else {\n const _previousRoot = _global.murmur;\n murmur.noConflict = function() {\n _global.murmur = _previousRoot;\n return murmur;\n }\n _global.murmur = murmur;\n }\n}());\n","import * as murmurhash from \"murmurhash\";\n\nconst HASH_SEED = 1;\nconst MAX_HASH_VALUE = Math.pow(2, 32);\n\nexport const MAX_BUCKETED_NUMBER = 100000; // 100% * 1000 to include three decimal places in the same integer value\n\nexport function getBucketedNumber(bucketKey: string): number {\n const hashValue = murmurhash.v3(bucketKey, HASH_SEED);\n const ratio = hashValue / MAX_HASH_VALUE;\n\n return Math.floor(ratio * MAX_BUCKETED_NUMBER);\n}\n","import {\n Attributes,\n VariationValue,\n VariableValue,\n Feature,\n DatafileContent,\n BucketKey,\n BucketValue,\n FeatureKey,\n} from \"@featurevisor/types\";\nimport { DatafileReader } from \"./datafileReader\";\nimport {\n getBucketedVariation,\n getBucketedVariableValue,\n getForcedVariation,\n getForcedVariableValue,\n} from \"./feature\";\nimport { getBucketedNumber } from \"./bucket\";\n\nexport type ActivationCallback = (\n featureName: string,\n variation: VariationValue,\n attributes: Attributes,\n captureAttributes: Attributes,\n) => void;\n\nexport type ConfigureBucketValue = (feature, attributes, bucketValue: BucketValue) => BucketValue;\n\nexport interface SdkOptions {\n datafile: DatafileContent | string;\n onActivation?: ActivationCallback; // @TODO: move it to FeaturevisorInstance in next breaking semver\n configureBucketValue?: ConfigureBucketValue;\n}\n\n// union of VariableValue and VariationValue\ntype FieldType = \"string\" | \"integer\" | \"double\" | \"boolean\" | \"array\" | \"object\";\ntype ValueType = VariableValue;\n\nexport function getValueByType(value: ValueType, fieldType: FieldType): ValueType {\n if (value === undefined) {\n return undefined;\n }\n\n switch (fieldType) {\n case \"string\":\n return typeof value === \"string\" ? value : undefined;\n case \"integer\":\n return parseInt(value as string, 10);\n case \"double\":\n return parseFloat(value as string);\n case \"boolean\":\n return value === true;\n case \"array\":\n return Array.isArray(value) ? value : undefined;\n case \"object\":\n return typeof value === \"object\" ? value : undefined;\n default:\n return value;\n }\n}\n\n// @TODO: change it to FeaturevisorEngine in next breaking semver\n// @TODO: move activate*() methods to FeaturevisorInstance in next breaking semver\nexport class FeaturevisorSDK {\n private onActivation?: ActivationCallback;\n private datafileReader: DatafileReader;\n private configureBucketValue?: ConfigureBucketValue;\n\n constructor(options: SdkOptions) {\n if (options.onActivation) {\n this.onActivation = options.onActivation;\n }\n\n if (options.configureBucketValue) {\n this.configureBucketValue = options.configureBucketValue;\n }\n\n this.setDatafile(options.datafile);\n }\n\n setDatafile(datafile: DatafileContent | string) {\n try {\n this.datafileReader = new DatafileReader(\n typeof datafile === \"string\" ? JSON.parse(datafile) : datafile,\n );\n } catch (e) {\n console.error(`Featurevisor could not parse the datafile`);\n console.error(e);\n }\n }\n\n private getFeature(featureKey: string | Feature): Feature | undefined {\n return typeof featureKey === \"string\"\n ? this.datafileReader.getFeature(featureKey) // only key provided\n : featureKey; // full feature provided\n }\n\n /**\n * Bucketing\n */\n\n private getBucketKey(feature: Feature, attributes: Attributes): BucketKey {\n const featureKey = feature.key;\n\n const prefix =\n typeof feature.bucketBy === \"string\" ? feature.bucketBy : feature.bucketBy.join(\"_\");\n\n return `${prefix}_${featureKey}`;\n }\n\n private getBucketValue(feature: Feature, attributes: Attributes): BucketValue {\n const bucketKey = this.getBucketKey(feature, attributes);\n\n const value = getBucketedNumber(bucketKey);\n\n if (this.configureBucketValue) {\n return this.configureBucketValue(feature, attributes, value);\n }\n\n return value;\n }\n\n /**\n * Variation\n */\n\n getVariation(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): VariationValue | undefined {\n try {\n const feature = this.getFeature(featureKey);\n\n if (!feature) {\n return undefined;\n }\n\n const forcedVariation = getForcedVariation(feature, attributes, this.datafileReader);\n\n if (forcedVariation) {\n return forcedVariation.value;\n }\n\n const bucketValue = this.getBucketValue(feature, attributes);\n\n const variation = getBucketedVariation(feature, attributes, bucketValue, this.datafileReader);\n\n if (!variation) {\n return feature.defaultVariation;\n }\n\n return variation.value;\n } catch (e) {\n console.error(\"[Featurevisor]\", e);\n\n return undefined;\n }\n }\n\n getVariationBoolean(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): boolean | undefined {\n const variationValue = this.getVariation(featureKey, attributes);\n\n return getValueByType(variationValue, \"boolean\") as boolean | undefined;\n }\n\n getVariationString(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): string | undefined {\n const variationValue = this.getVariation(featureKey, attributes);\n\n return getValueByType(variationValue, \"string\") as string | undefined;\n }\n\n getVariationInteger(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): number | undefined {\n const variationValue = this.getVariation(featureKey, attributes);\n\n return getValueByType(variationValue, \"integer\") as number | undefined;\n }\n\n getVariationDouble(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): number | undefined {\n const variationValue = this.getVariation(featureKey, attributes);\n\n return getValueByType(variationValue, \"double\") as number | undefined;\n }\n\n /**\n * Activate\n */\n activate(featureKey: FeatureKey, attributes: Attributes = {}): VariationValue | undefined {\n try {\n const variationValue = this.getVariation(featureKey, attributes);\n\n if (!variationValue) {\n return undefined;\n }\n\n if (this.onActivation) {\n const captureAttributes: Attributes = {};\n\n const attributesForCapturing = this.datafileReader\n .getAllAttributes()\n .filter((a) => a.capture === true);\n\n attributesForCapturing.forEach((a) => {\n if (typeof attributes[a.key] !== \"undefined\") {\n captureAttributes[a.key] = attributes[a.key];\n }\n });\n\n this.onActivation(featureKey, variationValue, attributes, captureAttributes);\n }\n\n return variationValue;\n } catch (e) {\n console.error(\"[Featurevisor]\", e);\n\n return undefined;\n }\n }\n\n activateBoolean(featureKey: FeatureKey, attributes: Attributes = {}): boolean | undefined {\n const variationValue = this.activate(featureKey, attributes);\n\n return getValueByType(variationValue, \"boolean\") as boolean | undefined;\n }\n\n activateString(featureKey: FeatureKey, attributes: Attributes = {}): string | undefined {\n const variationValue = this.activate(featureKey, attributes);\n\n return getValueByType(variationValue, \"string\") as string | undefined;\n }\n\n activateInteger(featureKey: FeatureKey, attributes: Attributes = {}): number | undefined {\n const variationValue = this.activate(featureKey, attributes);\n\n return getValueByType(variationValue, \"integer\") as number | undefined;\n }\n\n activateDouble(featureKey: FeatureKey, attributes: Attributes = {}): number | undefined {\n const variationValue = this.activate(featureKey, attributes);\n\n return getValueByType(variationValue, \"double\") as number | undefined;\n }\n\n /**\n * Variable\n */\n\n getVariable(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): VariableValue | undefined {\n try {\n const feature = this.getFeature(featureKey);\n\n if (!feature) {\n return undefined;\n }\n\n const forcedVariableValue = getForcedVariableValue(\n feature,\n variableKey,\n attributes,\n this.datafileReader,\n );\n\n if (typeof forcedVariableValue !== \"undefined\") {\n return forcedVariableValue;\n }\n\n const bucketValue = this.getBucketValue(feature, attributes);\n\n return getBucketedVariableValue(\n feature,\n variableKey,\n attributes,\n bucketValue,\n this.datafileReader,\n );\n } catch (e) {\n console.error(\"[Featurevisor]\", e);\n\n return undefined;\n }\n }\n\n getVariableBoolean(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): boolean | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"boolean\") as boolean | undefined;\n }\n\n getVariableString(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): string | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"string\") as string | undefined;\n }\n\n getVariableInteger(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): number | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"integer\") as number | undefined;\n }\n\n getVariableDouble(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): number | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"double\") as number | undefined;\n }\n\n getVariableArray(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): string[] | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"array\") as string[] | undefined;\n }\n\n getVariableObject<T>(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): T | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"object\") as T | undefined;\n }\n}\n","import { Attributes, Condition, PlainCondition } from \"@featurevisor/types\";\n\nexport function conditionIsMatched(condition: PlainCondition, attributes: Attributes): boolean {\n const { attribute, operator, value } = condition;\n\n if (operator === \"equals\") {\n return attributes[attribute] === value;\n } else if (operator === \"notEquals\") {\n return attributes[attribute] !== value;\n } else if (typeof attributes[attribute] === \"string\" && Array.isArray(value)) {\n // array\n const valueInAttributes = attributes[attribute] as string;\n\n if (operator === \"in\") {\n return value.indexOf(valueInAttributes) !== -1;\n } else if (operator === \"notIn\") {\n return value.indexOf(valueInAttributes) === -1;\n }\n } else if (typeof attributes[attribute] === \"string\" && typeof value === \"string\") {\n // string\n const valueInAttributes = attributes[attribute] as string;\n\n if (operator === \"contains\") {\n return valueInAttributes.indexOf(value) !== -1;\n } else if (operator === \"notContains\") {\n return valueInAttributes.indexOf(value) === -1;\n } else if (operator === \"startsWith\") {\n return valueInAttributes.startsWith(value);\n } else if (operator === \"endsWith\") {\n return valueInAttributes.endsWith(value);\n }\n } else if (typeof attributes[attribute] === \"number\" && typeof value === \"number\") {\n // numeric\n const valueInAttributes = attributes[attribute] as number;\n\n if (operator === \"greaterThan\") {\n return valueInAttributes > value;\n } else if (operator === \"greaterThanOrEquals\") {\n return valueInAttributes >= value;\n } else if (operator === \"lessThan\") {\n return valueInAttributes < value;\n } else if (operator === \"lessThanOrEquals\") {\n return valueInAttributes <= value;\n }\n }\n\n return false;\n}\n\nexport function allConditionsAreMatched(\n conditions: Condition[] | Condition,\n attributes: Attributes,\n): boolean {\n if (\"attribute\" in conditions) {\n return conditionIsMatched(conditions, attributes);\n }\n\n if (\"and\" in conditions && Array.isArray(conditions.and)) {\n return conditions.and.every((c) => allConditionsAreMatched(c, attributes));\n }\n\n if (\"or\" in conditions && Array.isArray(conditions.or)) {\n return conditions.or.some((c) => allConditionsAreMatched(c, attributes));\n }\n\n if (\"not\" in conditions && Array.isArray(conditions.not)) {\n return conditions.not.every(\n (c) =>\n allConditionsAreMatched(\n {\n and: conditions.not,\n },\n attributes,\n ) === false,\n );\n }\n\n if (Array.isArray(conditions)) {\n return conditions.every((c) => allConditionsAreMatched(c, attributes));\n }\n\n return false;\n}\n","import { DatafileContent } from \"@featurevisor/types\";\nimport { FeaturevisorSDK, ConfigureBucketValue, ActivationCallback } from \"./client\";\n\nexport type ReadyCallback = () => void;\n\nexport interface InstanceOptions {\n // from SdkOptions\n datafile?: DatafileContent | string; // optional here, but not in SdkOptions\n onActivation?: ActivationCallback;\n configureBucketValue?: ConfigureBucketValue;\n\n // additions\n datafileUrl?: string;\n onReady?: ReadyCallback;\n handleDatafileFetch?: (datafileUrl: string) => Promise<DatafileContent>;\n}\n\n// @TODO: consider renaming it to FeaturevisorSDK in next breaking semver\nexport interface FeaturevisorInstance {\n /**\n * From FeaturevisorSDK\n */\n\n // variation\n getVariation: FeaturevisorSDK[\"getVariation\"];\n getVariationBoolean: FeaturevisorSDK[\"getVariationBoolean\"];\n getVariationInteger: FeaturevisorSDK[\"getVariationInteger\"];\n getVariationDouble: FeaturevisorSDK[\"getVariationDouble\"];\n getVariationString: FeaturevisorSDK[\"getVariationString\"];\n\n // activate\n activate: FeaturevisorSDK[\"activate\"];\n activateBoolean: FeaturevisorSDK[\"activateBoolean\"];\n activateInteger: FeaturevisorSDK[\"activateInteger\"];\n activateDouble: FeaturevisorSDK[\"activateDouble\"];\n activateString: FeaturevisorSDK[\"activateString\"];\n\n // variable\n getVariable: FeaturevisorSDK[\"getVariable\"];\n getVariableBoolean: FeaturevisorSDK[\"getVariableBoolean\"];\n getVariableInteger: FeaturevisorSDK[\"getVariableInteger\"];\n getVariableDouble: FeaturevisorSDK[\"getVariableDouble\"];\n getVariableString: FeaturevisorSDK[\"getVariableString\"];\n getVariableArray: FeaturevisorSDK[\"getVariableArray\"];\n getVariableObject: FeaturevisorSDK[\"getVariableObject\"];\n\n /**\n * Additions\n *\n * @TODO\n */\n // start: () => void;\n // stop: () => void;\n // refresh: () => void;\n}\n\nfunction getInstanceFromSdk(sdk: FeaturevisorSDK, options: InstanceOptions): FeaturevisorInstance {\n return {\n // variation\n getVariation: sdk.getVariation.bind(sdk),\n getVariationBoolean: sdk.getVariationBoolean.bind(sdk),\n getVariationInteger: sdk.getVariationInteger.bind(sdk),\n getVariationDouble: sdk.getVariationDouble.bind(sdk),\n getVariationString: sdk.getVariationString.bind(sdk),\n\n // activate\n activate: sdk.activate,\n activateBoolean: sdk.activateBoolean.bind(sdk),\n activateInteger: sdk.activateInteger.bind(sdk),\n activateDouble: sdk.activateDouble.bind(sdk),\n activateString: sdk.activateString.bind(sdk),\n\n // variable\n getVariable: sdk.getVariable.bind(sdk),\n getVariableBoolean: sdk.getVariableBoolean.bind(sdk),\n getVariableInteger: sdk.getVariableInteger.bind(sdk),\n getVariableDouble: sdk.getVariableDouble.bind(sdk),\n getVariableString: sdk.getVariableString.bind(sdk),\n getVariableArray: sdk.getVariableArray.bind(sdk),\n getVariableObject: sdk.getVariableObject.bind(sdk),\n\n // additions\n // @TODO\n // start: () => {},\n // stop: () => {},\n // refresh: () => {},\n };\n}\n\nconst emptyDatafile: DatafileContent = {\n schemaVersion: \"1\",\n revision: \"unknown\",\n attributes: [],\n segments: [],\n features: [],\n};\n\nfunction fetchDatafileContent(datafileUrl, options: InstanceOptions): Promise<DatafileContent> {\n if (options.handleDatafileFetch) {\n return options.handleDatafileFetch(datafileUrl);\n }\n\n return fetch(datafileUrl).then((res) => res.json());\n}\n\nexport function createInstance(options: InstanceOptions) {\n if (!options.datafile && !options.datafileUrl) {\n throw new Error(\n \"Featurevisor SDK instance cannot be created without `datafile` or `datafileUrl` option\",\n );\n }\n\n // datafile content is already provided\n if (options.datafile) {\n const sdk = new FeaturevisorSDK({\n datafile: options.datafile,\n onActivation: options.onActivation,\n configureBucketValue: options.configureBucketValue,\n });\n\n if (typeof options.onReady === \"function\") {\n const onReady = options.onReady;\n\n setTimeout(function () {\n onReady();\n }, 0);\n }\n\n return getInstanceFromSdk(sdk, options);\n }\n\n // datafile has to be fetched\n const sdk = new FeaturevisorSDK({\n datafile: emptyDatafile,\n onActivation: options.onActivation,\n configureBucketValue: options.configureBucketValue,\n });\n\n if (options.datafileUrl) {\n fetchDatafileContent(options.datafileUrl, options)\n .then((datafile) => {\n sdk.setDatafile(datafile);\n\n if (typeof options.onReady === \"function\") {\n options.onReady();\n }\n })\n .catch((e) => {\n console.error(\"Featurevisor failed to fetch datafile:\");\n console.error(e);\n });\n }\n\n return getInstanceFromSdk(sdk, options);\n}\n","import {\n Feature,\n Segment,\n DatafileContent,\n Attribute,\n AttributeKey,\n SegmentKey,\n FeatureKey,\n} from \"@featurevisor/types\";\n\nexport function parseJsonConditionsIfStringified<T>(record: T, key: string): T {\n if (typeof record[key] === \"string\" && record[key] !== \"*\") {\n try {\n record[key] = JSON.parse(record[key]);\n } catch (e) {\n console.error(\"Error parsing JSON\", e);\n }\n }\n\n return record;\n}\n\nexport class DatafileReader {\n private schemaVersion: string;\n private revision: string;\n private attributes: Attribute[];\n private segments: Segment[];\n private features: Feature[];\n\n constructor(datafileJson: DatafileContent) {\n this.schemaVersion = datafileJson.schemaVersion;\n this.revision = datafileJson.revision;\n this.segments = datafileJson.segments;\n this.attributes = datafileJson.attributes;\n this.features = datafileJson.features;\n }\n\n getRevision(): string {\n return this.revision;\n }\n\n getSchemaVersion(): string {\n return this.schemaVersion;\n }\n\n getAllAttributes(): Attribute[] {\n return this.attributes;\n }\n\n getAttribute(attributeKey: AttributeKey): Attribute | undefined {\n return this.attributes.find((a) => a.key === attributeKey);\n }\n\n getSegment(segmentKey: SegmentKey): Segment | undefined {\n const segment = this.segments.find((s) => s.key === segmentKey);\n\n if (!segment) {\n return undefined;\n }\n\n return parseJsonConditionsIfStringified(segment, \"conditions\");\n }\n\n getFeature(featureKey: FeatureKey): Feature | undefined {\n const feature = this.features.find((s) => s.key === featureKey);\n\n if (!feature) {\n return undefined;\n }\n\n return feature;\n }\n}\n","import {\n Allocation,\n Attributes,\n Traffic,\n Feature,\n Variation,\n VariableKey,\n VariableValue,\n Force,\n} from \"@featurevisor/types\";\nimport { DatafileReader } from \"./datafileReader\";\nimport { allGroupSegmentsAreMatched } from \"./segments\";\nimport { allConditionsAreMatched } from \"./conditions\";\n\nexport function getMatchedTraffic(\n traffic: Traffic[],\n attributes: Attributes,\n bucketValue: number,\n datafileReader: DatafileReader,\n): Traffic | undefined {\n return traffic.find((traffic) => {\n if (bucketValue > traffic.percentage) {\n // out of bucket range\n return false;\n }\n\n if (\n !allGroupSegmentsAreMatched(\n typeof traffic.segments === \"string\" && traffic.segments !== \"*\"\n ? JSON.parse(traffic.segments)\n : traffic.segments,\n attributes,\n datafileReader,\n )\n ) {\n return false;\n }\n\n return true;\n });\n}\n\n// @TODO: make this function better with tests\nexport function getMatchedAllocation(\n matchedTraffic: Traffic,\n bucketValue: number,\n): Allocation | undefined {\n let total = 0;\n\n for (const allocation of matchedTraffic.allocation) {\n total += allocation.percentage;\n\n if (bucketValue <= total) {\n return allocation;\n }\n }\n\n return undefined;\n}\n\nfunction findForceFromFeature(\n feature: Feature,\n attributes: Attributes,\n datafileReader: DatafileReader,\n): Force | undefined {\n if (!feature.force) {\n return undefined;\n }\n\n return feature.force.find((f: Force) => {\n if (f.conditions) {\n return allConditionsAreMatched(f.conditions, attributes);\n }\n\n if (f.segments) {\n return allGroupSegmentsAreMatched(f.segments, attributes, datafileReader);\n }\n\n return false;\n });\n}\n\nexport function getForcedVariation(\n feature: Feature,\n attributes: Attributes,\n datafileReader: DatafileReader,\n): Variation | undefined {\n const force = findForceFromFeature(feature, attributes, datafileReader);\n\n if (!force || !force.variation) {\n return undefined;\n }\n\n return feature.variations.find((v) => v.value === force.variation);\n}\n\nexport function getBucketedVariation(\n feature: Feature,\n attributes: Attributes,\n bucketValue: number,\n datafileReader: DatafileReader,\n): Variation | undefined {\n const matchedTraffic = getMatchedTraffic(\n feature.traffic,\n attributes,\n bucketValue,\n datafileReader,\n );\n\n if (!matchedTraffic) {\n return undefined;\n }\n\n const allocation = getMatchedAllocation(matchedTraffic, bucketValue);\n\n if (!allocation) {\n return undefined;\n }\n\n const variationValue = allocation.variation;\n\n const variation = feature.variations.find((v) => {\n return v.value === variationValue;\n });\n\n if (!variation) {\n return undefined;\n }\n\n return variation;\n}\n\nexport function getForcedVariableValue(\n feature: Feature,\n variableKey: VariableKey,\n attributes: Attributes,\n datafileReader: DatafileReader,\n): VariableValue | undefined {\n const force = findForceFromFeature(feature, attributes, datafileReader);\n\n if (!force || !force.variables) {\n return undefined;\n }\n\n return force.variables[variableKey];\n}\n\nexport function getBucketedVariableValue(\n feature: Feature,\n variableKey: VariableKey,\n attributes: Attributes,\n bucketValue: number,\n datafileReader: DatafileReader,\n): VariableValue | undefined {\n // all variables\n const variablesSchema = feature.variablesSchema;\n\n if (!variablesSchema) {\n return undefined;\n }\n\n // single variable\n const variableSchema = variablesSchema.find((v) => {\n return v.key === variableKey;\n });\n\n if (!variableSchema) {\n return undefined;\n }\n\n // get traffic\n const matchedTraffic = getMatchedTraffic(\n feature.traffic,\n attributes,\n bucketValue,\n datafileReader,\n );\n\n if (!matchedTraffic) {\n return undefined;\n }\n\n // see if variable is set at traffic/rule level\n if (matchedTraffic.variables && typeof matchedTraffic.variables[variableKey] !== \"undefined\") {\n return matchedTraffic.variables[variableKey];\n }\n\n const allocation = getMatchedAllocation(matchedTraffic, bucketValue);\n\n if (!allocation) {\n return undefined;\n }\n\n const variationValue = allocation.variation;\n\n const variation = feature.variations.find((v) => {\n return v.value === variationValue;\n });\n\n if (!variation) {\n return undefined;\n }\n\n const variableFromVariation = variation.variables?.find((v) => {\n return v.key === variableKey;\n });\n\n if (!variableFromVariation) {\n return variableSchema.defaultValue;\n }\n\n if (variableFromVariation.overrides) {\n const override = variableFromVariation.overrides.find((o) => {\n if (o.conditions) {\n return allConditionsAreMatched(\n typeof o.conditions === \"string\" ? JSON.parse(o.conditions) : o.conditions,\n attributes,\n );\n }\n\n if (o.segments) {\n return allGroupSegmentsAreMatched(\n typeof o.segments === \"string\" && o.segments !== \"*\"\n ? JSON.parse(o.segments)\n : o.segments,\n attributes,\n datafileReader,\n );\n }\n\n return false;\n });\n\n if (override) {\n return override.value;\n }\n }\n\n return variableFromVariation.value;\n}\n","export * from \"./bucket\";\nexport * from \"./client\";\nexport * from \"./createInstance\";\n","import { Attributes, GroupSegment, Segment, Condition } from \"@featurevisor/types\";\nimport { allConditionsAreMatched } from \"./conditions\";\nimport { DatafileReader } from \"./datafileReader\";\n\nexport function segmentIsMatched(segment: Segment, attributes: Attributes): boolean {\n return allConditionsAreMatched(segment.conditions as Condition | Condition[], attributes);\n}\n\nexport function allGroupSegmentsAreMatched(\n groupSegments: GroupSegment | GroupSegment[] | \"*\",\n attributes: Attributes,\n datafileReader: DatafileReader,\n): boolean {\n if (groupSegments === \"*\") {\n return true;\n }\n\n if (typeof groupSegments === \"string\") {\n const segment = datafileReader.getSegment(groupSegments);\n\n if (segment) {\n return segmentIsMatched(segment, attributes);\n }\n\n return false;\n }\n\n if (typeof groupSegments === \"object\") {\n if (\"and\" in groupSegments && Array.isArray(groupSegments.and)) {\n return groupSegments.and.every((groupSegment) =>\n allGroupSegmentsAreMatched(groupSegment, attributes, datafileReader),\n );\n }\n\n if (\"or\" in groupSegments && Array.isArray(groupSegments.or)) {\n return groupSegments.or.some((groupSegment) =>\n allGroupSegmentsAreMatched(groupSegment, attributes, datafileReader),\n );\n }\n\n if (\"not\" in groupSegments && Array.isArray(groupSegments.not)) {\n return groupSegments.not.every(\n (groupSegment) =>\n allGroupSegmentsAreMatched(groupSegment, attributes, datafileReader) === false,\n );\n }\n }\n\n if (Array.isArray(groupSegments)) {\n return groupSegments.every((groupSegment) =>\n allGroupSegmentsAreMatched(groupSegment, attributes, datafileReader),\n );\n }\n\n return false;\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(97);\n"],"names":["root","factory","exports","module","define","amd","this","createBuffer","val","TextEncoder","encode","MurmurHashV3","key","seed","remainder","bytes","h1","h1b","c1","c2","k1","i","length","murmur","v2","str","k","l","h","v3","MAX_HASH_VALUE","Math","pow","MAX_BUCKETED_NUMBER","bucketKey","ratio","murmurhash","floor","getValueByType","value","fieldType","undefined","parseInt","parseFloat","Array","isArray","options","onActivation","configureBucketValue","setDatafile","datafile","datafileReader","DatafileReader","JSON","parse","e","console","error","getFeature","featureKey","getBucketKey","feature","attributes","prefix","bucketBy","join","getBucketValue","getBucketedNumber","getVariation","forcedVariation","getForcedVariation","bucketValue","variation","getBucketedVariation","defaultVariation","getVariationBoolean","getVariationString","getVariationInteger","getVariationDouble","activate","variationValue","getAllAttributes","filter","a","capture","forEach","activateBoolean","activateString","activateInteger","activateDouble","getVariable","variableKey","forcedVariableValue","getForcedVariableValue","getBucketedVariableValue","getVariableBoolean","getVariableString","getVariableInteger","getVariableDouble","getVariableArray","getVariableObject","FeaturevisorSDK","conditionIsMatched","condition","attribute","operator","valueInAttributes","indexOf","startsWith","endsWith","allConditionsAreMatched","conditions","and","every","c","or","some","not","getInstanceFromSdk","sdk","bind","emptyDatafile","schemaVersion","revision","segments","features","datafileUrl","Error","onReady","setTimeout","handleDatafileFetch","fetch","then","res","json","fetchDatafileContent","catch","parseJsonConditionsIfStringified","record","datafileJson","getRevision","getSchemaVersion","getAttribute","attributeKey","find","getSegment","segmentKey","segment","s","getMatchedTraffic","traffic","percentage","allGroupSegmentsAreMatched","getMatchedAllocation","matchedTraffic","total","allocation","findForceFromFeature","force","f","variations","v","variables","variablesSchema","variableSchema","variableFromVariation","defaultValue","overrides","override","o","segmentIsMatched","groupSegments","groupSegment","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","call"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAyB,gBAAID,IAE7BD,EAAsB,gBAAIC,GAC3B,CATD,CASGK,MAAM,KACT,O,WCVC,WACC,MAEMC,EAAgBC,IAAQ,IAAIC,aAAcC,OAAOF,GAiEvD,SAASG,EAAaC,EAAKC,GAGzB,IAAIC,EAAWC,EAAOC,EAAIC,EAAKC,EAASC,EAASC,EAAIC,EASrD,I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GCtDI4H,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBxI,IAAjByI,EACH,OAAOA,EAAahL,QAGrB,IAAIC,EAAS4K,EAAyBE,GAAY,CAGjD/K,QAAS,CAAC,GAOX,OAHAiL,EAAoBF,GAAUG,KAAKjL,EAAOD,QAASC,EAAQA,EAAOD,QAAS8K,GAGpE7K,EAAOD,OACf,CCnB0B8K,CAAoB,I,MDF1CD,C","sources":["webpack://FeaturevisorSDK/webpack/universalModuleDefinition","webpack://FeaturevisorSDK/../../node_modules/murmurhash/murmurhash.js","webpack://FeaturevisorSDK/./src/bucket.ts","webpack://FeaturevisorSDK/./src/client.ts","webpack://FeaturevisorSDK/./src/conditions.ts","webpack://FeaturevisorSDK/./src/createInstance.ts","webpack://FeaturevisorSDK/./src/datafileReader.ts","webpack://FeaturevisorSDK/./src/feature.ts","webpack://FeaturevisorSDK/./src/index.ts","webpack://FeaturevisorSDK/./src/segments.ts","webpack://FeaturevisorSDK/webpack/bootstrap","webpack://FeaturevisorSDK/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"FeaturevisorSDK\"] = factory();\n\telse\n\t\troot[\"FeaturevisorSDK\"] = factory();\n})(this, () => {\nreturn ","(function(){\n const _global = this;\n\n const createBuffer = (val) => new TextEncoder().encode(val)\n\n /**\n * JS Implementation of MurmurHash2\n *\n * @author <a href=\"mailto:gary.court@gmail.com\">Gary Court</a>\n * @see http://github.com/garycourt/murmurhash-js\n * @author <a href=\"mailto:aappleby@gmail.com\">Austin Appleby</a>\n * @see http://sites.google.com/site/murmurhash/\n *\n * @param {Uint8Array | string} str ASCII only\n * @param {number} seed Positive integer only\n * @return {number} 32-bit positive integer hash\n */\n function MurmurHashV2(str, seed) {\n if (typeof str === 'string') str = createBuffer(str);\n let\n l = str.length,\n h = seed ^ l,\n i = 0,\n k;\n\n while (l >= 4) {\n k =\n ((str[i] & 0xff)) |\n ((str[++i] & 0xff) << 8) |\n ((str[++i] & 0xff) << 16) |\n ((str[++i] & 0xff) << 24);\n\n k = (((k & 0xffff) * 0x5bd1e995) + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16));\n k ^= k >>> 24;\n k = (((k & 0xffff) * 0x5bd1e995) + ((((k >>> 16) * 0x5bd1e995) & 0xffff) << 16));\n\n h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16)) ^ k;\n\n l -= 4;\n ++i;\n }\n\n switch (l) {\n case 3: h ^= (str[i + 2] & 0xff) << 16;\n case 2: h ^= (str[i + 1] & 0xff) << 8;\n case 1: h ^= (str[i] & 0xff);\n h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16));\n }\n\n h ^= h >>> 13;\n h = (((h & 0xffff) * 0x5bd1e995) + ((((h >>> 16) * 0x5bd1e995) & 0xffff) << 16));\n h ^= h >>> 15;\n\n return h >>> 0;\n };\n\n /*\n * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)\n *\n * @author <a href=\"mailto:gary.court@gmail.com\">Gary Court</a>\n * @see http://github.com/garycourt/murmurhash-js\n * @author <a href=\"mailto:aappleby@gmail.com\">Austin Appleby</a>\n * @see http://sites.google.com/site/murmurhash/\n *\n * @param {Uint8Array | string} key ASCII only\n * @param {number} seed Positive integer only\n * @return {number} 32-bit positive integer hash\n */\n function MurmurHashV3(key, seed) {\n if (typeof key === 'string') key = createBuffer(key);\n\n let remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i;\n\n remainder = key.length & 3; // key.length % 4\n bytes = key.length - remainder;\n h1 = seed;\n c1 = 0xcc9e2d51;\n c2 = 0x1b873593;\n i = 0;\n\n while (i < bytes) {\n k1 =\n ((key[i] & 0xff)) |\n ((key[++i] & 0xff) << 8) |\n ((key[++i] & 0xff) << 16) |\n ((key[++i] & 0xff) << 24);\n ++i;\n\n k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff;\n k1 = (k1 << 15) | (k1 >>> 17);\n k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff;\n\n h1 ^= k1;\n h1 = (h1 << 13) | (h1 >>> 19);\n h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff;\n h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16));\n }\n\n k1 = 0;\n\n switch (remainder) {\n case 3: k1 ^= (key[i + 2] & 0xff) << 16;\n case 2: k1 ^= (key[i + 1] & 0xff) << 8;\n case 1: k1 ^= (key[i] & 0xff);\n\n k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;\n k1 = (k1 << 15) | (k1 >>> 17);\n k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;\n h1 ^= k1;\n }\n\n h1 ^= key.length;\n\n h1 ^= h1 >>> 16;\n h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;\n h1 ^= h1 >>> 13;\n h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;\n h1 ^= h1 >>> 16;\n\n return h1 >>> 0;\n }\n\n const murmur = MurmurHashV3;\n murmur.v2 = MurmurHashV2;\n murmur.v3 = MurmurHashV3;\n\n if (typeof(module) != 'undefined') {\n module.exports = murmur;\n } else {\n const _previousRoot = _global.murmur;\n murmur.noConflict = function() {\n _global.murmur = _previousRoot;\n return murmur;\n }\n _global.murmur = murmur;\n }\n}());\n","import * as murmurhash from \"murmurhash\";\n\nconst HASH_SEED = 1;\nconst MAX_HASH_VALUE = Math.pow(2, 32);\n\nexport const MAX_BUCKETED_NUMBER = 100000; // 100% * 1000 to include three decimal places in the same integer value\n\nexport function getBucketedNumber(bucketKey: string): number {\n const hashValue = murmurhash.v3(bucketKey, HASH_SEED);\n const ratio = hashValue / MAX_HASH_VALUE;\n\n return Math.floor(ratio * MAX_BUCKETED_NUMBER);\n}\n","import {\n Attributes,\n VariationValue,\n VariableValue,\n Feature,\n DatafileContent,\n BucketKey,\n BucketValue,\n FeatureKey,\n VariationType,\n VariableType,\n} from \"@featurevisor/types\";\nimport { DatafileReader } from \"./datafileReader\";\nimport {\n getBucketedVariation,\n getBucketedVariableValue,\n getForcedVariation,\n getForcedVariableValue,\n} from \"./feature\";\nimport { getBucketedNumber } from \"./bucket\";\nimport { VariableSchema } from \"@featurevisor/types/src\";\n\nexport type ActivationCallback = (\n featureName: string,\n variation: VariationValue,\n attributes: Attributes,\n captureAttributes: Attributes,\n) => void;\n\nexport type ConfigureBucketValue = (feature, attributes, bucketValue: BucketValue) => BucketValue;\n\nexport interface SdkOptions {\n datafile: DatafileContent | string;\n onActivation?: ActivationCallback; // @TODO: move it to FeaturevisorInstance in next breaking semver\n configureBucketValue?: ConfigureBucketValue;\n}\n\ntype FieldType = VariationType | VariableType;\ntype ValueType = VariableValue;\n\nexport function getValueByType(value: ValueType, fieldType: FieldType): ValueType {\n if (value === undefined) {\n return undefined;\n }\n\n switch (fieldType) {\n case \"string\":\n return typeof value === \"string\" ? value : undefined;\n case \"integer\":\n return parseInt(value as string, 10);\n case \"double\":\n return parseFloat(value as string);\n case \"boolean\":\n return value === true;\n case \"array\":\n return Array.isArray(value) ? value : undefined;\n case \"object\":\n return typeof value === \"object\" ? value : undefined;\n // @NOTE: `json` is not handled here intentionally\n default:\n return value;\n }\n}\n\n// @TODO: change it to FeaturevisorEngine in next breaking semver\n// @TODO: move activate*() methods to FeaturevisorInstance in next breaking semver\nexport class FeaturevisorSDK {\n private onActivation?: ActivationCallback;\n private datafileReader: DatafileReader;\n private configureBucketValue?: ConfigureBucketValue;\n\n constructor(options: SdkOptions) {\n if (options.onActivation) {\n this.onActivation = options.onActivation;\n }\n\n if (options.configureBucketValue) {\n this.configureBucketValue = options.configureBucketValue;\n }\n\n this.setDatafile(options.datafile);\n }\n\n setDatafile(datafile: DatafileContent | string) {\n try {\n this.datafileReader = new DatafileReader(\n typeof datafile === \"string\" ? JSON.parse(datafile) : datafile,\n );\n } catch (e) {\n console.error(`Featurevisor could not parse the datafile`);\n console.error(e);\n }\n }\n\n private getFeature(featureKey: string | Feature): Feature | undefined {\n return typeof featureKey === \"string\"\n ? this.datafileReader.getFeature(featureKey) // only key provided\n : featureKey; // full feature provided\n }\n\n /**\n * Bucketing\n */\n\n private getBucketKey(feature: Feature, attributes: Attributes): BucketKey {\n const featureKey = feature.key;\n\n const prefix =\n typeof feature.bucketBy === \"string\" ? feature.bucketBy : feature.bucketBy.join(\"_\");\n\n return `${prefix}_${featureKey}`;\n }\n\n private getBucketValue(feature: Feature, attributes: Attributes): BucketValue {\n const bucketKey = this.getBucketKey(feature, attributes);\n\n const value = getBucketedNumber(bucketKey);\n\n if (this.configureBucketValue) {\n return this.configureBucketValue(feature, attributes, value);\n }\n\n return value;\n }\n\n /**\n * Variation\n */\n\n getVariation(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): VariationValue | undefined {\n try {\n const feature = this.getFeature(featureKey);\n\n if (!feature) {\n return undefined;\n }\n\n const forcedVariation = getForcedVariation(feature, attributes, this.datafileReader);\n\n if (forcedVariation) {\n return forcedVariation.value;\n }\n\n const bucketValue = this.getBucketValue(feature, attributes);\n\n const variation = getBucketedVariation(feature, attributes, bucketValue, this.datafileReader);\n\n if (!variation) {\n return feature.defaultVariation;\n }\n\n return variation.value;\n } catch (e) {\n console.error(\"[Featurevisor]\", e);\n\n return undefined;\n }\n }\n\n getVariationBoolean(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): boolean | undefined {\n const variationValue = this.getVariation(featureKey, attributes);\n\n return getValueByType(variationValue, \"boolean\") as boolean | undefined;\n }\n\n getVariationString(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): string | undefined {\n const variationValue = this.getVariation(featureKey, attributes);\n\n return getValueByType(variationValue, \"string\") as string | undefined;\n }\n\n getVariationInteger(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): number | undefined {\n const variationValue = this.getVariation(featureKey, attributes);\n\n return getValueByType(variationValue, \"integer\") as number | undefined;\n }\n\n getVariationDouble(\n featureKey: FeatureKey | Feature,\n attributes: Attributes = {},\n ): number | undefined {\n const variationValue = this.getVariation(featureKey, attributes);\n\n return getValueByType(variationValue, \"double\") as number | undefined;\n }\n\n /**\n * Activate\n */\n activate(featureKey: FeatureKey, attributes: Attributes = {}): VariationValue | undefined {\n try {\n const variationValue = this.getVariation(featureKey, attributes);\n\n if (!variationValue) {\n return undefined;\n }\n\n if (this.onActivation) {\n const captureAttributes: Attributes = {};\n\n const attributesForCapturing = this.datafileReader\n .getAllAttributes()\n .filter((a) => a.capture === true);\n\n attributesForCapturing.forEach((a) => {\n if (typeof attributes[a.key] !== \"undefined\") {\n captureAttributes[a.key] = attributes[a.key];\n }\n });\n\n this.onActivation(featureKey, variationValue, attributes, captureAttributes);\n }\n\n return variationValue;\n } catch (e) {\n console.error(\"[Featurevisor]\", e);\n\n return undefined;\n }\n }\n\n activateBoolean(featureKey: FeatureKey, attributes: Attributes = {}): boolean | undefined {\n const variationValue = this.activate(featureKey, attributes);\n\n return getValueByType(variationValue, \"boolean\") as boolean | undefined;\n }\n\n activateString(featureKey: FeatureKey, attributes: Attributes = {}): string | undefined {\n const variationValue = this.activate(featureKey, attributes);\n\n return getValueByType(variationValue, \"string\") as string | undefined;\n }\n\n activateInteger(featureKey: FeatureKey, attributes: Attributes = {}): number | undefined {\n const variationValue = this.activate(featureKey, attributes);\n\n return getValueByType(variationValue, \"integer\") as number | undefined;\n }\n\n activateDouble(featureKey: FeatureKey, attributes: Attributes = {}): number | undefined {\n const variationValue = this.activate(featureKey, attributes);\n\n return getValueByType(variationValue, \"double\") as number | undefined;\n }\n\n /**\n * Variable\n */\n\n getVariable(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): VariableValue | undefined {\n try {\n const feature = this.getFeature(featureKey);\n\n if (!feature) {\n return undefined;\n }\n\n const variableSchema = Array.isArray(feature.variablesSchema)\n ? feature.variablesSchema.find((v) => v.key === variableKey)\n : undefined;\n\n if (!variableSchema) {\n return undefined;\n }\n\n const forcedVariableValue = getForcedVariableValue(\n feature,\n variableSchema,\n attributes,\n this.datafileReader,\n );\n\n if (typeof forcedVariableValue !== \"undefined\") {\n return forcedVariableValue;\n }\n\n const bucketValue = this.getBucketValue(feature, attributes);\n\n return getBucketedVariableValue(\n feature,\n variableSchema,\n attributes,\n bucketValue,\n this.datafileReader,\n );\n } catch (e) {\n console.error(\"[Featurevisor]\", e);\n\n return undefined;\n }\n }\n\n getVariableBoolean(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): boolean | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"boolean\") as boolean | undefined;\n }\n\n getVariableString(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): string | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"string\") as string | undefined;\n }\n\n getVariableInteger(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): number | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"integer\") as number | undefined;\n }\n\n getVariableDouble(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): number | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"double\") as number | undefined;\n }\n\n getVariableArray(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): string[] | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"array\") as string[] | undefined;\n }\n\n getVariableObject<T>(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): T | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"object\") as T | undefined;\n }\n\n getVariableJSON<T>(\n featureKey: FeatureKey | Feature,\n variableKey: string,\n attributes: Attributes = {},\n ): T | undefined {\n const variableValue = this.getVariable(featureKey, variableKey, attributes);\n\n return getValueByType(variableValue, \"json\") as T | undefined;\n }\n}\n","import { Attributes, Condition, PlainCondition } from \"@featurevisor/types\";\n\nexport function conditionIsMatched(condition: PlainCondition, attributes: Attributes): boolean {\n const { attribute, operator, value } = condition;\n\n if (operator === \"equals\") {\n return attributes[attribute] === value;\n } else if (operator === \"notEquals\") {\n return attributes[attribute] !== value;\n } else if (typeof attributes[attribute] === \"string\" && Array.isArray(value)) {\n // array\n const valueInAttributes = attributes[attribute] as string;\n\n if (operator === \"in\") {\n return value.indexOf(valueInAttributes) !== -1;\n } else if (operator === \"notIn\") {\n return value.indexOf(valueInAttributes) === -1;\n }\n } else if (typeof attributes[attribute] === \"string\" && typeof value === \"string\") {\n // string\n const valueInAttributes = attributes[attribute] as string;\n\n if (operator === \"contains\") {\n return valueInAttributes.indexOf(value) !== -1;\n } else if (operator === \"notContains\") {\n return valueInAttributes.indexOf(value) === -1;\n } else if (operator === \"startsWith\") {\n return valueInAttributes.startsWith(value);\n } else if (operator === \"endsWith\") {\n return valueInAttributes.endsWith(value);\n }\n } else if (typeof attributes[attribute] === \"number\" && typeof value === \"number\") {\n // numeric\n const valueInAttributes = attributes[attribute] as number;\n\n if (operator === \"greaterThan\") {\n return valueInAttributes > value;\n } else if (operator === \"greaterThanOrEquals\") {\n return valueInAttributes >= value;\n } else if (operator === \"lessThan\") {\n return valueInAttributes < value;\n } else if (operator === \"lessThanOrEquals\") {\n return valueInAttributes <= value;\n }\n }\n\n return false;\n}\n\nexport function allConditionsAreMatched(\n conditions: Condition[] | Condition,\n attributes: Attributes,\n): boolean {\n if (\"attribute\" in conditions) {\n return conditionIsMatched(conditions, attributes);\n }\n\n if (\"and\" in conditions && Array.isArray(conditions.and)) {\n return conditions.and.every((c) => allConditionsAreMatched(c, attributes));\n }\n\n if (\"or\" in conditions && Array.isArray(conditions.or)) {\n return conditions.or.some((c) => allConditionsAreMatched(c, attributes));\n }\n\n if (\"not\" in conditions && Array.isArray(conditions.not)) {\n return conditions.not.every(\n (c) =>\n allConditionsAreMatched(\n {\n and: conditions.not,\n },\n attributes,\n ) === false,\n );\n }\n\n if (Array.isArray(conditions)) {\n return conditions.every((c) => allConditionsAreMatched(c, attributes));\n }\n\n return false;\n}\n","import { DatafileContent } from \"@featurevisor/types\";\nimport { FeaturevisorSDK, ConfigureBucketValue, ActivationCallback } from \"./client\";\n\nexport type ReadyCallback = () => void;\n\nexport interface InstanceOptions {\n // from SdkOptions\n datafile?: DatafileContent | string; // optional here, but not in SdkOptions\n onActivation?: ActivationCallback;\n configureBucketValue?: ConfigureBucketValue;\n\n // additions\n datafileUrl?: string;\n onReady?: ReadyCallback;\n handleDatafileFetch?: (datafileUrl: string) => Promise<DatafileContent>;\n}\n\n// @TODO: consider renaming it to FeaturevisorSDK in next breaking semver\nexport interface FeaturevisorInstance {\n /**\n * From FeaturevisorSDK\n */\n\n // variation\n getVariation: FeaturevisorSDK[\"getVariation\"];\n getVariationBoolean: FeaturevisorSDK[\"getVariationBoolean\"];\n getVariationInteger: FeaturevisorSDK[\"getVariationInteger\"];\n getVariationDouble: FeaturevisorSDK[\"getVariationDouble\"];\n getVariationString: FeaturevisorSDK[\"getVariationString\"];\n\n // activate\n activate: FeaturevisorSDK[\"activate\"];\n activateBoolean: FeaturevisorSDK[\"activateBoolean\"];\n activateInteger: FeaturevisorSDK[\"activateInteger\"];\n activateDouble: FeaturevisorSDK[\"activateDouble\"];\n activateString: FeaturevisorSDK[\"activateString\"];\n\n // variable\n getVariable: FeaturevisorSDK[\"getVariable\"];\n getVariableBoolean: FeaturevisorSDK[\"getVariableBoolean\"];\n getVariableInteger: FeaturevisorSDK[\"getVariableInteger\"];\n getVariableDouble: FeaturevisorSDK[\"getVariableDouble\"];\n getVariableString: FeaturevisorSDK[\"getVariableString\"];\n getVariableArray: FeaturevisorSDK[\"getVariableArray\"];\n getVariableObject: FeaturevisorSDK[\"getVariableObject\"];\n\n /**\n * Additions\n *\n * @TODO\n */\n // start: () => void;\n // stop: () => void;\n // refresh: () => void;\n}\n\nfunction getInstanceFromSdk(sdk: FeaturevisorSDK, options: InstanceOptions): FeaturevisorInstance {\n return {\n // variation\n getVariation: sdk.getVariation.bind(sdk),\n getVariationBoolean: sdk.getVariationBoolean.bind(sdk),\n getVariationInteger: sdk.getVariationInteger.bind(sdk),\n getVariationDouble: sdk.getVariationDouble.bind(sdk),\n getVariationString: sdk.getVariationString.bind(sdk),\n\n // activate\n activate: sdk.activate,\n activateBoolean: sdk.activateBoolean.bind(sdk),\n activateInteger: sdk.activateInteger.bind(sdk),\n activateDouble: sdk.activateDouble.bind(sdk),\n activateString: sdk.activateString.bind(sdk),\n\n // variable\n getVariable: sdk.getVariable.bind(sdk),\n getVariableBoolean: sdk.getVariableBoolean.bind(sdk),\n getVariableInteger: sdk.getVariableInteger.bind(sdk),\n getVariableDouble: sdk.getVariableDouble.bind(sdk),\n getVariableString: sdk.getVariableString.bind(sdk),\n getVariableArray: sdk.getVariableArray.bind(sdk),\n getVariableObject: sdk.getVariableObject.bind(sdk),\n\n // additions\n // @TODO\n // start: () => {},\n // stop: () => {},\n // refresh: () => {},\n };\n}\n\nconst emptyDatafile: DatafileContent = {\n schemaVersion: \"1\",\n revision: \"unknown\",\n attributes: [],\n segments: [],\n features: [],\n};\n\nfunction fetchDatafileContent(datafileUrl, options: InstanceOptions): Promise<DatafileContent> {\n if (options.handleDatafileFetch) {\n return options.handleDatafileFetch(datafileUrl);\n }\n\n return fetch(datafileUrl).then((res) => res.json());\n}\n\nexport function createInstance(options: InstanceOptions) {\n if (!options.datafile && !options.datafileUrl) {\n throw new Error(\n \"Featurevisor SDK instance cannot be created without `datafile` or `datafileUrl` option\",\n );\n }\n\n // datafile content is already provided\n if (options.datafile) {\n const sdk = new FeaturevisorSDK({\n datafile: options.datafile,\n onActivation: options.onActivation,\n configureBucketValue: options.configureBucketValue,\n });\n\n if (typeof options.onReady === \"function\") {\n const onReady = options.onReady;\n\n setTimeout(function () {\n onReady();\n }, 0);\n }\n\n return getInstanceFromSdk(sdk, options);\n }\n\n // datafile has to be fetched\n const sdk = new FeaturevisorSDK({\n datafile: emptyDatafile,\n onActivation: options.onActivation,\n configureBucketValue: options.configureBucketValue,\n });\n\n if (options.datafileUrl) {\n fetchDatafileContent(options.datafileUrl, options)\n .then((datafile) => {\n sdk.setDatafile(datafile);\n\n if (typeof options.onReady === \"function\") {\n options.onReady();\n }\n })\n .catch((e) => {\n console.error(\"Featurevisor failed to fetch datafile:\");\n console.error(e);\n });\n }\n\n return getInstanceFromSdk(sdk, options);\n}\n","import {\n Feature,\n Segment,\n DatafileContent,\n Attribute,\n AttributeKey,\n SegmentKey,\n FeatureKey,\n} from \"@featurevisor/types\";\n\nexport function parseJsonConditionsIfStringified<T>(record: T, key: string): T {\n if (typeof record[key] === \"string\" && record[key] !== \"*\") {\n try {\n record[key] = JSON.parse(record[key]);\n } catch (e) {\n console.error(\"Error parsing JSON\", e);\n }\n }\n\n return record;\n}\n\nexport class DatafileReader {\n private schemaVersion: string;\n private revision: string;\n private attributes: Attribute[];\n private segments: Segment[];\n private features: Feature[];\n\n constructor(datafileJson: DatafileContent) {\n this.schemaVersion = datafileJson.schemaVersion;\n this.revision = datafileJson.revision;\n this.segments = datafileJson.segments;\n this.attributes = datafileJson.attributes;\n this.features = datafileJson.features;\n }\n\n getRevision(): string {\n return this.revision;\n }\n\n getSchemaVersion(): string {\n return this.schemaVersion;\n }\n\n getAllAttributes(): Attribute[] {\n return this.attributes;\n }\n\n getAttribute(attributeKey: AttributeKey): Attribute | undefined {\n return this.attributes.find((a) => a.key === attributeKey);\n }\n\n getSegment(segmentKey: SegmentKey): Segment | undefined {\n const segment = this.segments.find((s) => s.key === segmentKey);\n\n if (!segment) {\n return undefined;\n }\n\n return parseJsonConditionsIfStringified(segment, \"conditions\");\n }\n\n getFeature(featureKey: FeatureKey): Feature | undefined {\n const feature = this.features.find((s) => s.key === featureKey);\n\n if (!feature) {\n return undefined;\n }\n\n return feature;\n }\n}\n","import {\n Allocation,\n Attributes,\n Traffic,\n Feature,\n Variation,\n VariableValue,\n Force,\n} from \"@featurevisor/types\";\nimport { DatafileReader } from \"./datafileReader\";\nimport { allGroupSegmentsAreMatched } from \"./segments\";\nimport { allConditionsAreMatched } from \"./conditions\";\nimport { VariableSchema } from \"@featurevisor/types/src\";\n\nexport function getMatchedTraffic(\n traffic: Traffic[],\n attributes: Attributes,\n bucketValue: number,\n datafileReader: DatafileReader,\n): Traffic | undefined {\n return traffic.find((traffic) => {\n if (bucketValue > traffic.percentage) {\n // out of bucket range\n return false;\n }\n\n if (\n !allGroupSegmentsAreMatched(\n typeof traffic.segments === \"string\" && traffic.segments !== \"*\"\n ? JSON.parse(traffic.segments)\n : traffic.segments,\n attributes,\n datafileReader,\n )\n ) {\n return false;\n }\n\n return true;\n });\n}\n\n// @TODO: make this function better with tests\nexport function getMatchedAllocation(\n matchedTraffic: Traffic,\n bucketValue: number,\n): Allocation | undefined {\n let total = 0;\n\n for (const allocation of matchedTraffic.allocation) {\n total += allocation.percentage;\n\n if (bucketValue <= total) {\n return allocation;\n }\n }\n\n return undefined;\n}\n\nfunction findForceFromFeature(\n feature: Feature,\n attributes: Attributes,\n datafileReader: DatafileReader,\n): Force | undefined {\n if (!feature.force) {\n return undefined;\n }\n\n return feature.force.find((f: Force) => {\n if (f.conditions) {\n return allConditionsAreMatched(f.conditions, attributes);\n }\n\n if (f.segments) {\n return allGroupSegmentsAreMatched(f.segments, attributes, datafileReader);\n }\n\n return false;\n });\n}\n\nexport function getForcedVariation(\n feature: Feature,\n attributes: Attributes,\n datafileReader: DatafileReader,\n): Variation | undefined {\n const force = findForceFromFeature(feature, attributes, datafileReader);\n\n if (!force || !force.variation) {\n return undefined;\n }\n\n return feature.variations.find((v) => v.value === force.variation);\n}\n\nexport function getBucketedVariation(\n feature: Feature,\n attributes: Attributes,\n bucketValue: number,\n datafileReader: DatafileReader,\n): Variation | undefined {\n const matchedTraffic = getMatchedTraffic(\n feature.traffic,\n attributes,\n bucketValue,\n datafileReader,\n );\n\n if (!matchedTraffic) {\n return undefined;\n }\n\n const allocation = getMatchedAllocation(matchedTraffic, bucketValue);\n\n if (!allocation) {\n return undefined;\n }\n\n const variationValue = allocation.variation;\n\n const variation = feature.variations.find((v) => {\n return v.value === variationValue;\n });\n\n if (!variation) {\n return undefined;\n }\n\n return variation;\n}\n\nexport function getForcedVariableValue(\n feature: Feature,\n variableSchema: VariableSchema,\n attributes: Attributes,\n datafileReader: DatafileReader,\n): VariableValue | undefined {\n const force = findForceFromFeature(feature, attributes, datafileReader);\n\n if (!force || !force.variables) {\n return undefined;\n }\n\n const value = force.variables[variableSchema.key];\n\n if (typeof value === \"string\" && variableSchema.type === \"json\") {\n return JSON.parse(value);\n }\n\n return value;\n}\n\nexport function getBucketedVariableValue(\n feature: Feature,\n variableSchema: VariableSchema,\n attributes: Attributes,\n bucketValue: number,\n datafileReader: DatafileReader,\n): VariableValue | undefined {\n // get traffic\n const matchedTraffic = getMatchedTraffic(\n feature.traffic,\n attributes,\n bucketValue,\n datafileReader,\n );\n\n if (!matchedTraffic) {\n return undefined;\n }\n\n const variableKey = variableSchema.key;\n\n // see if variable is set at traffic/rule level\n if (matchedTraffic.variables && typeof matchedTraffic.variables[variableKey] !== \"undefined\") {\n return matchedTraffic.variables[variableKey];\n }\n\n const allocation = getMatchedAllocation(matchedTraffic, bucketValue);\n\n if (!allocation) {\n return undefined;\n }\n\n const variationValue = allocation.variation;\n\n const variation = feature.variations.find((v) => {\n return v.value === variationValue;\n });\n\n if (!variation) {\n return undefined;\n }\n\n const variableFromVariation = variation.variables?.find((v) => {\n return v.key === variableKey;\n });\n\n if (!variableFromVariation) {\n if (variableSchema.type === \"json\") {\n return JSON.parse(variableSchema.defaultValue as string);\n }\n\n return variableSchema.defaultValue;\n }\n\n if (variableFromVariation.overrides) {\n const override = variableFromVariation.overrides.find((o) => {\n if (o.conditions) {\n return allConditionsAreMatched(\n typeof o.conditions === \"string\" ? JSON.parse(o.conditions) : o.conditions,\n attributes,\n );\n }\n\n if (o.segments) {\n return allGroupSegmentsAreMatched(\n typeof o.segments === \"string\" && o.segments !== \"*\"\n ? JSON.parse(o.segments)\n : o.segments,\n attributes,\n datafileReader,\n );\n }\n\n return false;\n });\n\n if (override) {\n if (variableSchema.type === \"json\") {\n return JSON.parse(override.value as string);\n }\n\n return override.value;\n }\n }\n\n if (variableSchema.type === \"json\") {\n return JSON.parse(variableFromVariation.value as string);\n }\n\n return variableFromVariation.value;\n}\n","export * from \"./bucket\";\nexport * from \"./client\";\nexport * from \"./createInstance\";\n","import { Attributes, GroupSegment, Segment, Condition } from \"@featurevisor/types\";\nimport { allConditionsAreMatched } from \"./conditions\";\nimport { DatafileReader } from \"./datafileReader\";\n\nexport function segmentIsMatched(segment: Segment, attributes: Attributes): boolean {\n return allConditionsAreMatched(segment.conditions as Condition | Condition[], attributes);\n}\n\nexport function allGroupSegmentsAreMatched(\n groupSegments: GroupSegment | GroupSegment[] | \"*\",\n attributes: Attributes,\n datafileReader: DatafileReader,\n): boolean {\n if (groupSegments === \"*\") {\n return true;\n }\n\n if (typeof groupSegments === \"string\") {\n const segment = datafileReader.getSegment(groupSegments);\n\n if (segment) {\n return segmentIsMatched(segment, attributes);\n }\n\n return false;\n }\n\n if (typeof groupSegments === \"object\") {\n if (\"and\" in groupSegments && Array.isArray(groupSegments.and)) {\n return groupSegments.and.every((groupSegment) =>\n allGroupSegmentsAreMatched(groupSegment, attributes, datafileReader),\n );\n }\n\n if (\"or\" in groupSegments && Array.isArray(groupSegments.or)) {\n return groupSegments.or.some((groupSegment) =>\n allGroupSegmentsAreMatched(groupSegment, attributes, datafileReader),\n );\n }\n\n if (\"not\" in groupSegments && Array.isArray(groupSegments.not)) {\n return groupSegments.not.every(\n (groupSegment) =>\n allGroupSegmentsAreMatched(groupSegment, attributes, datafileReader) === false,\n );\n }\n }\n\n if (Array.isArray(groupSegments)) {\n return groupSegments.every((groupSegment) =>\n allGroupSegmentsAreMatched(groupSegment, attributes, datafileReader),\n );\n }\n\n return false;\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(97);\n"],"names":["root","factory","exports","module","define","amd","this","createBuffer","val","TextEncoder","encode","MurmurHashV3","key","seed","remainder","bytes","h1","h1b","c1","c2","k1","i","length","murmur","v2","str","k","l","h","v3","MAX_HASH_VALUE","Math","pow","MAX_BUCKETED_NUMBER","bucketKey","ratio","murmurhash","floor","getValueByType","value","fieldType","undefined","parseInt","parseFloat","Array","isArray","options","onActivation","configureBucketValue","setDatafile","datafile","datafileReader","DatafileReader","JSON","parse","e","console","error","getFeature","featureKey","getBucketKey","feature","attributes","prefix","bucketBy","join","getBucketValue","getBucketedNumber","getVariation","forcedVariation","getForcedVariation","bucketValue","variation","getBucketedVariation","defaultVariation","getVariationBoolean","getVariationString","getVariationInteger","getVariationDouble","activate","variationValue","getAllAttributes","filter","a","capture","forEach","activateBoolean","activateString","activateInteger","activateDouble","getVariable","variableKey","variableSchema","variablesSchema","find","v","forcedVariableValue","getForcedVariableValue","getBucketedVariableValue","getVariableBoolean","getVariableString","getVariableInteger","getVariableDouble","getVariableArray","getVariableObject","getVariableJSON","FeaturevisorSDK","conditionIsMatched","condition","attribute","operator","valueInAttributes","indexOf","startsWith","endsWith","allConditionsAreMatched","conditions","and","every","c","or","some","not","getInstanceFromSdk","sdk","bind","emptyDatafile","schemaVersion","revision","segments","features","datafileUrl","Error","onReady","setTimeout","handleDatafileFetch","fetch","then","res","json","fetchDatafileContent","catch","parseJsonConditionsIfStringified","record","datafileJson","getRevision","getSchemaVersion","getAttribute","attributeKey","getSegment","segmentKey","segment","s","getMatchedTraffic","traffic","percentage","allGroupSegmentsAreMatched","getMatchedAllocation","matchedTraffic","total","allocation","findForceFromFeature","force","f","variations","variables","type","variableFromVariation","defaultValue","overrides","override","o","segmentIsMatched","groupSegments","groupSegment","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","call"],"sourceRoot":""}
|
package/lib/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Attributes, VariationValue, VariableValue, Feature, DatafileContent, BucketValue, FeatureKey } from "@featurevisor/types";
|
|
1
|
+
import { Attributes, VariationValue, VariableValue, Feature, DatafileContent, BucketValue, FeatureKey, VariationType, VariableType } from "@featurevisor/types";
|
|
2
2
|
export type ActivationCallback = (featureName: string, variation: VariationValue, attributes: Attributes, captureAttributes: Attributes) => void;
|
|
3
3
|
export type ConfigureBucketValue = (feature: any, attributes: any, bucketValue: BucketValue) => BucketValue;
|
|
4
4
|
export interface SdkOptions {
|
|
@@ -6,7 +6,7 @@ export interface SdkOptions {
|
|
|
6
6
|
onActivation?: ActivationCallback;
|
|
7
7
|
configureBucketValue?: ConfigureBucketValue;
|
|
8
8
|
}
|
|
9
|
-
type FieldType =
|
|
9
|
+
type FieldType = VariationType | VariableType;
|
|
10
10
|
type ValueType = VariableValue;
|
|
11
11
|
export declare function getValueByType(value: ValueType, fieldType: FieldType): ValueType;
|
|
12
12
|
export declare class FeaturevisorSDK {
|
|
@@ -47,5 +47,6 @@ export declare class FeaturevisorSDK {
|
|
|
47
47
|
getVariableDouble(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): number | undefined;
|
|
48
48
|
getVariableArray(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): string[] | undefined;
|
|
49
49
|
getVariableObject<T>(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): T | undefined;
|
|
50
|
+
getVariableJSON<T>(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): T | undefined;
|
|
50
51
|
}
|
|
51
52
|
export {};
|
package/lib/client.js
CHANGED
|
@@ -18,6 +18,7 @@ export function getValueByType(value, fieldType) {
|
|
|
18
18
|
return Array.isArray(value) ? value : undefined;
|
|
19
19
|
case "object":
|
|
20
20
|
return typeof value === "object" ? value : undefined;
|
|
21
|
+
// @NOTE: `json` is not handled here intentionally
|
|
21
22
|
default:
|
|
22
23
|
return value;
|
|
23
24
|
}
|
|
@@ -169,12 +170,18 @@ var FeaturevisorSDK = /** @class */ (function () {
|
|
|
169
170
|
if (!feature) {
|
|
170
171
|
return undefined;
|
|
171
172
|
}
|
|
172
|
-
var
|
|
173
|
+
var variableSchema = Array.isArray(feature.variablesSchema)
|
|
174
|
+
? feature.variablesSchema.find(function (v) { return v.key === variableKey; })
|
|
175
|
+
: undefined;
|
|
176
|
+
if (!variableSchema) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
var forcedVariableValue = getForcedVariableValue(feature, variableSchema, attributes, this.datafileReader);
|
|
173
180
|
if (typeof forcedVariableValue !== "undefined") {
|
|
174
181
|
return forcedVariableValue;
|
|
175
182
|
}
|
|
176
183
|
var bucketValue = this.getBucketValue(feature, attributes);
|
|
177
|
-
return getBucketedVariableValue(feature,
|
|
184
|
+
return getBucketedVariableValue(feature, variableSchema, attributes, bucketValue, this.datafileReader);
|
|
178
185
|
}
|
|
179
186
|
catch (e) {
|
|
180
187
|
console.error("[Featurevisor]", e);
|
|
@@ -211,6 +218,11 @@ var FeaturevisorSDK = /** @class */ (function () {
|
|
|
211
218
|
var variableValue = this.getVariable(featureKey, variableKey, attributes);
|
|
212
219
|
return getValueByType(variableValue, "object");
|
|
213
220
|
};
|
|
221
|
+
FeaturevisorSDK.prototype.getVariableJSON = function (featureKey, variableKey, attributes) {
|
|
222
|
+
if (attributes === void 0) { attributes = {}; }
|
|
223
|
+
var variableValue = this.getVariable(featureKey, variableKey, attributes);
|
|
224
|
+
return getValueByType(variableValue, "json");
|
|
225
|
+
};
|
|
214
226
|
return FeaturevisorSDK;
|
|
215
227
|
}());
|
|
216
228
|
export { FeaturevisorSDK };
|
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAqB7C,MAAM,UAAU,cAAc,CAAC,KAAgB,EAAE,SAAoB;IACnE,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,OAAO,SAAS,CAAC;KAClB;IAED,QAAQ,SAAS,EAAE;QACjB,KAAK,QAAQ;YACX,OAAO,O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ributes, Traffic, Feature, Variation, VariableValue } from "@featurevisor/types";
|
|
2
2
|
import { DatafileReader } from "./datafileReader";
|
|
3
|
+
import { VariableSchema } from "@featurevisor/types/src";
|
|
3
4
|
export declare function getMatchedTraffic(traffic: Traffic[], attributes: Attributes, bucketValue: number, datafileReader: DatafileReader): Traffic | undefined;
|
|
4
5
|
export declare function getMatchedAllocation(matchedTraffic: Traffic, bucketValue: number): Allocation | undefined;
|
|
5
6
|
export declare function getForcedVariation(feature: Feature, attributes: Attributes, datafileReader: DatafileReader): Variation | undefined;
|
|
6
7
|
export declare function getBucketedVariation(feature: Feature, attributes: Attributes, bucketValue: number, datafileReader: DatafileReader): Variation | undefined;
|
|
7
|
-
export declare function getForcedVariableValue(feature: Feature,
|
|
8
|
-
export declare function getBucketedVariableValue(feature: Feature,
|
|
8
|
+
export declare function getForcedVariableValue(feature: Feature, variableSchema: VariableSchema, attributes: Attributes, datafileReader: DatafileReader): VariableValue | undefined;
|
|
9
|
+
export declare function getBucketedVariableValue(feature: Feature, variableSchema: VariableSchema, attributes: Attributes, bucketValue: number, datafileReader: DatafileReader): VariableValue | undefined;
|
package/lib/feature.js
CHANGED
|
@@ -65,32 +65,25 @@ export function getBucketedVariation(feature, attributes, bucketValue, datafileR
|
|
|
65
65
|
}
|
|
66
66
|
return variation;
|
|
67
67
|
}
|
|
68
|
-
export function getForcedVariableValue(feature,
|
|
68
|
+
export function getForcedVariableValue(feature, variableSchema, attributes, datafileReader) {
|
|
69
69
|
var force = findForceFromFeature(feature, attributes, datafileReader);
|
|
70
70
|
if (!force || !force.variables) {
|
|
71
71
|
return undefined;
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
var value = force.variables[variableSchema.key];
|
|
74
|
+
if (typeof value === "string" && variableSchema.type === "json") {
|
|
75
|
+
return JSON.parse(value);
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
74
78
|
}
|
|
75
|
-
export function getBucketedVariableValue(feature,
|
|
79
|
+
export function getBucketedVariableValue(feature, variableSchema, attributes, bucketValue, datafileReader) {
|
|
76
80
|
var _a;
|
|
77
|
-
// all variables
|
|
78
|
-
var variablesSchema = feature.variablesSchema;
|
|
79
|
-
if (!variablesSchema) {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
// single variable
|
|
83
|
-
var variableSchema = variablesSchema.find(function (v) {
|
|
84
|
-
return v.key === variableKey;
|
|
85
|
-
});
|
|
86
|
-
if (!variableSchema) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
81
|
// get traffic
|
|
90
82
|
var matchedTraffic = getMatchedTraffic(feature.traffic, attributes, bucketValue, datafileReader);
|
|
91
83
|
if (!matchedTraffic) {
|
|
92
84
|
return undefined;
|
|
93
85
|
}
|
|
86
|
+
var variableKey = variableSchema.key;
|
|
94
87
|
// see if variable is set at traffic/rule level
|
|
95
88
|
if (matchedTraffic.variables && typeof matchedTraffic.variables[variableKey] !== "undefined") {
|
|
96
89
|
return matchedTraffic.variables[variableKey];
|
|
@@ -110,6 +103,9 @@ export function getBucketedVariableValue(feature, variableKey, attributes, bucke
|
|
|
110
103
|
return v.key === variableKey;
|
|
111
104
|
});
|
|
112
105
|
if (!variableFromVariation) {
|
|
106
|
+
if (variableSchema.type === "json") {
|
|
107
|
+
return JSON.parse(variableSchema.defaultValue);
|
|
108
|
+
}
|
|
113
109
|
return variableSchema.defaultValue;
|
|
114
110
|
}
|
|
115
111
|
if (variableFromVariation.overrides) {
|
|
@@ -125,9 +121,15 @@ export function getBucketedVariableValue(feature, variableKey, attributes, bucke
|
|
|
125
121
|
return false;
|
|
126
122
|
});
|
|
127
123
|
if (override) {
|
|
124
|
+
if (variableSchema.type === "json") {
|
|
125
|
+
return JSON.parse(override.value);
|
|
126
|
+
}
|
|
128
127
|
return override.value;
|
|
129
128
|
}
|
|
130
129
|
}
|
|
130
|
+
if (variableSchema.type === "json") {
|
|
131
|
+
return JSON.parse(variableFromVariation.value);
|
|
132
|
+
}
|
|
131
133
|
return variableFromVariation.value;
|
|
132
134
|
}
|
|
133
135
|
//# sourceMappingURL=feature.js.map
|
package/lib/feature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.js","sourceRoot":"","sources":["../src/feature.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"feature.js","sourceRoot":"","sources":["../src/feature.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGvD,MAAM,UAAU,iBAAiB,CAC/B,OAAkB,EAClB,UAAsB,EACtB,WAAmB,EACnB,cAA8B;IAE9B,OAAO,OAAO,CAAC,IAAI,CAAC,UAAC,OAAO;QAC1B,IAAI,WAAW,GAAG,OAAO,CAAC,UAAU,EAAE;YACpC,sBAAsB;YACtB,OAAO,KAAK,CAAC;SACd;QAED,IACE,CAAC,0BAA0B,CACzB,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAC,QAAQ,KAAK,GAAG;YAC9D,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YAC9B,CAAC,CAAC,OAAO,CAAC,QAAQ,EACpB,UAAU,EACV,cAAc,CACf,EACD;YACA,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,oBAAoB,CAClC,cAAuB,EACvB,WAAmB;IAEnB,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAyB,UAAyB,EAAzB,KAAA,cAAc,CAAC,UAAU,EAAzB,cAAyB,EAAzB,IAAyB,EAAE;QAA/C,IAAM,UAAU,SAAA;QACnB,KAAK,IAAI,UAAU,CAAC,UAAU,CAAC;QAE/B,IAAI,WAAW,IAAI,KAAK,EAAE;YACxB,OAAO,UAAU,CAAC;SACnB;KACF;I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,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,GAAG;oBAClD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;oBACxB,CAAC,CAAC,CAAC,CAAC,QAAQ,EACd,UAAU,EACV,cAAc,CACf,CAAC;aACH;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,IAAI,QAAQ,EAAE;YACZ,IAAI,cAAc,CAAC,IAAI,KAAK,MAAM,EAAE;gBAClC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAe,CAAC,CAAC;aAC7C;YAED,OAAO,QAAQ,CAAC,KAAK,CAAC;SACvB;KACF;IAED,IAAI,cAAc,CAAC,IAAI,KAAK,MAAM,EAAE;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAe,CAAC,CAAC;KAC1D;IAED,OAAO,qBAAqB,CAAC,KAAK,CAAC;AACrC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@featurevisor/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Featurevisor SDK for Node.js and the browser",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
},
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@featurevisor/types": "^0.
|
|
45
|
+
"@featurevisor/types": "^0.6.0",
|
|
46
46
|
"murmurhash": "^2.0.1"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "03d4c4e37ac7491f306f5858c98bf65ac8f62fdf"
|
|
49
49
|
}
|
package/src/client.ts
CHANGED
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
BucketKey,
|
|
8
8
|
BucketValue,
|
|
9
9
|
FeatureKey,
|
|
10
|
+
VariationType,
|
|
11
|
+
VariableType,
|
|
10
12
|
} from "@featurevisor/types";
|
|
11
13
|
import { DatafileReader } from "./datafileReader";
|
|
12
14
|
import {
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
getForcedVariableValue,
|
|
17
19
|
} from "./feature";
|
|
18
20
|
import { getBucketedNumber } from "./bucket";
|
|
21
|
+
import { VariableSchema } from "@featurevisor/types/src";
|
|
19
22
|
|
|
20
23
|
export type ActivationCallback = (
|
|
21
24
|
featureName: string,
|
|
@@ -32,8 +35,7 @@ export interface SdkOptions {
|
|
|
32
35
|
configureBucketValue?: ConfigureBucketValue;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
type FieldType = "string" | "integer" | "double" | "boolean" | "array" | "object";
|
|
38
|
+
type FieldType = VariationType | VariableType;
|
|
37
39
|
type ValueType = VariableValue;
|
|
38
40
|
|
|
39
41
|
export function getValueByType(value: ValueType, fieldType: FieldType): ValueType {
|
|
@@ -54,6 +56,7 @@ export function getValueByType(value: ValueType, fieldType: FieldType): ValueTyp
|
|
|
54
56
|
return Array.isArray(value) ? value : undefined;
|
|
55
57
|
case "object":
|
|
56
58
|
return typeof value === "object" ? value : undefined;
|
|
59
|
+
// @NOTE: `json` is not handled here intentionally
|
|
57
60
|
default:
|
|
58
61
|
return value;
|
|
59
62
|
}
|
|
@@ -268,9 +271,17 @@ export class FeaturevisorSDK {
|
|
|
268
271
|
return undefined;
|
|
269
272
|
}
|
|
270
273
|
|
|
274
|
+
const variableSchema = Array.isArray(feature.variablesSchema)
|
|
275
|
+
? feature.variablesSchema.find((v) => v.key === variableKey)
|
|
276
|
+
: undefined;
|
|
277
|
+
|
|
278
|
+
if (!variableSchema) {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
|
|
271
282
|
const forcedVariableValue = getForcedVariableValue(
|
|
272
283
|
feature,
|
|
273
|
-
|
|
284
|
+
variableSchema,
|
|
274
285
|
attributes,
|
|
275
286
|
this.datafileReader,
|
|
276
287
|
);
|
|
@@ -283,7 +294,7 @@ export class FeaturevisorSDK {
|
|
|
283
294
|
|
|
284
295
|
return getBucketedVariableValue(
|
|
285
296
|
feature,
|
|
286
|
-
|
|
297
|
+
variableSchema,
|
|
287
298
|
attributes,
|
|
288
299
|
bucketValue,
|
|
289
300
|
this.datafileReader,
|
|
@@ -354,4 +365,14 @@ export class FeaturevisorSDK {
|
|
|
354
365
|
|
|
355
366
|
return getValueByType(variableValue, "object") as T | undefined;
|
|
356
367
|
}
|
|
368
|
+
|
|
369
|
+
getVariableJSON<T>(
|
|
370
|
+
featureKey: FeatureKey | Feature,
|
|
371
|
+
variableKey: string,
|
|
372
|
+
attributes: Attributes = {},
|
|
373
|
+
): T | undefined {
|
|
374
|
+
const variableValue = this.getVariable(featureKey, variableKey, attributes);
|
|
375
|
+
|
|
376
|
+
return getValueByType(variableValue, "json") as T | undefined;
|
|
377
|
+
}
|
|
357
378
|
}
|
package/src/feature.ts
CHANGED
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
Traffic,
|
|
5
5
|
Feature,
|
|
6
6
|
Variation,
|
|
7
|
-
VariableKey,
|
|
8
7
|
VariableValue,
|
|
9
8
|
Force,
|
|
10
9
|
} from "@featurevisor/types";
|
|
11
10
|
import { DatafileReader } from "./datafileReader";
|
|
12
11
|
import { allGroupSegmentsAreMatched } from "./segments";
|
|
13
12
|
import { allConditionsAreMatched } from "./conditions";
|
|
13
|
+
import { VariableSchema } from "@featurevisor/types/src";
|
|
14
14
|
|
|
15
15
|
export function getMatchedTraffic(
|
|
16
16
|
traffic: Traffic[],
|
|
@@ -132,7 +132,7 @@ export function getBucketedVariation(
|
|
|
132
132
|
|
|
133
133
|
export function getForcedVariableValue(
|
|
134
134
|
feature: Feature,
|
|
135
|
-
|
|
135
|
+
variableSchema: VariableSchema,
|
|
136
136
|
attributes: Attributes,
|
|
137
137
|
datafileReader: DatafileReader,
|
|
138
138
|
): VariableValue | undefined {
|
|
@@ -142,32 +142,22 @@ export function getForcedVariableValue(
|
|
|
142
142
|
return undefined;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
const value = force.variables[variableSchema.key];
|
|
146
|
+
|
|
147
|
+
if (typeof value === "string" && variableSchema.type === "json") {
|
|
148
|
+
return JSON.parse(value);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return value;
|
|
146
152
|
}
|
|
147
153
|
|
|
148
154
|
export function getBucketedVariableValue(
|
|
149
155
|
feature: Feature,
|
|
150
|
-
|
|
156
|
+
variableSchema: VariableSchema,
|
|
151
157
|
attributes: Attributes,
|
|
152
158
|
bucketValue: number,
|
|
153
159
|
datafileReader: DatafileReader,
|
|
154
160
|
): VariableValue | undefined {
|
|
155
|
-
// all variables
|
|
156
|
-
const variablesSchema = feature.variablesSchema;
|
|
157
|
-
|
|
158
|
-
if (!variablesSchema) {
|
|
159
|
-
return undefined;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// single variable
|
|
163
|
-
const variableSchema = variablesSchema.find((v) => {
|
|
164
|
-
return v.key === variableKey;
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
if (!variableSchema) {
|
|
168
|
-
return undefined;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
161
|
// get traffic
|
|
172
162
|
const matchedTraffic = getMatchedTraffic(
|
|
173
163
|
feature.traffic,
|
|
@@ -180,6 +170,8 @@ export function getBucketedVariableValue(
|
|
|
180
170
|
return undefined;
|
|
181
171
|
}
|
|
182
172
|
|
|
173
|
+
const variableKey = variableSchema.key;
|
|
174
|
+
|
|
183
175
|
// see if variable is set at traffic/rule level
|
|
184
176
|
if (matchedTraffic.variables && typeof matchedTraffic.variables[variableKey] !== "undefined") {
|
|
185
177
|
return matchedTraffic.variables[variableKey];
|
|
@@ -206,6 +198,10 @@ export function getBucketedVariableValue(
|
|
|
206
198
|
});
|
|
207
199
|
|
|
208
200
|
if (!variableFromVariation) {
|
|
201
|
+
if (variableSchema.type === "json") {
|
|
202
|
+
return JSON.parse(variableSchema.defaultValue as string);
|
|
203
|
+
}
|
|
204
|
+
|
|
209
205
|
return variableSchema.defaultValue;
|
|
210
206
|
}
|
|
211
207
|
|
|
@@ -232,9 +228,17 @@ export function getBucketedVariableValue(
|
|
|
232
228
|
});
|
|
233
229
|
|
|
234
230
|
if (override) {
|
|
231
|
+
if (variableSchema.type === "json") {
|
|
232
|
+
return JSON.parse(override.value as string);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
235
|
return override.value;
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
if (variableSchema.type === "json") {
|
|
240
|
+
return JSON.parse(variableFromVariation.value as string);
|
|
241
|
+
}
|
|
242
|
+
|
|
239
243
|
return variableFromVariation.value;
|
|
240
244
|
}
|