@guardian/ab-core
Advanced tools
Comparing version 1.2.0 to 2.0.0
import { AB } from './ab'; | ||
import { ABTest as _ABTest, ABTestAPI as _ABTestAPI, AbTestConfig as _AbTestConfig, Runnable as _Runnable, Variant as _Variant } from './types'; | ||
import { ABTest as _ABTest, ABTestAPI as _ABTestAPI, AbTestConfig as _AbTestConfig, Runnable as _Runnable, Variant as _Variant, Participations as _Participations } from './types'; | ||
export { AB }; | ||
@@ -9,1 +9,2 @@ export declare type ABTest = _ABTest; | ||
export declare type Variant = _Variant; | ||
export declare type Participations = _Participations; |
@@ -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["ab"+e.id]&&!!a["ab"+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},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,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){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}(); | ||
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){var n=e.id;return void 0!==t&&void 0!==t[n]&&void 0!==t[n].variant&&function(e,t){return e.variants.find(function(e){return e.id===t})||!1}(e,t[n].variant)}(t,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 @@ | ||
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.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["ab"+e.id]&&!!a["ab"+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},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,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){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}; | ||
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){var n=e.id;return void 0!==t&&void 0!==t[n]&&void 0!==t[n].variant&&function(e,t){return e.variants.find(function(e){return e.id===t})||!1}(e,t[n].variant)}(t,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 u=a.variantToRun,o=(e?u.success:u.impression)||n;try{o(function(e,t,n,s){var a,u=((a={})[e.id]=i(t,n),a);return function(){return r(u,s)}}(a,u,e,s))}catch(e){t(e,{},!1)}}};e.AB=function(){function e(e){var n=e.serverSideTests,u=e.errorReporter,o=e.ophanRecord,c=function(e){var n=e.mvtMaxValue,r=void 0===n?1e6:n,i=e.mvtId,s=e.pageIsSensitive,a=e.abTestSwitches,u=e.forcedTestVariant,o=e.forcedTestException,c=e.arrayOfTestObjects,f=void 0===c?[]:c,l=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),l=u&&u.testId===e.id&&u.variant||f;return o!==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["ab"+e.id]&&!!a["ab"+e.id],u=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&u}(e)&&l&&(c="notintest"!==(n=l).id,n.canRun?n.canRun()&&c:c)?t({},e,{variantToRun:l}):null},v=function(e){return e.reduce(function(e,t){var n=l(t);return n?[].concat(e,[n]):e},[])};return{allRunnableTests:v,runnableTest:l,firstRunnableTest:function(e){return e.map(function(e){return l(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return v(f).some(function(n){return n.id===e&&n.variantToRun.id===t})}}}({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,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(a(!0,o,f))},registerImpressionEvents:function(e){e.filter(s).forEach(a(!1,o,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,o,n),f)}}}({serverSideTests:n,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 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}()}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).abCore={})}(this,function(e){function n(){return(n=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}var t=function(){},r=function(e,n){return n({abTestRegister:e})},i=function(e,n){var t={variantName:e.id,complete:n};return e.campaignCode&&(t.campaignCodes=[e.campaignCode]),t},s=function(e){return e.variants.every(function(e){return"function"==typeof e.impression})},a=function(e,n,s){return function(a){var u=a.variantToRun,o=(e?u.success:u.impression)||t;try{o(function(e,n,t,s){var a,u=((a={})[e.id]=i(n,t),a);return function(){return r(u,s)}}(a,u,e,s))}catch(e){n(e,{},!1)}}};e.AB=function(){function e(e){var t=e.serverSideTests,u=e.errorReporter,o=e.ophanRecord,c=function(e){var t=e.mvtMaxValue,r=void 0===t?1e6:t,i=e.mvtId,s=e.pageIsSensitive,a=e.abTestSwitches,u=e.forcedTestVariants,o=e.forcedTestException,c=e.arrayOfTestObjects,f=void 0===c?[]:c,v=function(e){var t,c,f=function(e){var n=r*e.audienceOffset;return i&&i>n&&i<=n+r*e.audience?e.variants[i%e.variants.length]:null}(e),v=function(e,n){var t=e.id;return void 0!==n&&void 0!==n[t]&&void 0!==n[t].variant&&function(e,n){return e.variants.find(function(e){return e.id===n})||!1}(e,n[t].variant)}(e,u),l=v||f;return o!==e.id&&(v||function(e){var n,t=(n=e.expiry,(new Date).valueOf()>new Date(n).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&&!t&&u}(e))&&l&&(v||(c="notintest"!==(t=l).id,t.canRun?t.canRun()&&c:c))?n({},e,{variantToRun:l}):null},l=function(e){return e.reduce(function(e,n){var t=v(n);return t?[].concat(e,[t]):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,n){return l(f).some(function(t){return t.id===e&&t.variantToRun.id===n})}}}({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 n=e.serverSideTests,t=void 0===n?{}:n,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(a(!0,o,f))},registerImpressionEvents:function(e){e.filter(s).forEach(a(!1,o,f))},trackABTests:function(e){return r(function(e,n,t){try{var r={},a=Object.keys(t).filter(function(e){return!!t[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 n(e,{},!1),{}}}(e,o,t),f)}}}({serverSideTests:t,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 t;return(t=[{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,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}()}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -6,6 +6,3 @@ export declare type CoreAPIConfig = { | ||
abTestSwitches: Record<string, boolean>; | ||
forcedTestVariant?: { | ||
testId: ABTest['id']; | ||
variant: Variant; | ||
}; | ||
forcedTestVariants?: Participations; | ||
forcedTestException?: ABTest['id']; | ||
@@ -72,2 +69,7 @@ arrayOfTestObjects: ABTest[]; | ||
} | ||
export declare type Participations = { | ||
[key: string]: { | ||
variant: string; | ||
}; | ||
}; | ||
export declare type Runnable<ABTest> = ABTest & { | ||
@@ -74,0 +76,0 @@ variantToRun: Variant; |
{ | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"name": "@guardian/ab-core", | ||
@@ -77,3 +77,3 @@ "author": "The Guardian", | ||
}, | ||
"gitHead": "93bf6cf5a345d2c4547116dc80ada060dae9c49c" | ||
"gitHead": "1fc82fde50dc2c0955966d93cc7d567519f41176" | ||
} |
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
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
83576
209