Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@guardian/ab-core

Package Overview
Dependencies
Maintainers
34
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@guardian/ab-core - npm Package Compare versions

Comparing version 0.1.1-alpha.19 to 0.3.0

6

dist/index.d.ts
import { AB } from './ab';
import { ABProvider, useAB } from './ab-react';
export { AB, ABProvider, useAB };
import { ABTest as _ABTest, CoreAPI as _CoreAPI } from './types';
export { AB };
export declare type ABTest = _ABTest;
export declare type CoreAPI = _CoreAPI;

@@ -1,2 +0,2 @@

var e,t=(e=require("react"))&&"object"==typeof e&&"default"in e?e.default:e;function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var n=function(){},i=function(e,t){return t({abTestRegister:e})},s=function(e,t){var r={variantName:e.id,complete:t};return e.campaignCode&&(r.campaignCodes=[e.campaignCode]),r},a=function(e){return e.variants.every(function(e){return"function"==typeof e.impression})},u=function(e,t,r){return function(a){var u=a.variantToRun,o=(e?u.success:u.impression)||n;try{o(function(e,t,r,n){var a,u=((a={})[e.id]=s(t,r),a);return function(){return i(u,n)}}(a,u,e,r))}catch(e){t(e,{},!1)}}},o={mvtMaxValue:1e6,mvtCookieId:1234,pageIsSensitive:!1,abTestSwitches:{},serverSideTests:{},errorReporter:function(){return null},ophanRecord:function(){return null},arrayOfTestObjects:[]},c=function(){function e(e){var t=r(r({},o),e),n=t.serverSideTests,c=t.errorReporter,f=t.ophanRecord,v=function(e){var t=e.mvtMaxValue,n=e.mvtCookieId,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 r=t*e.audienceOffset;return n&&n>r&&n<=r+t*e.audience?e.variants[n%e.variants.length]:null}(e),v=(null==a?void 0:a.testId)===e.id&&a.variant||f;return u!==e.id&&function(e){var t,r=(t=e.expiry,(new Date).valueOf()>new Date(t).setHours(23,59,59,59)),n=!!e.showForSensitive,a=s[e.id]&&!!s[e.id],u=!e.canRun||e.canRun();return(!i||n)&&a&&!r&&u}(e)&&v&&(c="notintest"!==(o=v).id,o.canRun?o.canRun()&&c:c)?r(r({},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(r=o,r.reduce(function(e,t){var r=c(t);return r?[].concat(e,[r]):e},[])).some(function(r){return r.id===e&&r.variantToRun.id===t});var r}}}({mvtMaxValue:t.mvtMaxValue,mvtCookieId:t.mvtCookieId,pageIsSensitive:t.pageIsSensitive,abTestSwitches:t.abTestSwitches,arrayOfTestObjects:t.arrayOfTestObjects}),l=function(e){var t=e.serverSideTests,r=e.errorReporter,n=e.ophanRecord;return{registerCompleteEvents:function(e){return e.forEach(u(!0,r,n))},registerImpressionEvents:function(e){return e.filter(a).forEach(u(!1,r,n))},trackABTests:function(e){return i(function(e,t,r){try{var n={},i=Object.keys(t).filter(function(e){return!!t[e]});return e.filter(function(e){return!a(e)}).forEach(function(e){n[e.id]=s(e.variantToRun,!1)}),i.forEach(function(e){n["ab"+e]=s({id:"inTest",test:function(){}},!1)}),n}catch(e){return r(e,{},!1),{}}}(e,t,r),n)}}}({serverSideTests:n,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 t;return(t=[{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 r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(e.prototype,t),e}(),f=t.createContext(void 0);exports.AB=c,exports.ABProvider=function(e){var r=e.mvtMax,n=e.children;return t.createElement(f.Provider,{value:new c({mvtCookieId:e.mvtId,mvtMaxValue:void 0===r?1e6:r,pageIsSensitive:e.isSensitive,abTestSwitches:e.switches,arrayOfTestObjects:e.tests})},n)},exports.useAB=function(){var e=t.useContext(f);if(void 0===e)throw new Error("useAB must be used within the ABProvider");return e};
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}();
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import e from"react";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)}}},o={mvtMaxValue:1e6,mvtCookieId:1234,pageIsSensitive:!1,abTestSwitches:{},serverSideTests:{},errorReporter:function(){return null},ophanRecord:function(){return null},arrayOfTestObjects:[]},u=function(){function e(e){var n=t(t({},o),e),u=n.serverSideTests,c=n.errorReporter,f=n.ophanRecord,v=function(e){var n=e.mvtMaxValue,r=e.mvtCookieId,i=e.pageIsSensitive,s=e.abTestSwitches,a=e.forcedTestVariant,o=e.forcedTestException,u=e.arrayOfTestObjects,c=function(e){var u,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=(null==a?void 0:a.testId)===e.id&&a.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,a=s[e.id]&&!!s[e.id],o=!e.canRun||e.canRun();return(!i||r)&&a&&!n&&o}(e)&&v&&(c="notintest"!==(u=v).id,u.canRun?u.canRun()&&c:c)?t(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=u,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,mvtCookieId:n.mvtCookieId,pageIsSensitive:n.pageIsSensitive,abTestSwitches:n.abTestSwitches,arrayOfTestObjects:n.arrayOfTestObjects}),l=function(e){var t=e.serverSideTests,n=e.errorReporter,o=e.ophanRecord;return{registerCompleteEvents:function(e){return e.forEach(a(!0,n,o))},registerImpressionEvents:function(e){return e.filter(s).forEach(a(!1,n,o))},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),o)}}}({serverSideTests:u,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}(),c=e.createContext(void 0),f=function(t){var n=t.mvtMax,r=t.children;return e.createElement(c.Provider,{value:new u({mvtCookieId:t.mvtId,mvtMaxValue:void 0===n?1e6:n,pageIsSensitive:t.isSensitive,abTestSwitches:t.switches,arrayOfTestObjects:t.tests})},r)},v=function(){var t=e.useContext(c);if(void 0===t)throw new Error("useAB must be used within the ABProvider");return t};export{u as AB,f as ABProvider,v as useAB};
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};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).abCore={},e.react)}(this,function(e,t){function n(){return(n=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)}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var r=function(){},i=function(e,t){return t({abTestRegister:e})},s=function(e,t){var n={variantName:e.id,complete:t};return e.campaignCode&&(n.campaignCodes=[e.campaignCode]),n},a=function(e){return e.variants.every(function(e){return"function"==typeof e.impression})},o=function(e,t,n){return function(a){var o=a.variantToRun,u=(e?o.success:o.impression)||r;try{u(function(e,t,n,r){var a,o=((a={})[e.id]=s(t,n),a);return function(){return i(o,r)}}(a,o,e,n))}catch(e){t(e,{},!1)}}},u={mvtMaxValue:1e6,mvtCookieId:1234,pageIsSensitive:!1,abTestSwitches:{},serverSideTests:{},errorReporter:function(){return null},ophanRecord:function(){return null},arrayOfTestObjects:[]},c=function(){function e(e){var t=n(n({},u),e),r=t.serverSideTests,c=t.errorReporter,f=t.ophanRecord,v=function(e){var t=e.mvtMaxValue,r=e.mvtCookieId,i=e.pageIsSensitive,s=e.abTestSwitches,a=e.forcedTestVariant,o=e.forcedTestException,u=e.arrayOfTestObjects,c=function(e){var u,c,f=function(e){var n=t*e.audienceOffset;return r&&r>n&&r<=n+t*e.audience?e.variants[r%e.variants.length]:null}(e),v=(null==a?void 0:a.testId)===e.id&&a.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,a=s[e.id]&&!!s[e.id],o=!e.canRun||e.canRun();return(!i||r)&&a&&!n&&o}(e)&&v&&(c="notintest"!==(u=v).id,u.canRun?u.canRun()&&c:c)?n(n({},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=u,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:t.mvtMaxValue,mvtCookieId:t.mvtCookieId,pageIsSensitive:t.pageIsSensitive,abTestSwitches:t.abTestSwitches,arrayOfTestObjects:t.arrayOfTestObjects}),l=function(e){var t=e.serverSideTests,n=e.errorReporter,r=e.ophanRecord;return{registerCompleteEvents:function(e){return e.forEach(o(!0,n,r))},registerImpressionEvents:function(e){return e.filter(a).forEach(o(!1,n,r))},trackABTests:function(e){return i(function(e,t,n){try{var r={},i=Object.keys(t).filter(function(e){return!!t[e]});return e.filter(function(e){return!a(e)}).forEach(function(e){r[e.id]=s(e.variantToRun,!1)}),i.forEach(function(e){r["ab"+e]=s({id:"inTest",test:function(){}},!1)}),r}catch(e){return n(e,{},!1),{}}}(e,t,n),r)}}}({serverSideTests:r,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 t;return(t=[{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,t),e}(),f=t.createContext(void 0);e.AB=c,e.ABProvider=function(e){var n=e.mvtMax,r=e.children;return t.createElement(f.Provider,{value:new c({mvtCookieId:e.mvtId,mvtMaxValue:void 0===n?1e6:n,pageIsSensitive:e.isSensitive,abTestSwitches:e.switches,arrayOfTestObjects:e.tests})},r)},e.useAB=function(){var e=t.useContext(f);if(void 0===e)throw new Error("useAB must be used within the ABProvider");return 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 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}()});
//# sourceMappingURL=index.umd.js.map
export declare const initABCoreDefaultConfig: {
mvtMaxValue: number;
mvtCookieId: number;
mvtId: number;
pageIsSensitive: boolean;

@@ -5,0 +5,0 @@ abTestSwitches: {

export declare type ConfigType = {
mvtMaxValue: number;
mvtCookieId: number;
mvtId: number;
pageIsSensitive: boolean;

@@ -5,0 +5,0 @@ abTestSwitches: Record<string, boolean>;

{
"version": "0.1.1-alpha.19+c59aea0",
"version": "0.3.0",
"name": "@guardian/ab-core",

@@ -22,4 +22,4 @@ "author": "The Guardian",

"lint": "eslint . --ext .ts",
"build": "microbundle --jsx React.createElement",
"dev": "microbundle watch --jsx React.createElement",
"build": "microbundle",
"dev": "microbundle watch",
"validate": "yarn lint && yarn tsc && yarn test",

@@ -29,12 +29,7 @@ "prepublishOnly": "yarn build"

"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-optional-chaining": "^7.10.1",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0",
"@testing-library/jest-dom": "^5.8.0",
"@testing-library/react": "^10.2.1",
"@types/jest": "^25.2.3",
"@types/react": "^16.9.36",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^3.3.0",

@@ -47,10 +42,5 @@ "@typescript-eslint/parser": "^3.3.0",

"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.20.0",
"jest": "^26.0.1",
"jest-environment-jsdom-sixteen": "^1.0.3",
"lerna": "^3.22.1",
"microbundle": "^0.12.0-next.9",
"prettier": "^2.0.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"ts-jest": "^26.1.0"

@@ -75,3 +65,2 @@ },

"plugin:prettier/recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"

@@ -92,7 +81,3 @@ ]

},
"peerDependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"gitHead": "c59aea0d15b47ae0214316686f83ed5a77817336"
"gitHead": "533edc18b88b3531046e983f15a446c807a4b86b"
}

@@ -36,3 +36,3 @@ # ab-rendering

| mvtMaxValue | number | `10000` | MVT % is calculated from 0 to mvtMaxValue |
| mvtCookieId | number | getCookie('mvtCookie') | The user's MVT ID to calculate what tests and variants they fall into |
| 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 |

@@ -39,0 +39,0 @@ | abTestSwitches | Record<string, boolean> | {'TestOne': true} | An object containing all of the boolean values of abTestSwitches, in Frontend from page.config.switches.abTests |

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc