@guardian/ab-core
Advanced tools
Comparing version 0.2.1-alpha.11 to 0.2.1-alpha.12
import { OphanAPI, CoreAPI, AbTestConfig } from './types'; | ||
export declare class AB { | ||
private _allRunnableTests; | ||
private _isUserInVariant; | ||
@@ -10,2 +11,3 @@ private _firstRunnableTest; | ||
constructor(config: AbTestConfig); | ||
get allRunnableTests(): CoreAPI['allRunnableTests']; | ||
get firstRunnableTest(): CoreAPI['firstRunnableTest']; | ||
@@ -12,0 +14,0 @@ get runnableTest(): CoreAPI['runnableTest']; |
import { AB } from './ab'; | ||
import { ABTestAPI as _ABTestAPI, CoreAPI as _CoreAPI, AbTestConfig as _AbTestConfig } from './types'; | ||
import { ABTest as _ABTest, ABTestAPI as _ABTestAPI, AbTestConfig as _AbTestConfig, Runnable as _Runnable, Variant as _Variant } from './types'; | ||
export { AB }; | ||
export declare type ABTest = _ABTest; | ||
export declare type ABTestAPI = _ABTestAPI; | ||
export declare type CoreAPI = _CoreAPI; | ||
export declare type AbTestConfig = _AbTestConfig; | ||
export declare type Runnable = _Runnable<_ABTest>; | ||
export declare type Variant = _Variant; |
@@ -1,2 +0,2 @@ | ||
function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var t=function(){},n=function(e,t){return t({abTestRegister:e})},r=function(e,t){var n={variantName:e.id,complete:t};return e.campaignCode&&(n.campaignCodes=[e.campaignCode]),n},i=function(e){return e.variants.every(function(e){return"function"==typeof e.impression})},s=function(e,i,s){return function(a){var u=a.variantToRun,o=(e?u.success:u.impression)||t;try{o(function(e,t,i,s){var a,u=((a={})[e.id]=r(t,i),a);return function(){return n(u,s)}}(a,u,e,s))}catch(e){i(e,{},!1)}}};exports.AB=function(){function t(t){var a=t.serverSideTests,u=t.errorReporter,o=t.ophanRecord,c=function(t){var n=t.mvtMaxValue,r=void 0===n?1e6:n,i=t.mvtId,s=t.pageIsSensitive,a=t.abTestSwitches,u=t.forcedTestVariant,o=t.forcedTestException,c=t.arrayOfTestObjects,f=void 0===c?[]:c,v=function(t){var n,c,f=function(e){var t=r*e.audienceOffset;return i&&i>t&&i<=t+r*e.audience?e.variants[i%e.variants.length]:null}(t),v=u&&u.testId===t.id&&u.variant||f;return o!==t.id&&function(e){var t,n=(t=e.expiry,(new Date).valueOf()>new Date(t).setHours(23,59,59,59)),r=!!e.showForSensitive,i=a[e.id]&&!!a[e.id],u=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&u}(t)&&v&&(c="notintest"!==(n=v).id,n.canRun?n.canRun()&&c:c)?e({},t,{variantToRun:v}):null};return{runnableTest:v,firstRunnableTest:function(e){return e.map(function(e){return v(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return(n=f,n.reduce(function(e,t){var n=v(t);return n?[].concat(e,[n]):e},[])).some(function(n){return n.id===e&&n.variantToRun.id===t});var n}}}({mvtMaxValue:t.mvtMaxValue,mvtId:t.mvtId,pageIsSensitive:t.pageIsSensitive,abTestSwitches:t.abTestSwitches,forcedTestVariant:t.forcedTestVariant,forcedTestException:t.forcedTestException,arrayOfTestObjects:t.arrayOfTestObjects}),f=function(e){var t=e.serverSideTests,a=void 0===t?{}:t,u=e.errorReporter,o=void 0===u?function(){}:u,c=e.ophanRecord,f=void 0===c?function(){}:c;return{registerCompleteEvents:function(e){return e.forEach(s(!0,o,f))},registerImpressionEvents:function(e){return e.filter(i).forEach(s(!1,o,f))},trackABTests:function(e){return n(function(e,t,n){try{var s={},a=Object.keys(n).filter(function(e){return!!n[e]});return e.filter(function(e){return!i(e)}).forEach(function(e){s[e.id]=r(e.variantToRun,!1)}),a.forEach(function(e){s["ab"+e]=r({id:"inTest",test:function(){}},!1)}),s}catch(e){return t(e,{},!1),{}}}(e,o,a),f)}}}({serverSideTests:a,errorReporter:u,ophanRecord:o});this._firstRunnableTest=c.firstRunnableTest,this._runnableTest=c.runnableTest,this._isUserInVariant=c.isUserInVariant,this._registerCompleteEvents=f.registerCompleteEvents,this._registerImpressionEvents=f.registerImpressionEvents,this._trackABTests=f.trackABTests}var a;return(a=[{key:"firstRunnableTest",get:function(){return this._firstRunnableTest}},{key:"runnableTest",get:function(){return this._runnableTest}},{key:"isUserInVariant",get:function(){return this._isUserInVariant}},{key:"registerCompleteEvents",get:function(){return this._registerCompleteEvents}},{key:"registerImpressionEvents",get:function(){return this._registerImpressionEvents}},{key:"trackABTests",get:function(){return this._trackABTests}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,a),t}(); | ||
function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var t=function(){},n=function(e,t){return t({abTestRegister:e})},r=function(e,t){var n={variantName:e.id,complete:t};return e.campaignCode&&(n.campaignCodes=[e.campaignCode]),n},i=function(e){return e.variants.every(function(e){return"function"==typeof e.impression})},s=function(e,i,s){return function(a){var u=a.variantToRun,o=(e?u.success:u.impression)||t;try{o(function(e,t,i,s){var a,u=((a={})[e.id]=r(t,i),a);return function(){return n(u,s)}}(a,u,e,s))}catch(e){i(e,{},!1)}}};exports.AB=function(){function t(t){var a=t.serverSideTests,u=t.errorReporter,o=t.ophanRecord,c=function(t){var n=t.mvtMaxValue,r=void 0===n?1e6:n,i=t.mvtId,s=t.pageIsSensitive,a=t.abTestSwitches,u=t.forcedTestVariants,o=t.forcedTestException,c=t.arrayOfTestObjects,f=void 0===c?[]:c,v=function(t){var n,c,f=function(e){var t=r*e.audienceOffset;return i&&i>t&&i<=t+r*e.audience?e.variants[i%e.variants.length]:null}(t),v=function(e,t){return void 0!==t&&void 0!==t[e]&&t[e].variant}(t.id,u),l=v||f;return o!==t.id&&(v||function(e){var t,n=(t=e.expiry,(new Date).valueOf()>new Date(t).setHours(23,59,59,59)),r=!!e.showForSensitive,i=a["ab"+e.id]&&!!a["ab"+e.id],u=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&u}(t))&&l&&(v||(c="notintest"!==(n=l).id,n.canRun?n.canRun()&&c:c))?e({},t,{variantToRun:l}):null},l=function(e){return e.reduce(function(e,t){var n=v(t);return n?[].concat(e,[n]):e},[])};return{allRunnableTests:l,runnableTest:v,firstRunnableTest:function(e){return e.map(function(e){return v(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return l(f).some(function(n){return n.id===e&&n.variantToRun.id===t})}}}({mvtMaxValue:t.mvtMaxValue,mvtId:t.mvtId,pageIsSensitive:t.pageIsSensitive,abTestSwitches:t.abTestSwitches,forcedTestVariants:t.forcedTestVariants,forcedTestException:t.forcedTestException,arrayOfTestObjects:t.arrayOfTestObjects}),f=function(e){var t=e.serverSideTests,a=void 0===t?{}:t,u=e.errorReporter,o=void 0===u?function(){}:u,c=e.ophanRecord,f=void 0===c?function(){}:c;return{registerCompleteEvents:function(e){return e.forEach(s(!0,o,f))},registerImpressionEvents:function(e){e.filter(i).forEach(s(!1,o,f))},trackABTests:function(e){return n(function(e,t,n){try{var s={},a=Object.keys(n).filter(function(e){return!!n[e]});return e.filter(function(e){return!i(e)}).forEach(function(e){s[e.id]=r(e.variantToRun,!1)}),a.forEach(function(e){s["ab"+e]=r({id:"inTest",test:function(){}},!1)}),s}catch(e){return t(e,{},!1),{}}}(e,o,a),f)}}}({serverSideTests:a,errorReporter:u,ophanRecord:o});this._allRunnableTests=c.allRunnableTests,this._firstRunnableTest=c.firstRunnableTest,this._runnableTest=c.runnableTest,this._isUserInVariant=c.isUserInVariant,this._registerCompleteEvents=f.registerCompleteEvents,this._registerImpressionEvents=f.registerImpressionEvents,this._trackABTests=f.trackABTests}var a;return(a=[{key:"allRunnableTests",get:function(){return this._allRunnableTests}},{key:"firstRunnableTest",get:function(){return this._firstRunnableTest}},{key:"runnableTest",get:function(){return this._runnableTest}},{key:"isUserInVariant",get:function(){return this._isUserInVariant}},{key:"registerCompleteEvents",get:function(){return this._registerCompleteEvents}},{key:"registerImpressionEvents",get:function(){return this._registerImpressionEvents}},{key:"trackABTests",get:function(){return this._trackABTests}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,a),t}(); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
const e=()=>{},t=(e,t)=>t({abTestRegister:e}),r=(e,t)=>{const r={variantName:e.id,complete:t};return e.campaignCode&&(r.campaignCodes=[e.campaignCode]),r},s=e=>e.variants.every(e=>"function"==typeof e.impression),n=(s,n,i)=>a=>{const o=a.variantToRun,c=(s?o.success:o.impression)||e;try{c(((e,s,n,i)=>{const a={[e.id]:r(s,n)};return()=>t(a,i)})(a,o,s,i))}catch(e){n(e,{},!1)}};class i{constructor(e){const{mvtMaxValue:i,mvtId:a,pageIsSensitive:o,abTestSwitches:c,serverSideTests:u,forcedTestVariant:v,forcedTestException:T,errorReporter:d,ophanRecord:l,arrayOfTestObjects:p}=e,f=(e=>{const{mvtMaxValue:t=1e6,mvtId:r,pageIsSensitive:s,abTestSwitches:n,forcedTestVariant:i,forcedTestException:a,arrayOfTestObjects:o=[]}=e,c=e=>{const o=(e=>{const s=t*e.audienceOffset;return r&&r>s&&r<=s+t*e.audience?e.variants[r%e.variants.length]:null})(e),c=i&&i.testId===e.id&&i.variant||o;return a!==e.id&&(e=>{const t=(r=e.expiry,(new Date).valueOf()>new Date(r).setHours(23,59,59,59));var r;const i=!!e.showForSensitive,a=n[e.id]&&!!n[e.id],o=!e.canRun||e.canRun();return(!s||i)&&a&&!t&&o})(e)&&c&&(e=>{const t="notintest"!==e.id;return e.canRun?e.canRun()&&t:t})(c)?{...e,variantToRun:c}:null};return{runnableTest:c,firstRunnableTest:e=>e.map(e=>c(e)).find(e=>null!==e)||null,isUserInVariant:(e,t)=>{return(r=o,r.reduce((e,t)=>{const r=c(t);return r?[...e,r]:e},[])).some(r=>r.id===e&&r.variantToRun.id===t);var r}}})({mvtMaxValue:i,mvtId:a,pageIsSensitive:o,abTestSwitches:c,forcedTestVariant:v,forcedTestException:T,arrayOfTestObjects:p}),h=(e=>{const{serverSideTests:i={},errorReporter:a=(()=>{}),ophanRecord:o=(()=>{})}=e;return{registerCompleteEvents:e=>e.forEach(n(!0,a,o)),registerImpressionEvents:e=>e.filter(s).forEach(n(!1,a,o)),trackABTests:e=>t(((e,t,n)=>{try{const t={},i=Object.keys(n).filter(e=>!!n[e]);return e.filter(e=>!s(e)).forEach(e=>{t[e.id]=r(e.variantToRun,!1)}),i.forEach(e=>{t["ab"+e]=r({id:"inTest",test:()=>{}},!1)}),t}catch(e){return t(e,{},!1),{}}})(e,a,i),o)}})({serverSideTests:u,errorReporter:d,ophanRecord:l});this._firstRunnableTest=f.firstRunnableTest,this._runnableTest=f.runnableTest,this._isUserInVariant=f.isUserInVariant,this._registerCompleteEvents=h.registerCompleteEvents,this._registerImpressionEvents=h.registerImpressionEvents,this._trackABTests=h.trackABTests}get firstRunnableTest(){return this._firstRunnableTest}get runnableTest(){return this._runnableTest}get isUserInVariant(){return this._isUserInVariant}get registerCompleteEvents(){return this._registerCompleteEvents}get registerImpressionEvents(){return this._registerImpressionEvents}get trackABTests(){return this._trackABTests}}export{i as AB}; | ||
function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var t=function(){},n=function(e,t){return t({abTestRegister:e})},r=function(e,t){var n={variantName:e.id,complete:t};return e.campaignCode&&(n.campaignCodes=[e.campaignCode]),n},i=function(e){return e.variants.every(function(e){return"function"==typeof e.impression})},s=function(e,i,s){return function(a){var u=a.variantToRun,o=(e?u.success:u.impression)||t;try{o(function(e,t,i,s){var a,u=((a={})[e.id]=r(t,i),a);return function(){return n(u,s)}}(a,u,e,s))}catch(e){i(e,{},!1)}}},a=function(){function t(t){var a=t.serverSideTests,u=t.errorReporter,o=t.ophanRecord,c=function(t){var n=t.mvtMaxValue,r=void 0===n?1e6:n,i=t.mvtId,s=t.pageIsSensitive,a=t.abTestSwitches,u=t.forcedTestVariants,o=t.forcedTestException,c=t.arrayOfTestObjects,f=void 0===c?[]:c,v=function(t){var n,c,f=function(e){var t=r*e.audienceOffset;return i&&i>t&&i<=t+r*e.audience?e.variants[i%e.variants.length]:null}(t),v=function(e,t){return void 0!==t&&void 0!==t[e]&&t[e].variant}(t.id,u),l=v||f;return o!==t.id&&(v||function(e){var t,n=(t=e.expiry,(new Date).valueOf()>new Date(t).setHours(23,59,59,59)),r=!!e.showForSensitive,i=a["ab"+e.id]&&!!a["ab"+e.id],u=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&u}(t))&&l&&(v||(c="notintest"!==(n=l).id,n.canRun?n.canRun()&&c:c))?e({},t,{variantToRun:l}):null},l=function(e){return e.reduce(function(e,t){var n=v(t);return n?[].concat(e,[n]):e},[])};return{allRunnableTests:l,runnableTest:v,firstRunnableTest:function(e){return e.map(function(e){return v(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return l(f).some(function(n){return n.id===e&&n.variantToRun.id===t})}}}({mvtMaxValue:t.mvtMaxValue,mvtId:t.mvtId,pageIsSensitive:t.pageIsSensitive,abTestSwitches:t.abTestSwitches,forcedTestVariants:t.forcedTestVariants,forcedTestException:t.forcedTestException,arrayOfTestObjects:t.arrayOfTestObjects}),f=function(e){var t=e.serverSideTests,a=void 0===t?{}:t,u=e.errorReporter,o=void 0===u?function(){}:u,c=e.ophanRecord,f=void 0===c?function(){}:c;return{registerCompleteEvents:function(e){return e.forEach(s(!0,o,f))},registerImpressionEvents:function(e){e.filter(i).forEach(s(!1,o,f))},trackABTests:function(e){return n(function(e,t,n){try{var s={},a=Object.keys(n).filter(function(e){return!!n[e]});return e.filter(function(e){return!i(e)}).forEach(function(e){s[e.id]=r(e.variantToRun,!1)}),a.forEach(function(e){s["ab"+e]=r({id:"inTest",test:function(){}},!1)}),s}catch(e){return t(e,{},!1),{}}}(e,o,a),f)}}}({serverSideTests:a,errorReporter:u,ophanRecord:o});this._allRunnableTests=c.allRunnableTests,this._firstRunnableTest=c.firstRunnableTest,this._runnableTest=c.runnableTest,this._isUserInVariant=c.isUserInVariant,this._registerCompleteEvents=f.registerCompleteEvents,this._registerImpressionEvents=f.registerImpressionEvents,this._trackABTests=f.trackABTests}var a;return(a=[{key:"allRunnableTests",get:function(){return this._allRunnableTests}},{key:"firstRunnableTest",get:function(){return this._firstRunnableTest}},{key:"runnableTest",get:function(){return this._runnableTest}},{key:"isUserInVariant",get:function(){return this._isUserInVariant}},{key:"registerCompleteEvents",get:function(){return this._registerCompleteEvents}},{key:"registerImpressionEvents",get:function(){return this._registerImpressionEvents}},{key:"trackABTests",get:function(){return this._trackABTests}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,a),t}();export{a as AB}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).abCore={})}(this,function(e){function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n=function(){},r=function(e,t){return t({abTestRegister:e})},i=function(e,t){var n={variantName:e.id,complete:t};return e.campaignCode&&(n.campaignCodes=[e.campaignCode]),n},s=function(e){return e.variants.every(function(e){return"function"==typeof e.impression})},a=function(e,t,s){return function(a){var o=a.variantToRun,u=(e?o.success:o.impression)||n;try{u(function(e,t,n,s){var a,o=((a={})[e.id]=i(t,n),a);return function(){return r(o,s)}}(a,o,e,s))}catch(e){t(e,{},!1)}}};e.AB=function(){function e(e){var n=e.serverSideTests,o=e.errorReporter,u=e.ophanRecord,c=function(e){var n=e.mvtMaxValue,r=void 0===n?1e6:n,i=e.mvtId,s=e.pageIsSensitive,a=e.abTestSwitches,o=e.forcedTestVariant,u=e.forcedTestException,c=e.arrayOfTestObjects,f=void 0===c?[]:c,v=function(e){var n,c,f=function(e){var t=r*e.audienceOffset;return i&&i>t&&i<=t+r*e.audience?e.variants[i%e.variants.length]:null}(e),v=o&&o.testId===e.id&&o.variant||f;return u!==e.id&&function(e){var t,n=(t=e.expiry,(new Date).valueOf()>new Date(t).setHours(23,59,59,59)),r=!!e.showForSensitive,i=a[e.id]&&!!a[e.id],o=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&o}(e)&&v&&(c="notintest"!==(n=v).id,n.canRun?n.canRun()&&c:c)?t({},e,{variantToRun:v}):null};return{runnableTest:v,firstRunnableTest:function(e){return e.map(function(e){return v(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return(n=f,n.reduce(function(e,t){var n=v(t);return n?[].concat(e,[n]):e},[])).some(function(n){return n.id===e&&n.variantToRun.id===t});var n}}}({mvtMaxValue:e.mvtMaxValue,mvtId:e.mvtId,pageIsSensitive:e.pageIsSensitive,abTestSwitches:e.abTestSwitches,forcedTestVariant:e.forcedTestVariant,forcedTestException:e.forcedTestException,arrayOfTestObjects:e.arrayOfTestObjects}),f=function(e){var t=e.serverSideTests,n=void 0===t?{}:t,o=e.errorReporter,u=void 0===o?function(){}:o,c=e.ophanRecord,f=void 0===c?function(){}:c;return{registerCompleteEvents:function(e){return e.forEach(a(!0,u,f))},registerImpressionEvents:function(e){return e.filter(s).forEach(a(!1,u,f))},trackABTests:function(e){return r(function(e,t,n){try{var r={},a=Object.keys(n).filter(function(e){return!!n[e]});return e.filter(function(e){return!s(e)}).forEach(function(e){r[e.id]=i(e.variantToRun,!1)}),a.forEach(function(e){r["ab"+e]=i({id:"inTest",test:function(){}},!1)}),r}catch(e){return t(e,{},!1),{}}}(e,u,n),f)}}}({serverSideTests:n,errorReporter:o,ophanRecord:u});this._firstRunnableTest=c.firstRunnableTest,this._runnableTest=c.runnableTest,this._isUserInVariant=c.isUserInVariant,this._registerCompleteEvents=f.registerCompleteEvents,this._registerImpressionEvents=f.registerImpressionEvents,this._trackABTests=f.trackABTests}var n;return(n=[{key:"firstRunnableTest",get:function(){return this._firstRunnableTest}},{key:"runnableTest",get:function(){return this._runnableTest}},{key:"isUserInVariant",get:function(){return this._isUserInVariant}},{key:"registerCompleteEvents",get:function(){return this._registerCompleteEvents}},{key:"registerImpressionEvents",get:function(){return this._registerImpressionEvents}},{key:"trackABTests",get:function(){return this._trackABTests}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,n),e}()}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).abCore={})}(this,function(e){function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n=function(){},r=function(e,t){return t({abTestRegister:e})},i=function(e,t){var n={variantName:e.id,complete:t};return e.campaignCode&&(n.campaignCodes=[e.campaignCode]),n},s=function(e){return e.variants.every(function(e){return"function"==typeof e.impression})},a=function(e,t,s){return function(a){var o=a.variantToRun,u=(e?o.success:o.impression)||n;try{u(function(e,t,n,s){var a,o=((a={})[e.id]=i(t,n),a);return function(){return r(o,s)}}(a,o,e,s))}catch(e){t(e,{},!1)}}};e.AB=function(){function e(e){var n=e.serverSideTests,o=e.errorReporter,u=e.ophanRecord,c=function(e){var n=e.mvtMaxValue,r=void 0===n?1e6:n,i=e.mvtId,s=e.pageIsSensitive,a=e.abTestSwitches,o=e.forcedTestVariants,u=e.forcedTestException,c=e.arrayOfTestObjects,f=void 0===c?[]:c,v=function(e){var n,c,f=function(e){var t=r*e.audienceOffset;return i&&i>t&&i<=t+r*e.audience?e.variants[i%e.variants.length]:null}(e),v=function(e,t){return void 0!==t&&void 0!==t[e]&&t[e].variant}(e.id,o),l=v||f;return u!==e.id&&(v||function(e){var t,n=(t=e.expiry,(new Date).valueOf()>new Date(t).setHours(23,59,59,59)),r=!!e.showForSensitive,i=a["ab"+e.id]&&!!a["ab"+e.id],o=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&o}(e))&&l&&(v||(c="notintest"!==(n=l).id,n.canRun?n.canRun()&&c:c))?t({},e,{variantToRun:l}):null},l=function(e){return e.reduce(function(e,t){var n=v(t);return n?[].concat(e,[n]):e},[])};return{allRunnableTests:l,runnableTest:v,firstRunnableTest:function(e){return e.map(function(e){return v(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return l(f).some(function(n){return n.id===e&&n.variantToRun.id===t})}}}({mvtMaxValue:e.mvtMaxValue,mvtId:e.mvtId,pageIsSensitive:e.pageIsSensitive,abTestSwitches:e.abTestSwitches,forcedTestVariants:e.forcedTestVariants,forcedTestException:e.forcedTestException,arrayOfTestObjects:e.arrayOfTestObjects}),f=function(e){var t=e.serverSideTests,n=void 0===t?{}:t,o=e.errorReporter,u=void 0===o?function(){}:o,c=e.ophanRecord,f=void 0===c?function(){}:c;return{registerCompleteEvents:function(e){return e.forEach(a(!0,u,f))},registerImpressionEvents:function(e){e.filter(s).forEach(a(!1,u,f))},trackABTests:function(e){return r(function(e,t,n){try{var r={},a=Object.keys(n).filter(function(e){return!!n[e]});return e.filter(function(e){return!s(e)}).forEach(function(e){r[e.id]=i(e.variantToRun,!1)}),a.forEach(function(e){r["ab"+e]=i({id:"inTest",test:function(){}},!1)}),r}catch(e){return t(e,{},!1),{}}}(e,u,n),f)}}}({serverSideTests:n,errorReporter:o,ophanRecord:u});this._allRunnableTests=c.allRunnableTests,this._firstRunnableTest=c.firstRunnableTest,this._runnableTest=c.runnableTest,this._isUserInVariant=c.isUserInVariant,this._registerCompleteEvents=f.registerCompleteEvents,this._registerImpressionEvents=f.registerImpressionEvents,this._trackABTests=f.trackABTests}var n;return(n=[{key:"allRunnableTests",get:function(){return this._allRunnableTests}},{key:"firstRunnableTest",get:function(){return this._firstRunnableTest}},{key:"runnableTest",get:function(){return this._runnableTest}},{key:"isUserInVariant",get:function(){return this._isUserInVariant}},{key:"registerCompleteEvents",get:function(){return this._registerCompleteEvents}},{key:"registerImpressionEvents",get:function(){return this._registerImpressionEvents}},{key:"trackABTests",get:function(){return this._trackABTests}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,n),e}()}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -6,5 +6,6 @@ export declare type CoreAPIConfig = { | ||
abTestSwitches: Record<string, boolean>; | ||
forcedTestVariant?: { | ||
testId: ABTest['id']; | ||
variant: Variant; | ||
forcedTestVariants?: { | ||
[key: string]: { | ||
variant: Variant; | ||
}; | ||
}; | ||
@@ -15,2 +16,3 @@ forcedTestException?: ABTest['id']; | ||
export declare type CoreAPI = { | ||
allRunnableTests: (tests: ReadonlyArray<ABTest>) => ReadonlyArray<Runnable<ABTest>> | []; | ||
runnableTest: (test: ABTest) => Runnable<ABTest & { | ||
@@ -17,0 +19,0 @@ variantToRun: Variant; |
{ | ||
"version": "0.2.1-alpha.11+75b5583", | ||
"version": "0.2.1-alpha.12+a527980", | ||
"name": "@guardian/ab-core", | ||
@@ -77,3 +77,3 @@ "author": "The Guardian", | ||
}, | ||
"gitHead": "75b5583b449162fc3334d1433b60427cf4f6394a" | ||
"gitHead": "a527980c7594acd7c81c8ffe0b55b66f22d5e04e" | ||
} |
@@ -1,49 +0,5 @@ | ||
# ab-rendering | ||
# AB Core | ||
Client-side ab testing framework (broken out from Frontend) | ||
A client-side library for ab-testing | ||
## API | ||
### Initialise AB Tests | ||
```ts | ||
import { AB } from '@guardian/ab-rendering'; | ||
// See config object values below | ||
const coreConfig = {}; | ||
const ophanConfig = {}; | ||
const abTests = new AB(config); | ||
// Provides access to: | ||
// test being a single AB tests | ||
// [tests] being an array of ab tests | ||
abTests.runnableTest(test); | ||
abTests.firstRunnableTest([tests]); | ||
abTests.isUserInVariant(test, variantId); | ||
// [tests] being an array of *runnable* ab tests | ||
abTest.registerCompleteEvents([tests]); | ||
abTest.registerImpressionEvents([tests]); | ||
abTest.trackABTests([tests]); | ||
``` | ||
#### coreConfig | ||
| Config | Type | Example | Note | | ||
| ------------------- | ---------------------------------------------------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | | ||
| mvtMaxValue | number | `10000` | MVT % is calculated from 0 to mvtMaxValue | | ||
| mvtId | number | getCookie('mvtCookie') | The user's MVT ID to calculate what tests and variants they fall into | | ||
| pageIsSensitive | boolean | guardian.config.page.isSensitive | Sensitive pages must have explicit settings in AB tests | | ||
| abTestSwitches | Record<string, boolean> | {'TestOne': true} | An object containing all of the boolean values of abTestSwitches, in Frontend from page.config.switches.abTests | | ||
| forcedTestVariant | Optional: { testId: ABTest['id']; variant: Variant } | | In Frontend this might be set by the URL override, but otherwise can be used to force a user into a test and variant at init time | | ||
| forcedTestException | Optional: ABTest['id'] | | Can be used to force a user out of a test (in Frontend, again with url override) | | ||
| arrayOfTestObjects | ABTest[] | | Pass all tests definitions into the config | | ||
| ServerSideTets | ServerSideTests | | ServerSideTets are accessed via window config in Frontend | | ||
| errorReporter | ErrorReporterFunc | | Pass an error reporter, probably Sentry | | ||
| ophanRecord | OphanRecordFunction | | Probably Ophan's 'record' function | | ||
## TODO | ||
- Generate flow types from Typescript definition https://github.com/joarwilk/flowgen | ||
- Move time-utils to a packaged lib folder | ||
See the [main docs](https://github.com/guardian/ab-testing). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
81651
22
207
6