@guardian/ab-core
Advanced tools
Comparing version 0.3.0 to 1.0.0-next.0
@@ -1,3 +0,4 @@ | ||
import { ConfigType, OphanAPI, CoreAPI } from './types'; | ||
import { OphanAPI, CoreAPI, AbTestConfig } from './types'; | ||
export declare class AB { | ||
private _allRunnableTests; | ||
private _isUserInVariant; | ||
@@ -9,3 +10,4 @@ private _firstRunnableTest; | ||
private _trackABTests; | ||
constructor(config: ConfigType); | ||
constructor(config: AbTestConfig); | ||
get allRunnableTests(): CoreAPI['allRunnableTests']; | ||
get firstRunnableTest(): CoreAPI['firstRunnableTest']; | ||
@@ -12,0 +14,0 @@ get runnableTest(): CoreAPI['runnableTest']; |
@@ -1,2 +0,2 @@ | ||
import { ConfigType, CoreAPI } from './types'; | ||
export declare const initCore: (config: ConfigType) => CoreAPI; | ||
import { CoreAPIConfig, CoreAPI } from './types'; | ||
export declare const initCore: (config: CoreAPIConfig) => CoreAPI; |
import { AB } from './ab'; | ||
import { ABTest as _ABTest, CoreAPI as _CoreAPI } from './types'; | ||
import { ABTest as _ABTest, ABTestAPI as _ABTestAPI, AbTestConfig as _AbTestConfig } from './types'; | ||
export { AB }; | ||
export declare type ABTest = _ABTest; | ||
export declare type CoreAPI = _CoreAPI; | ||
export declare type ABTestAPI = _ABTestAPI; | ||
export declare type AbTestConfig = _AbTestConfig; |
@@ -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={mvtMaxValue:1e6,mvtId:1234,pageIsSensitive:!1,abTestSwitches:{},serverSideTests:{},errorReporter:function(){return null},ophanRecord:function(){return null},arrayOfTestObjects:[]};exports.AB=function(){function t(t){var u=e({},a,t),o=u.serverSideTests,c=u.errorReporter,f=u.ophanRecord,v=function(t){var n=t.mvtMaxValue,r=t.mvtId,i=t.pageIsSensitive,s=t.abTestSwitches,a=t.forcedTestVariant,u=t.forcedTestException,o=t.arrayOfTestObjects,c=function(t){var o,c,f=function(e){var t=n*e.audienceOffset;return r&&r>t&&r<=t+n*e.audience?e.variants[r%e.variants.length]:null}(t),v=a&&a.testId===t.id&&a.variant||f;return u!==t.id&&function(e){var t,n=(t=e.expiry,(new Date).valueOf()>new Date(t).setHours(23,59,59,59)),r=!!e.showForSensitive,a=s[e.id]&&!!s[e.id],u=!e.canRun||e.canRun();return(!i||r)&&a&&!n&&u}(t)&&v&&(c="notintest"!==(o=v).id,o.canRun?o.canRun()&&c:c)?e({},t,{variantToRun:v}):null};return{runnableTest:c,firstRunnableTest:function(e){return e.map(function(e){return c(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return(n=o,n.reduce(function(e,t){var n=c(t);return n?[].concat(e,[n]):e},[])).some(function(n){return n.id===e&&n.variantToRun.id===t});var n}}}({mvtMaxValue:u.mvtMaxValue,mvtId:u.mvtId,pageIsSensitive:u.pageIsSensitive,abTestSwitches:u.abTestSwitches,arrayOfTestObjects:u.arrayOfTestObjects}),l=function(e){var t=e.serverSideTests,a=e.errorReporter,u=e.ophanRecord;return{registerCompleteEvents:function(e){return e.forEach(s(!0,a,u))},registerImpressionEvents:function(e){return e.filter(i).forEach(s(!1,a,u))},trackABTests:function(e){return n(function(e,t,n){try{var s={},a=Object.keys(t).filter(function(e){return!!t[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 n(e,{},!1),{}}}(e,t,a),u)}}}({serverSideTests:o,errorReporter:c,ophanRecord:f});this._firstRunnableTest=v.firstRunnableTest,this._runnableTest=v.runnableTest,this._isUserInVariant=v.isUserInVariant,this._registerCompleteEvents=l.registerCompleteEvents,this._registerImpressionEvents=l.registerImpressionEvents,this._trackABTests=l.trackABTests}var u;return(u=[{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,u),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 o=a.variantToRun,u=(e?o.success:o.impression)||t;try{u(function(e,t,i,s){var a,o=((a={})[e.id]=r(t,i),a);return function(){return n(o,s)}}(a,o,e,s))}catch(e){i(e,{},!1)}}};exports.AB=function(){function t(t){var a=t.serverSideTests,o=t.errorReporter,u=t.ophanRecord,c=function(t){var n=t.mvtMaxValue,r=void 0===n?1e6:n,i=t.mvtId,s=t.pageIsSensitive,a=t.abTestSwitches,o=t.forcedTestVariant,u=t.forcedTestException,c=t.arrayOfTestObjects,f=void 0===c?[]:c,l=function(t){var n,c,f=function(e){var t=r*e.audienceOffset,n=t+r*e.audience;return console.log(e.variants),console.log(i),i&&i>t&&i<=n?e.variants[i%e.variants.length]:null}(t),l=o&&o.testId===t.id&&o.variant||f;return u!==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],o=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&o}(t)&&l&&(c="notintest"!==(n=l).id,n.canRun?n.canRun()&&c:c)?e({},t,{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: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,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(s(!0,u,f))},registerImpressionEvents:function(e){console.log("registering impression events"),console.log(e),console.log("registering for",e.filter(i)),e.filter(i).forEach(s(!1,u,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,u,a),f)}}}({serverSideTests:a,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 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={mvtMaxValue:1e6,mvtId:1234,pageIsSensitive:!1,abTestSwitches:{},serverSideTests:{},errorReporter:function(){return null},ophanRecord:function(){return null},arrayOfTestObjects:[]},u=function(){function t(t){var u=e({},a,t),o=u.serverSideTests,c=u.errorReporter,f=u.ophanRecord,v=function(t){var n=t.mvtMaxValue,r=t.mvtId,i=t.pageIsSensitive,s=t.abTestSwitches,a=t.forcedTestVariant,u=t.forcedTestException,o=t.arrayOfTestObjects,c=function(t){var o,c,f=function(e){var t=n*e.audienceOffset;return r&&r>t&&r<=t+n*e.audience?e.variants[r%e.variants.length]:null}(t),v=a&&a.testId===t.id&&a.variant||f;return u!==t.id&&function(e){var t,n=(t=e.expiry,(new Date).valueOf()>new Date(t).setHours(23,59,59,59)),r=!!e.showForSensitive,a=s[e.id]&&!!s[e.id],u=!e.canRun||e.canRun();return(!i||r)&&a&&!n&&u}(t)&&v&&(c="notintest"!==(o=v).id,o.canRun?o.canRun()&&c:c)?e({},t,{variantToRun:v}):null};return{runnableTest:c,firstRunnableTest:function(e){return e.map(function(e){return c(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return(n=o,n.reduce(function(e,t){var n=c(t);return n?[].concat(e,[n]):e},[])).some(function(n){return n.id===e&&n.variantToRun.id===t});var n}}}({mvtMaxValue:u.mvtMaxValue,mvtId:u.mvtId,pageIsSensitive:u.pageIsSensitive,abTestSwitches:u.abTestSwitches,arrayOfTestObjects:u.arrayOfTestObjects}),l=function(e){var t=e.serverSideTests,a=e.errorReporter,u=e.ophanRecord;return{registerCompleteEvents:function(e){return e.forEach(s(!0,a,u))},registerImpressionEvents:function(e){return e.filter(i).forEach(s(!1,a,u))},trackABTests:function(e){return n(function(e,t,n){try{var s={},a=Object.keys(t).filter(function(e){return!!t[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 n(e,{},!1),{}}}(e,t,a),u)}}}({serverSideTests:o,errorReporter:c,ophanRecord:f});this._firstRunnableTest=v.firstRunnableTest,this._runnableTest=v.runnableTest,this._isUserInVariant=v.isUserInVariant,this._registerCompleteEvents=l.registerCompleteEvents,this._registerImpressionEvents=l.registerImpressionEvents,this._trackABTests=l.trackABTests}var u;return(u=[{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,u),t}();export{u 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 o=a.variantToRun,u=(e?o.success:o.impression)||t;try{u(function(e,t,i,s){var a,o=((a={})[e.id]=r(t,i),a);return function(){return n(o,s)}}(a,o,e,s))}catch(e){i(e,{},!1)}}},a=function(){function t(t){var a=t.serverSideTests,o=t.errorReporter,u=t.ophanRecord,c=function(t){var n=t.mvtMaxValue,r=void 0===n?1e6:n,i=t.mvtId,s=t.pageIsSensitive,a=t.abTestSwitches,o=t.forcedTestVariant,u=t.forcedTestException,c=t.arrayOfTestObjects,f=void 0===c?[]:c,l=function(t){var n,c,f=function(e){var t=r*e.audienceOffset,n=t+r*e.audience;return console.log(e.variants),console.log(i),i&&i>t&&i<=n?e.variants[i%e.variants.length]:null}(t),l=o&&o.testId===t.id&&o.variant||f;return u!==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],o=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&o}(t)&&l&&(c="notintest"!==(n=l).id,n.canRun?n.canRun()&&c:c)?e({},t,{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: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,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(s(!0,u,f))},registerImpressionEvents:function(e){console.log("registering impression events"),console.log(e),console.log("registering for",e.filter(i)),e.filter(i).forEach(s(!1,u,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,u,a),f)}}}({serverSideTests:a,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 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)}}},u={mvtMaxValue:1e6,mvtId:1234,pageIsSensitive:!1,abTestSwitches:{},serverSideTests:{},errorReporter:function(){return null},ophanRecord:function(){return null},arrayOfTestObjects:[]};e.AB=function(){function e(e){var n=t({},u,e),o=n.serverSideTests,c=n.errorReporter,f=n.ophanRecord,v=function(e){var n=e.mvtMaxValue,r=e.mvtId,i=e.pageIsSensitive,s=e.abTestSwitches,a=e.forcedTestVariant,u=e.forcedTestException,o=e.arrayOfTestObjects,c=function(e){var o,c,f=function(e){var t=n*e.audienceOffset;return r&&r>t&&r<=t+n*e.audience?e.variants[r%e.variants.length]:null}(e),v=a&&a.testId===e.id&&a.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,a=s[e.id]&&!!s[e.id],u=!e.canRun||e.canRun();return(!i||r)&&a&&!n&&u}(e)&&v&&(c="notintest"!==(o=v).id,o.canRun?o.canRun()&&c:c)?t({},e,{variantToRun:v}):null};return{runnableTest:c,firstRunnableTest:function(e){return e.map(function(e){return c(e)}).find(function(e){return null!==e})||null},isUserInVariant:function(e,t){return(n=o,n.reduce(function(e,t){var n=c(t);return n?[].concat(e,[n]):e},[])).some(function(n){return n.id===e&&n.variantToRun.id===t});var n}}}({mvtMaxValue:n.mvtMaxValue,mvtId:n.mvtId,pageIsSensitive:n.pageIsSensitive,abTestSwitches:n.abTestSwitches,arrayOfTestObjects:n.arrayOfTestObjects}),l=function(e){var t=e.serverSideTests,n=e.errorReporter,u=e.ophanRecord;return{registerCompleteEvents:function(e){return e.forEach(a(!0,n,u))},registerImpressionEvents:function(e){return e.filter(s).forEach(a(!1,n,u))},trackABTests:function(e){return r(function(e,t,n){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,t,n),u)}}}({serverSideTests:o,errorReporter:c,ophanRecord:f});this._firstRunnableTest=v.firstRunnableTest,this._runnableTest=v.runnableTest,this._isUserInVariant=v.isUserInVariant,this._registerCompleteEvents=l.registerCompleteEvents,this._registerImpressionEvents=l.registerImpressionEvents,this._trackABTests=l.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})},o=function(e,t,s){return function(o){var a=o.variantToRun,u=(e?a.success:a.impression)||n;try{u(function(e,t,n,s){var o,a=((o={})[e.id]=i(t,n),o);return function(){return r(a,s)}}(o,a,e,s))}catch(e){t(e,{},!1)}}};e.AB=function(){function e(e){var n=e.serverSideTests,a=e.errorReporter,u=e.ophanRecord,c=function(e){var n=e.mvtMaxValue,r=void 0===n?1e6:n,i=e.mvtId,s=e.pageIsSensitive,o=e.abTestSwitches,a=e.forcedTestVariant,u=e.forcedTestException,c=e.arrayOfTestObjects,f=void 0===c?[]:c,l=function(e){var n,c,f=function(e){var t=r*e.audienceOffset,n=t+r*e.audience;return console.log(e.variants),console.log(i),i&&i>t&&i<=n?e.variants[i%e.variants.length]:null}(e),l=a&&a.testId===e.id&&a.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=o["ab"+e.id]&&!!o["ab"+e.id],a=!e.canRun||e.canRun();return(!s||r)&&i&&!n&&a}(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,a=e.errorReporter,u=void 0===a?function(){}:a,c=e.ophanRecord,f=void 0===c?function(){}:c;return{registerCompleteEvents:function(e){return e.forEach(o(!0,u,f))},registerImpressionEvents:function(e){console.log("registering impression events"),console.log(e),console.log("registering for",e.filter(s)),e.filter(s).forEach(o(!1,u,f))},trackABTests:function(e){return r(function(e,t,n){try{var r={},o=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)}),o.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:a,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 |
@@ -1,3 +0,3 @@ | ||
export declare type ConfigType = { | ||
mvtMaxValue: number; | ||
export declare type CoreAPIConfig = { | ||
mvtMaxValue?: number; | ||
mvtId: number; | ||
@@ -13,4 +13,4 @@ pageIsSensitive: boolean; | ||
}; | ||
export declare type ABType = CoreAPI & OphanAPI; | ||
export declare type CoreAPI = { | ||
allRunnableTests: (tests: ReadonlyArray<ABTest>) => ReadonlyArray<Runnable<ABTest>> | []; | ||
runnableTest: (test: ABTest) => Runnable<ABTest & { | ||
@@ -23,5 +23,5 @@ variantToRun: Variant; | ||
export declare type OphanAPIConfig = { | ||
serverSideTests: ServerSideTests; | ||
errorReporter: ErrorReporterFunc; | ||
ophanRecord: OphanRecordFunction; | ||
serverSideTests?: ServerSideTests; | ||
errorReporter?: ErrorReporterFunc; | ||
ophanRecord?: OphanRecordFunction; | ||
}; | ||
@@ -33,2 +33,4 @@ export declare type OphanAPI = { | ||
}; | ||
export declare type ABTestAPI = CoreAPI & OphanAPI; | ||
export declare type AbTestConfig = CoreAPIConfig & OphanAPIConfig; | ||
export declare type OphanProduct = 'CONTRIBUTION' | 'RECURRING_CONTRIBUTION' | 'MEMBERSHIP_SUPPORTER' | 'MEMBERSHIP_PATRON' | 'MEMBERSHIP_PARTNER' | 'DIGITAL_SUBSCRIPTION' | 'PRINT_SUBSCRIPTION'; | ||
@@ -35,0 +37,0 @@ export interface OphanABEvent { |
{ | ||
"version": "0.3.0", | ||
"version": "1.0.0-next.0", | ||
"name": "@guardian/ab-core", | ||
@@ -25,3 +25,3 @@ "author": "The Guardian", | ||
"validate": "yarn lint && yarn tsc && yarn test", | ||
"prepublishOnly": "yarn build" | ||
"prepublishOnly": "yarn validate && yarn build" | ||
}, | ||
@@ -78,3 +78,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "533edc18b88b3531046e983f15a446c807a4b86b" | ||
"gitHead": "af948fb107cc97c8aa17b17a0f32dee99984d1ee" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
84803
204
0