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

@guardian/ab-core

Package Overview
Dependencies
Maintainers
33
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.2.1-alpha.11

4

dist/ab.d.ts

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

import { ConfigType, OphanAPI, CoreAPI } from './types';
import { OphanAPI, CoreAPI, AbTestConfig } from './types';
export declare class AB {

@@ -9,3 +9,3 @@ private _isUserInVariant;

private _trackABTests;
constructor(config: ConfigType);
constructor(config: AbTestConfig);
get firstRunnableTest(): CoreAPI['firstRunnableTest'];

@@ -12,0 +12,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 { ABProvider, useAB } from './ab-react';
export { AB, ABProvider, useAB };
import { ABTestAPI as _ABTestAPI, CoreAPI as _CoreAPI, AbTestConfig as _AbTestConfig } from './types';
export { AB };
export declare type ABTestAPI = _ABTestAPI;
export declare type CoreAPI = _CoreAPI;
export declare type AbTestConfig = _AbTestConfig;

@@ -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)}}};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}();
//# 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};
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};
//# 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 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}()});
//# sourceMappingURL=index.umd.js.map
export declare const initABCoreDefaultConfig: {
mvtMaxValue: number;
mvtCookieId: number;
mvtId: number;
pageIsSensitive: boolean;

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

@@ -1,4 +0,4 @@

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

@@ -13,3 +13,2 @@ abTestSwitches: Record<string, boolean>;

};
export declare type ABType = CoreAPI & OphanAPI;
export declare type CoreAPI = {

@@ -23,5 +22,5 @@ runnableTest: (test: ABTest) => Runnable<ABTest & {

export declare type OphanAPIConfig = {
serverSideTests: ServerSideTests;
errorReporter: ErrorReporterFunc;
ophanRecord: OphanRecordFunction;
serverSideTests?: ServerSideTests;
errorReporter?: ErrorReporterFunc;
ophanRecord?: OphanRecordFunction;
};

@@ -33,2 +32,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 +36,0 @@ export interface OphanABEvent {

{
"version": "0.1.1-alpha.19+c59aea0",
"version": "0.2.1-alpha.11+75b5583",
"name": "@guardian/ab-core",

@@ -22,18 +22,13 @@ "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",
"prepublishOnly": "yarn build"
"prepublishOnly": "yarn validate && 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",

@@ -46,10 +41,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"

@@ -74,3 +64,2 @@ },

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

@@ -91,7 +80,3 @@ ]

},
"peerDependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"gitHead": "c59aea0d15b47ae0214316686f83ed5a77817336"
"gitHead": "75b5583b449162fc3334d1433b60427cf4f6394a"
}

@@ -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