@featurevisor/sdk 0.0.3
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 +30 -0
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/lib/bucket.d.ts +2 -0
- package/lib/bucket.js +10 -0
- package/lib/bucket.js.map +1 -0
- package/lib/bucket.spec.d.ts +1 -0
- package/lib/client.d.ts +49 -0
- package/lib/client.js +205 -0
- package/lib/client.js.map +1 -0
- package/lib/conditions.d.ts +3 -0
- package/lib/conditions.js +69 -0
- package/lib/conditions.js.map +1 -0
- package/lib/conditions.spec.d.ts +1 -0
- package/lib/datafileReader.d.ts +16 -0
- package/lib/datafileReader.js +49 -0
- package/lib/datafileReader.js.map +1 -0
- package/lib/feature.d.ts +8 -0
- package/lib/feature.js +117 -0
- package/lib/feature.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/lib/index.spec.d.ts +0 -0
- package/lib/segments.d.ts +4 -0
- package/lib/segments.js +35 -0
- package/lib/segments.js.map +1 -0
- package/lib/segments.spec.d.ts +1 -0
- package/package.json +49 -0
- package/src/bucket.spec.ts +18 -0
- package/src/bucket.ts +13 -0
- package/src/client.ts +338 -0
- package/src/conditions.spec.ts +533 -0
- package/src/conditions.ts +73 -0
- package/src/datafileReader.ts +73 -0
- package/src/feature.ts +213 -0
- package/src/index.spec.ts +5 -0
- package/src/index.ts +2 -0
- package/src/segments.spec.ts +196 -0
- package/src/segments.ts +49 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.esm.json +7 -0
- package/webpack.config.js +13 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.0.3](https://github.com/fahad19/featurevisor/compare/v0.0.2...v0.0.3) (2023-03-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* publish access ([ea5cd7c](https://github.com/fahad19/featurevisor/commit/ea5cd7cd8554e2def5fdcc1d3488598a08e99bfa))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.0.2](https://github.com/fahad19/featurevisor/compare/v0.0.1...v0.0.2) (2023-03-05)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @featurevisor/sdk
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 0.0.1 (2023-03-05)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* linting ([230bfa0](https://github.com/fahad19/featurevisor/commit/230bfa0824f79181581585ccc37c2e78c5aeac42))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Fahad Heylaal (https://fahad19.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @featurevisor/sdk
|
|
2
|
+
|
|
3
|
+
Universal Featurevisor SDK for both Node.js and the browser.
|
|
4
|
+
|
|
5
|
+
Visit [https://featurevisor.com](https://featurevisor.com) for more information.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
$ npm install --save @featurevisor/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Initialize the SDK:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { FeaturevisorSDK } from "@featurevisor/sdk";
|
|
19
|
+
|
|
20
|
+
const datafileContent = fetch(datafileURL).then((res) => res.json());
|
|
21
|
+
|
|
22
|
+
const sdk = new FeaturevisorSDK({
|
|
23
|
+
// required
|
|
24
|
+
datafile: datafileContent,
|
|
25
|
+
|
|
26
|
+
// optional
|
|
27
|
+
onActivation: (featureKey, variant, attributes, captureAttributes) => {
|
|
28
|
+
console.log(`Feature ${featureKey} activated with variant ${variant}`);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
### `getVariation`
|
|
36
|
+
|
|
37
|
+
> `getVariation(featureKey: string, attributes: Attributes): VariationValue`
|
|
38
|
+
|
|
39
|
+
### `getVariable`
|
|
40
|
+
|
|
41
|
+
> `getVariable(featureKey: string, variableKey: string, attributes: Attributes): VariableValue`
|
|
42
|
+
|
|
43
|
+
### `activate`
|
|
44
|
+
|
|
45
|
+
> `activate(featureKey: string, attributes: Attributes): VariationValue`
|
|
46
|
+
|
|
47
|
+
Same as `getVariation`, but also calls the `onActivation` callback.
|
|
48
|
+
|
|
49
|
+
This is a convenience method meant to be called when you know the User has been exposed to your Feature, and you also want to track the activation.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT © [Fahad Heylaal](https://fahad19.com)
|
package/dist/index.js
ADDED
|
@@ -0,0 +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 n,i,o,a,u,s,c,f;for("string"==typeof e&&(e=t(e)),n=3&e.length,i=e.length-n,o=r,u=3432918353,s=461845907,f=0;f<i;)c=255&e[f]|(255&e[++f])<<8|(255&e[++f])<<16|(255&e[++f])<<24,++f,c=(65535&c)*u+(((c>>>16)*u&65535)<<16)&4294967295,c=c<<15|c>>>17,c=(65535&c)*s+(((c>>>16)*s&65535)<<16)&4294967295,o^=c,o=o<<13|o>>>19,a=5*(65535&o)+((5*(o>>>16)&65535)<<16)&4294967295,o=27492+(65535&a)+((58964+(a>>>16)&65535)<<16);switch(c=0,n){case 3:c^=(255&e[f+2])<<16;case 2:c^=(255&e[f+1])<<8;case 1:c^=255&e[f],c=(65535&c)*u+(((c>>>16)*u&65535)<<16)&4294967295,c=c<<15|c>>>17,c=(65535&c)*s+(((c>>>16)*s&65535)<<16)&4294967295,o^=c}return o^=e.length,o^=o>>>16,o=2246822507*(65535&o)+((2246822507*(o>>>16)&65535)<<16)&4294967295,o^=o>>>13,o=3266489909*(65535&o)+((3266489909*(o>>>16)&65535)<<16)&4294967295,o^=o>>>16,o>>>0}const n=r;n.v2=function(e,r){"string"==typeof e&&(e=t(e));let n,i=e.length,o=r^i,a=0;for(;i>=4;)n=255&e[a]|(255&e[++a])<<8|(255&e[++a])<<16|(255&e[++a])<<24,n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16),n^=n>>>24,n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16),o=1540483477*(65535&o)+((1540483477*(o>>>16)&65535)<<16)^n,i-=4,++a;switch(i){case 3:o^=(255&e[a+2])<<16;case 2:o^=(255&e[a+1])<<8;case 1:o^=255&e[a],o=1540483477*(65535&o)+((1540483477*(o>>>16)&65535)<<16)}return o^=o>>>13,o=1540483477*(65535&o)+((1540483477*(o>>>16)&65535)<<16),o^=o>>>15,o>>>0},n.v3=r,e.exports=n}()},725:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getBucketedNumber=t.MAX_BUCKETED_NUMBER=void 0;var n=r(77),i=Math.pow(2,32);t.MAX_BUCKETED_NUMBER=1e5,t.getBucketedNumber=function(e){var r=n.v3(e,1)/i;return Math.floor(r*t.MAX_BUCKETED_NUMBER)}},352:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FeaturevisorSDK=t.getValueByType=void 0;var n=r(913),i=r(522),o=r(725);function a(e,t){if(void 0!==e)switch(t){case"string":return"string"==typeof e?e:void 0;case"integer":return parseInt(e,10);case"double":return parseFloat(e);case"boolean":return!0===e;case"array":return Array.isArray(e)?e:void 0;default:return e}}t.getValueByType=a;var u=function(){function e(e){e.onActivation&&(this.onActivation=e.onActivation),e.configureBucketValue&&(this.configureBucketValue=e.configureBucketValue);try{this.datafileReader=new n.DatafileReader("string"==typeof e.datafile?JSON.parse(e.datafile):e.datafile)}catch(e){console.error("Featurevisor could not parse the datafile"),console.error(e)}}return e.prototype.getFeature=function(e){return"string"==typeof e?this.datafileReader.getFeature(e):e},e.prototype.getBucketKey=function(e,t){var r=e.key,n="string"==typeof e.bucketBy?e.bucketBy:e.bucketBy.join("_");return"".concat(n,"_").concat(r)},e.prototype.getBucketValue=function(e,t){var r=this.getBucketKey(e,t),n=(0,o.getBucketedNumber)(r);return this.configureBucketValue?this.configureBucketValue(e,t,n):n},e.prototype.getVariation=function(e,t){void 0===t&&(t={});try{var r=this.getFeature(e);if(!r)return;var n=(0,i.getForcedVariation)(r,t,this.datafileReader);if(n)return n.value;var o=this.getBucketValue(r,t),a=(0,i.getBucketedVariation)(r,t,o,this.datafileReader);if(!a)return;return a.value}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.getVariationBoolean=function(e,t){return void 0===t&&(t={}),a(this.getVariation(e,t),"boolean")},e.prototype.getVariationString=function(e,t){return void 0===t&&(t={}),a(this.getVariation(e,t),"string")},e.prototype.getVariationInteger=function(e,t){return void 0===t&&(t={}),a(this.getVariation(e,t),"integer")},e.prototype.getVariationDouble=function(e,t){return void 0===t&&(t={}),a(this.getVariation(e,t),"double")},e.prototype.activate=function(e,t){void 0===t&&(t={});try{var r=this.getVariation(e,t);if(!r)return;if(this.onActivation){var n={};this.datafileReader.getAllAttributes().filter((function(e){return!0===e.capture})).forEach((function(e){void 0!==t[e.key]&&(n[e.key]=t[e.key])})),this.onActivation(e,r,t,n)}return r}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.activateBoolean=function(e,t){return void 0===t&&(t={}),a(this.activate(e,t),"boolean")},e.prototype.activateString=function(e,t){return void 0===t&&(t={}),a(this.activate(e,t),"string")},e.prototype.activateInteger=function(e,t){return void 0===t&&(t={}),a(this.activate(e,t),"integer")},e.prototype.activateDouble=function(e,t){return void 0===t&&(t={}),a(this.activate(e,t),"double")},e.prototype.getVariable=function(e,t,r){void 0===r&&(r={});try{var n=this.getFeature(e);if(!n)return;var o=(0,i.getForcedVariableValue)(n,t,r,this.datafileReader);if(void 0!==o)return o;var a=this.getBucketValue(n,r);return(0,i.getBucketedVariableValue)(n,t,r,a,this.datafileReader)}catch(e){return void console.error("[Featurevisor]",e)}},e.prototype.getVariableBoolean=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"boolean")},e.prototype.getVariableString=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"string")},e.prototype.getVariableInteger=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"integer")},e.prototype.getVariableDouble=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"double")},e.prototype.getVariableArray=function(e,t,r){return void 0===r&&(r={}),a(this.getVariable(e,t,r),"array")},e}();t.FeaturevisorSDK=u},243:(e,t)=>{"use strict";function r(e,t){var r=e.attribute,n=e.operator,i=e.value;if("equals"===n)return t[r]===i;if("notEquals"===n)return t[r]!==i;if("string"==typeof t[r]&&Array.isArray(i)){var o=t[r];if("in"===n)return-1!==i.indexOf(o);if("notIn"===n)return-1===i.indexOf(o)}else if("string"==typeof t[r]&&"string"==typeof i){if(o=t[r],"contains"===n)return-1!==o.indexOf(i);if("notContains"===n)return-1===o.indexOf(i);if("startsWith"===n)return o.startsWith(i);if("endsWith"===n)return o.endsWith(i)}else if("number"==typeof t[r]&&"number"==typeof i){if(o=t[r],"greaterThan"===n)return o>i;if("greaterThanOrEquals"===n)return o>=i;if("lessThan"===n)return o<i;if("lessThanOrEquals"===n)return o<=i}return!1}Object.defineProperty(t,"__esModule",{value:!0}),t.allConditionsAreMatched=t.conditionIsMatched=void 0,t.conditionIsMatched=r,t.allConditionsAreMatched=function e(t,n){return"attribute"in t?r(t,n):"and"in t&&Array.isArray(t.and)?t.and.every((function(t){return e(t,n)})):"or"in t&&Array.isArray(t.or)?t.or.some((function(t){return e(t,n)})):!!Array.isArray(t)&&t.every((function(t){return e(t,n)}))}},913:(e,t)=>{"use strict";function r(e,t){if("string"==typeof e[t]&&"*"!==e[t])try{e[t]=JSON.parse(e[t])}catch(e){console.error("Error parsing JSON",e)}return e}Object.defineProperty(t,"__esModule",{value:!0}),t.DatafileReader=t.parseJsonConditionsIfStringified=void 0,t.parseJsonConditionsIfStringified=r;var n=function(){function e(e){this.schemaVersion=e.schemaVersion,this.revision=e.revision,this.segments=e.segments,this.attributes=e.attributes,this.features=e.features}return e.prototype.getRevision=function(){return this.revision},e.prototype.getSchemaVersion=function(){return this.schemaVersion},e.prototype.getAllAttributes=function(){return this.attributes},e.prototype.getAttribute=function(e){return this.attributes.find((function(t){return t.key===e}))},e.prototype.getSegment=function(e){var t=this.segments.find((function(t){return t.key===e}));if(t)return r(t,"conditions")},e.prototype.getFeature=function(e){var t=this.features.find((function(t){return t.key===e}));if(t)return t},e}();t.DatafileReader=n},522:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getBucketedVariableValue=t.getForcedVariableValue=t.getBucketedVariation=t.getForcedVariation=t.getMatchedAllocation=t.getMatchedTraffic=void 0;var n=r(590),i=r(243);function o(e,t,r,i){return e.find((function(e){return!(r>e.percentage||!(0,n.allGroupSegmentsAreMatched)("string"==typeof e.segments&&"*"!==e.segments?JSON.parse(e.segments):e.segments,t,i))}))}function a(e,t){for(var r=0,n=0,i=e.allocation;n<i.length;n++){var o=i[n];if(t<=(r+=o.percentage))return o}}function u(e,t,r){if(e.force)return e.force.find((function(e){return e.conditions?(0,i.allConditionsAreMatched)(e.conditions,t):!!e.segments&&(0,n.allGroupSegmentsAreMatched)(e.segments,t,r)}))}function s(e,t,r,n){var i=o(e.traffic,t,r,n);if(i){var u=a(i,r);if(u){var s=u.variation,c=e.variations.find((function(e){return e.value===s}));if(c)return c}}}t.getMatchedTraffic=o,t.getMatchedAllocation=a,t.getForcedVariation=function(e,t,r){var n=u(e,t,r);if(n&&n.variation)return e.variations.find((function(e){return e.value===n.variation}))},t.getBucketedVariation=s,t.getForcedVariableValue=function(e,t,r,n){var i=u(e,r,n);if(i&&i.variables)return i.variables[t]},t.getBucketedVariableValue=function(e,t,r,o,a){var u,c=e.variablesSchema;if(c&&!c.find((function(e){e.key}))){var f=s(e,r,o,a);if(f){var d=null===(u=f.variables)||void 0===u?void 0:u.find((function(e){return e.key===t}));if(d){if(d.overrides){var l=d.overrides.find((function(e){return e.conditions?(0,i.allConditionsAreMatched)("string"==typeof e.conditions?JSON.parse(e.conditions):e.conditions,r):!!e.segments&&(0,n.allGroupSegmentsAreMatched)("string"==typeof e.segments&&"*"!==e.segments?JSON.parse(e.segments):e.segments,r,a)}));if(l)return l.value}return d.value}}}}},97:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(725),t),i(r(352),t)},590:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.allGroupSegmentsAreMatched=t.segmentIsMatched=void 0;var n=r(243);function i(e,t){return(0,n.allConditionsAreMatched)(e.conditions,t)}t.segmentIsMatched=i,t.allGroupSegmentsAreMatched=function e(t,r,n){if("*"===t)return!0;if("string"==typeof t){var o=n.getSegment(t);return!!o&&i(o,r)}if("object"==typeof t){if("and"in t&&Array.isArray(t.and))return t.and.every((function(t){return e(t,r,n)}));if("or"in t&&Array.isArray(t.or))return t.or.some((function(t){return e(t,r,n)}))}return!!Array.isArray(t)&&t.every((function(t){return e(t,r,n)}))}}},t={},function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}(97);var e,t}));
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAA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AAQA,EAAOD,QAASuJ,GAGpEtJ,EAAOD,OACf,CCnB0BuJ,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/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;\nexport interface SdkOptions {\n datafile: DatafileContent | string;\n onActivation?: ActivationCallback;\n configureBucketValue?: ConfigureBucketValue;\n}\n\n// union of VariableValue and VariationValue\ntype FieldType = \"string\" | \"integer\" | \"double\" | \"boolean\" | \"array\";\ntype ValueType = string | number | boolean | string[] | null | undefined;\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 default:\n return value;\n }\n}\n\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 try {\n this.datafileReader = new DatafileReader(\n typeof options.datafile === \"string\" ? JSON.parse(options.datafile) : options.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 undefined;\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","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 // @TODO: introduce `not`\n\n if (Array.isArray(conditions)) {\n return conditions.every((c) => allConditionsAreMatched(c, attributes));\n }\n\n return false;\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 v.key === variableKey;\n });\n\n if (variableSchema) {\n return undefined;\n }\n\n const variation = getBucketedVariation(feature, attributes, bucketValue, datafileReader);\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 undefined;\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\";\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\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","datafileReader","DatafileReader","datafile","JSON","parse","e","console","error","getFeature","featureKey","getBucketKey","feature","attributes","prefix","bucketBy","join","getBucketValue","getBucketedNumber","getVariation","forcedVariation","getForcedVariation","bucketValue","variation","getBucketedVariation","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","FeaturevisorSDK","conditionIsMatched","condition","attribute","operator","valueInAttributes","indexOf","startsWith","endsWith","allConditionsAreMatched","conditions","and","every","c","or","some","parseJsonConditionsIfStringified","record","datafileJson","schemaVersion","revision","segments","features","getRevision","getSchemaVersion","getAttribute","attributeKey","find","getSegment","segmentKey","segment","s","getMatchedTraffic","traffic","percentage","allGroupSegmentsAreMatched","getMatchedAllocation","matchedTraffic","total","allocation","findForceFromFeature","force","f","variations","v","variables","variablesSchema","variableFromVariation","overrides","override","o","segmentIsMatched","groupSegments","groupSegment","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","call"],"sourceRoot":""}
|
package/lib/bucket.d.ts
ADDED
package/lib/bucket.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as murmurhash from "murmurhash";
|
|
2
|
+
var HASH_SEED = 1;
|
|
3
|
+
var MAX_HASH_VALUE = Math.pow(2, 32);
|
|
4
|
+
export var MAX_BUCKETED_NUMBER = 100000; // 100% * 1000 to include three decimal places in the same integer value
|
|
5
|
+
export function getBucketedNumber(bucketKey) {
|
|
6
|
+
var hashValue = murmurhash.v3(bucketKey, HASH_SEED);
|
|
7
|
+
var ratio = hashValue / MAX_HASH_VALUE;
|
|
8
|
+
return Math.floor(ratio * MAX_BUCKETED_NUMBER);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=bucket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bucket.js","sourceRoot":"","sources":["../src/bucket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,IAAM,SAAS,GAAG,CAAC,CAAC;AACpB,IAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAEvC,MAAM,CAAC,IAAM,mBAAmB,GAAG,MAAM,CAAC,CAAC,wEAAwE;AAEnH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,IAAM,SAAS,GAAG,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IACtD,IAAM,KAAK,GAAG,SAAS,GAAG,cAAc,CAAC;IAEzC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,mBAAmB,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Attributes, VariationValue, VariableValue, Feature, DatafileContent, BucketValue, FeatureKey } from "@featurevisor/types";
|
|
2
|
+
export type ActivationCallback = (featureName: string, variation: VariationValue, attributes: Attributes, captureAttributes: Attributes) => void;
|
|
3
|
+
export type ConfigureBucketValue = (feature: any, attributes: any, bucketValue: BucketValue) => BucketValue;
|
|
4
|
+
export interface SdkOptions {
|
|
5
|
+
datafile: DatafileContent | string;
|
|
6
|
+
onActivation?: ActivationCallback;
|
|
7
|
+
configureBucketValue?: ConfigureBucketValue;
|
|
8
|
+
}
|
|
9
|
+
type FieldType = "string" | "integer" | "double" | "boolean" | "array";
|
|
10
|
+
type ValueType = string | number | boolean | string[] | null | undefined;
|
|
11
|
+
export declare function getValueByType(value: ValueType, fieldType: FieldType): ValueType;
|
|
12
|
+
export declare class FeaturevisorSDK {
|
|
13
|
+
private onActivation?;
|
|
14
|
+
private datafileReader;
|
|
15
|
+
private configureBucketValue?;
|
|
16
|
+
constructor(options: SdkOptions);
|
|
17
|
+
private getFeature;
|
|
18
|
+
/**
|
|
19
|
+
* Bucketing
|
|
20
|
+
*/
|
|
21
|
+
private getBucketKey;
|
|
22
|
+
private getBucketValue;
|
|
23
|
+
/**
|
|
24
|
+
* Variation
|
|
25
|
+
*/
|
|
26
|
+
getVariation(featureKey: FeatureKey | Feature, attributes?: Attributes): VariationValue | undefined;
|
|
27
|
+
getVariationBoolean(featureKey: FeatureKey | Feature, attributes?: Attributes): boolean | undefined;
|
|
28
|
+
getVariationString(featureKey: FeatureKey | Feature, attributes?: Attributes): string | undefined;
|
|
29
|
+
getVariationInteger(featureKey: FeatureKey | Feature, attributes?: Attributes): number | undefined;
|
|
30
|
+
getVariationDouble(featureKey: FeatureKey | Feature, attributes?: Attributes): number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Activate
|
|
33
|
+
*/
|
|
34
|
+
activate(featureKey: FeatureKey, attributes?: Attributes): VariationValue | undefined;
|
|
35
|
+
activateBoolean(featureKey: FeatureKey, attributes?: Attributes): boolean | undefined;
|
|
36
|
+
activateString(featureKey: FeatureKey, attributes?: Attributes): string | undefined;
|
|
37
|
+
activateInteger(featureKey: FeatureKey, attributes?: Attributes): number | undefined;
|
|
38
|
+
activateDouble(featureKey: FeatureKey, attributes?: Attributes): number | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Variable
|
|
41
|
+
*/
|
|
42
|
+
getVariable(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): VariableValue | undefined;
|
|
43
|
+
getVariableBoolean(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): boolean | undefined;
|
|
44
|
+
getVariableString(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): string | undefined;
|
|
45
|
+
getVariableInteger(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): number | undefined;
|
|
46
|
+
getVariableDouble(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): number | undefined;
|
|
47
|
+
getVariableArray(featureKey: FeatureKey | Feature, variableKey: string, attributes?: Attributes): string[] | undefined;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { DatafileReader } from "./datafileReader";
|
|
2
|
+
import { getBucketedVariation, getBucketedVariableValue, getForcedVariation, getForcedVariableValue, } from "./feature";
|
|
3
|
+
import { getBucketedNumber } from "./bucket";
|
|
4
|
+
export function getValueByType(value, fieldType) {
|
|
5
|
+
if (value === undefined) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
switch (fieldType) {
|
|
9
|
+
case "string":
|
|
10
|
+
return typeof value === "string" ? value : undefined;
|
|
11
|
+
case "integer":
|
|
12
|
+
return parseInt(value, 10);
|
|
13
|
+
case "double":
|
|
14
|
+
return parseFloat(value);
|
|
15
|
+
case "boolean":
|
|
16
|
+
return value === true;
|
|
17
|
+
case "array":
|
|
18
|
+
return Array.isArray(value) ? value : undefined;
|
|
19
|
+
default:
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
var FeaturevisorSDK = /** @class */ (function () {
|
|
24
|
+
function FeaturevisorSDK(options) {
|
|
25
|
+
if (options.onActivation) {
|
|
26
|
+
this.onActivation = options.onActivation;
|
|
27
|
+
}
|
|
28
|
+
if (options.configureBucketValue) {
|
|
29
|
+
this.configureBucketValue = options.configureBucketValue;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
this.datafileReader = new DatafileReader(typeof options.datafile === "string" ? JSON.parse(options.datafile) : options.datafile);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
console.error("Featurevisor could not parse the datafile");
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
FeaturevisorSDK.prototype.getFeature = function (featureKey) {
|
|
40
|
+
return typeof featureKey === "string"
|
|
41
|
+
? this.datafileReader.getFeature(featureKey) // only key provided
|
|
42
|
+
: featureKey; // full feature provided
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Bucketing
|
|
46
|
+
*/
|
|
47
|
+
FeaturevisorSDK.prototype.getBucketKey = function (feature, attributes) {
|
|
48
|
+
var featureKey = feature.key;
|
|
49
|
+
var prefix = typeof feature.bucketBy === "string" ? feature.bucketBy : feature.bucketBy.join("_");
|
|
50
|
+
return "".concat(prefix, "_").concat(featureKey);
|
|
51
|
+
};
|
|
52
|
+
FeaturevisorSDK.prototype.getBucketValue = function (feature, attributes) {
|
|
53
|
+
var bucketKey = this.getBucketKey(feature, attributes);
|
|
54
|
+
var value = getBucketedNumber(bucketKey);
|
|
55
|
+
if (this.configureBucketValue) {
|
|
56
|
+
return this.configureBucketValue(feature, attributes, value);
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Variation
|
|
62
|
+
*/
|
|
63
|
+
FeaturevisorSDK.prototype.getVariation = function (featureKey, attributes) {
|
|
64
|
+
if (attributes === void 0) { attributes = {}; }
|
|
65
|
+
try {
|
|
66
|
+
var feature = this.getFeature(featureKey);
|
|
67
|
+
if (!feature) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
var forcedVariation = getForcedVariation(feature, attributes, this.datafileReader);
|
|
71
|
+
if (forcedVariation) {
|
|
72
|
+
return forcedVariation.value;
|
|
73
|
+
}
|
|
74
|
+
var bucketValue = this.getBucketValue(feature, attributes);
|
|
75
|
+
var variation = getBucketedVariation(feature, attributes, bucketValue, this.datafileReader);
|
|
76
|
+
if (!variation) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return variation.value;
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
console.error("[Featurevisor]", e);
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
FeaturevisorSDK.prototype.getVariationBoolean = function (featureKey, attributes) {
|
|
87
|
+
if (attributes === void 0) { attributes = {}; }
|
|
88
|
+
var variationValue = this.getVariation(featureKey, attributes);
|
|
89
|
+
return getValueByType(variationValue, "boolean");
|
|
90
|
+
};
|
|
91
|
+
FeaturevisorSDK.prototype.getVariationString = function (featureKey, attributes) {
|
|
92
|
+
if (attributes === void 0) { attributes = {}; }
|
|
93
|
+
var variationValue = this.getVariation(featureKey, attributes);
|
|
94
|
+
return getValueByType(variationValue, "string");
|
|
95
|
+
};
|
|
96
|
+
FeaturevisorSDK.prototype.getVariationInteger = function (featureKey, attributes) {
|
|
97
|
+
if (attributes === void 0) { attributes = {}; }
|
|
98
|
+
var variationValue = this.getVariation(featureKey, attributes);
|
|
99
|
+
return getValueByType(variationValue, "integer");
|
|
100
|
+
};
|
|
101
|
+
FeaturevisorSDK.prototype.getVariationDouble = function (featureKey, attributes) {
|
|
102
|
+
if (attributes === void 0) { attributes = {}; }
|
|
103
|
+
var variationValue = this.getVariation(featureKey, attributes);
|
|
104
|
+
return getValueByType(variationValue, "double");
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Activate
|
|
108
|
+
*/
|
|
109
|
+
FeaturevisorSDK.prototype.activate = function (featureKey, attributes) {
|
|
110
|
+
if (attributes === void 0) { attributes = {}; }
|
|
111
|
+
try {
|
|
112
|
+
var variationValue = this.getVariation(featureKey, attributes);
|
|
113
|
+
if (!variationValue) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
if (this.onActivation) {
|
|
117
|
+
var captureAttributes_1 = {};
|
|
118
|
+
var attributesForCapturing = this.datafileReader
|
|
119
|
+
.getAllAttributes()
|
|
120
|
+
.filter(function (a) { return a.capture === true; });
|
|
121
|
+
attributesForCapturing.forEach(function (a) {
|
|
122
|
+
if (typeof attributes[a.key] !== "undefined") {
|
|
123
|
+
captureAttributes_1[a.key] = attributes[a.key];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
this.onActivation(featureKey, variationValue, attributes, captureAttributes_1);
|
|
127
|
+
}
|
|
128
|
+
return variationValue;
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
console.error("[Featurevisor]", e);
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
FeaturevisorSDK.prototype.activateBoolean = function (featureKey, attributes) {
|
|
136
|
+
if (attributes === void 0) { attributes = {}; }
|
|
137
|
+
var variationValue = this.activate(featureKey, attributes);
|
|
138
|
+
return getValueByType(variationValue, "boolean");
|
|
139
|
+
};
|
|
140
|
+
FeaturevisorSDK.prototype.activateString = function (featureKey, attributes) {
|
|
141
|
+
if (attributes === void 0) { attributes = {}; }
|
|
142
|
+
var variationValue = this.activate(featureKey, attributes);
|
|
143
|
+
return getValueByType(variationValue, "string");
|
|
144
|
+
};
|
|
145
|
+
FeaturevisorSDK.prototype.activateInteger = function (featureKey, attributes) {
|
|
146
|
+
if (attributes === void 0) { attributes = {}; }
|
|
147
|
+
var variationValue = this.activate(featureKey, attributes);
|
|
148
|
+
return getValueByType(variationValue, "integer");
|
|
149
|
+
};
|
|
150
|
+
FeaturevisorSDK.prototype.activateDouble = function (featureKey, attributes) {
|
|
151
|
+
if (attributes === void 0) { attributes = {}; }
|
|
152
|
+
var variationValue = this.activate(featureKey, attributes);
|
|
153
|
+
return getValueByType(variationValue, "double");
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Variable
|
|
157
|
+
*/
|
|
158
|
+
FeaturevisorSDK.prototype.getVariable = function (featureKey, variableKey, attributes) {
|
|
159
|
+
if (attributes === void 0) { attributes = {}; }
|
|
160
|
+
try {
|
|
161
|
+
var feature = this.getFeature(featureKey);
|
|
162
|
+
if (!feature) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
var forcedVariableValue = getForcedVariableValue(feature, variableKey, attributes, this.datafileReader);
|
|
166
|
+
if (typeof forcedVariableValue !== "undefined") {
|
|
167
|
+
return forcedVariableValue;
|
|
168
|
+
}
|
|
169
|
+
var bucketValue = this.getBucketValue(feature, attributes);
|
|
170
|
+
return getBucketedVariableValue(feature, variableKey, attributes, bucketValue, this.datafileReader);
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
console.error("[Featurevisor]", e);
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
FeaturevisorSDK.prototype.getVariableBoolean = function (featureKey, variableKey, attributes) {
|
|
178
|
+
if (attributes === void 0) { attributes = {}; }
|
|
179
|
+
var variableValue = this.getVariable(featureKey, variableKey, attributes);
|
|
180
|
+
return getValueByType(variableValue, "boolean");
|
|
181
|
+
};
|
|
182
|
+
FeaturevisorSDK.prototype.getVariableString = function (featureKey, variableKey, attributes) {
|
|
183
|
+
if (attributes === void 0) { attributes = {}; }
|
|
184
|
+
var variableValue = this.getVariable(featureKey, variableKey, attributes);
|
|
185
|
+
return getValueByType(variableValue, "string");
|
|
186
|
+
};
|
|
187
|
+
FeaturevisorSDK.prototype.getVariableInteger = function (featureKey, variableKey, attributes) {
|
|
188
|
+
if (attributes === void 0) { attributes = {}; }
|
|
189
|
+
var variableValue = this.getVariable(featureKey, variableKey, attributes);
|
|
190
|
+
return getValueByType(variableValue, "integer");
|
|
191
|
+
};
|
|
192
|
+
FeaturevisorSDK.prototype.getVariableDouble = function (featureKey, variableKey, attributes) {
|
|
193
|
+
if (attributes === void 0) { attributes = {}; }
|
|
194
|
+
var variableValue = this.getVariable(featureKey, variableKey, attributes);
|
|
195
|
+
return getValueByType(variableValue, "double");
|
|
196
|
+
};
|
|
197
|
+
FeaturevisorSDK.prototype.getVariableArray = function (featureKey, variableKey, attributes) {
|
|
198
|
+
if (attributes === void 0) { attributes = {}; }
|
|
199
|
+
var variableValue = this.getVariable(featureKey, variableKey, attributes);
|
|
200
|
+
return getValueByType(variableValue, "array");
|
|
201
|
+
};
|
|
202
|
+
return FeaturevisorSDK;
|
|
203
|
+
}());
|
|
204
|
+
export { FeaturevisorSDK };
|
|
205
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAUA,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;AAoB7C,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,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,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D,CAAC,AAvRD,IAuRC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Attributes, Condition, PlainCondition } from "@featurevisor/types";
|
|
2
|
+
export declare function conditionIsMatched(condition: PlainCondition, attributes: Attributes): boolean;
|
|
3
|
+
export declare function allConditionsAreMatched(conditions: Condition[] | Condition, attributes: Attributes): boolean;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export function conditionIsMatched(condition, attributes) {
|
|
2
|
+
var attribute = condition.attribute, operator = condition.operator, value = condition.value;
|
|
3
|
+
if (operator === "equals") {
|
|
4
|
+
return attributes[attribute] === value;
|
|
5
|
+
}
|
|
6
|
+
else if (operator === "notEquals") {
|
|
7
|
+
return attributes[attribute] !== value;
|
|
8
|
+
}
|
|
9
|
+
else if (typeof attributes[attribute] === "string" && Array.isArray(value)) {
|
|
10
|
+
// array
|
|
11
|
+
var valueInAttributes = attributes[attribute];
|
|
12
|
+
if (operator === "in") {
|
|
13
|
+
return value.indexOf(valueInAttributes) !== -1;
|
|
14
|
+
}
|
|
15
|
+
else if (operator === "notIn") {
|
|
16
|
+
return value.indexOf(valueInAttributes) === -1;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if (typeof attributes[attribute] === "string" && typeof value === "string") {
|
|
20
|
+
// string
|
|
21
|
+
var valueInAttributes = attributes[attribute];
|
|
22
|
+
if (operator === "contains") {
|
|
23
|
+
return valueInAttributes.indexOf(value) !== -1;
|
|
24
|
+
}
|
|
25
|
+
else if (operator === "notContains") {
|
|
26
|
+
return valueInAttributes.indexOf(value) === -1;
|
|
27
|
+
}
|
|
28
|
+
else if (operator === "startsWith") {
|
|
29
|
+
return valueInAttributes.startsWith(value);
|
|
30
|
+
}
|
|
31
|
+
else if (operator === "endsWith") {
|
|
32
|
+
return valueInAttributes.endsWith(value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else if (typeof attributes[attribute] === "number" && typeof value === "number") {
|
|
36
|
+
// numeric
|
|
37
|
+
var valueInAttributes = attributes[attribute];
|
|
38
|
+
if (operator === "greaterThan") {
|
|
39
|
+
return valueInAttributes > value;
|
|
40
|
+
}
|
|
41
|
+
else if (operator === "greaterThanOrEquals") {
|
|
42
|
+
return valueInAttributes >= value;
|
|
43
|
+
}
|
|
44
|
+
else if (operator === "lessThan") {
|
|
45
|
+
return valueInAttributes < value;
|
|
46
|
+
}
|
|
47
|
+
else if (operator === "lessThanOrEquals") {
|
|
48
|
+
return valueInAttributes <= value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
export function allConditionsAreMatched(conditions, attributes) {
|
|
54
|
+
if ("attribute" in conditions) {
|
|
55
|
+
return conditionIsMatched(conditions, attributes);
|
|
56
|
+
}
|
|
57
|
+
if ("and" in conditions && Array.isArray(conditions.and)) {
|
|
58
|
+
return conditions.and.every(function (c) { return allConditionsAreMatched(c, attributes); });
|
|
59
|
+
}
|
|
60
|
+
if ("or" in conditions && Array.isArray(conditions.or)) {
|
|
61
|
+
return conditions.or.some(function (c) { return allConditionsAreMatched(c, attributes); });
|
|
62
|
+
}
|
|
63
|
+
// @TODO: introduce `not`
|
|
64
|
+
if (Array.isArray(conditions)) {
|
|
65
|
+
return conditions.every(function (c) { return allConditionsAreMatched(c, attributes); });
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=conditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,kBAAkB,CAAC,SAAyB,EAAE,UAAsB;IAC1E,IAAA,SAAS,GAAsB,SAAS,UAA/B,EAAE,QAAQ,GAAY,SAAS,SAArB,EAAE,KAAK,GAAK,SAAS,MAAd,CAAe;IAEjD,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACzB,OAAO,UAAU,CAAC,SAAS,CAAC,KAA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EAAtC,CAAsC,CAAC,CAAC;KACxE;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Feature, Segment, DatafileContent, Attribute, AttributeKey, SegmentKey, FeatureKey } from "@featurevisor/types";
|
|
2
|
+
export declare function parseJsonConditionsIfStringified<T>(record: T, key: string): T;
|
|
3
|
+
export declare class DatafileReader {
|
|
4
|
+
private schemaVersion;
|
|
5
|
+
private revision;
|
|
6
|
+
private attributes;
|
|
7
|
+
private segments;
|
|
8
|
+
private features;
|
|
9
|
+
constructor(datafileJson: DatafileContent);
|
|
10
|
+
getRevision(): string;
|
|
11
|
+
getSchemaVersion(): string;
|
|
12
|
+
getAllAttributes(): Attribute[];
|
|
13
|
+
getAttribute(attributeKey: AttributeKey): Attribute | undefined;
|
|
14
|
+
getSegment(segmentKey: SegmentKey): Segment | undefined;
|
|
15
|
+
getFeature(featureKey: FeatureKey): Feature | undefined;
|
|
16
|
+
}
|