@instantdomain/bandit
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,1 @@ | ||
import a from"react";import*as b from"../lib/constants";import{useInstantBandit as c}from"../lib/hooks";export function Default(d){var e=c().variant.name===b.DEFAULT_VARIANT_NAME;return a.createElement(a.Fragment,null,e&&d.children)} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Default=void 0;var a=require("tslib"),b=a.__importDefault(require("react")),c=a.__importStar(require("../lib/constants")),d=require("../lib/hooks");exports.Default=function(a){var e=(0,d.useInstantBandit)().variant.name===c.DEFAULT_VARIANT_NAME;return b.default.createElement(b.default.Fragment,null,e&&a.children)} |
@@ -1,1 +0,1 @@ | ||
import{__assign as b,__awaiter as c,__generator as d}from"tslib";import e,{useCallback as f,useEffect as g,useState as h}from"react";import{DefaultMetrics as i,DEFAULT_TIMEOUT as j}from"../lib/constants";import{LoadState as k}from"../lib/types";import{InstantBanditContext as l,createBanditContext as m}from"../lib/contexts";import{exists as n,isBrowserEnvironment as o,useIsomorphicLayoutEffect as p}from"../lib/utils";import{DEFAULT_SITE as q}from"../lib/defaults";var a=function(s){var u=function(){Q()},C=function(a){if(o&& !0!==r.recordedExposure){var b=a.experiment,c=a.variant;try{P.persistVariant(a,b.id,c.name)}catch(d){console.warn("[IB] Session not saved")}J.sinkEvent(a,i.EXPOSURES),r.recordedExposure=!0}},D=function(a,b){if(void 0===a&&(a=null),a&&(console.warn("[IB] Component received error: ".concat(a)),O))try{O(a,b)}catch(c){console.warn("[IB] Additional error received invoking error handler: ".concat(c))}},v=h(!1),E=v[0],M=v[1],w=h({renders:0,recordedExposure:!1,state:k.PRELOAD,loadTimeStart:new Date().getTime(),loadTimeEnd:0,loadDuration:0,loadTimedOut:!1,loadTimeoutTimer:null}),r=w[0],F=w[1],x=h(function(){var e=s||{},f=e.options,g=e.siteName,a=m(f),h=a.loader;return a.select=function(e){return c(void 0,void 0,void 0,function(){var c,f;return d(this,function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),[4,h.load(a,g,"string"==typeof e?e:null==e?void 0:e.name)];case 1:return c=d.sent(),N(b({},a)),[2,c];case 2:return D(f=d.sent(),a),console.warn("[IB] Error loading site: ".concat(f)),[2,q];case 3:return[2]}})})},a}),a=x[0],N=x[1],G=s.defer,y=s.select,z=s.site,H=s.siteName,A=s.timeout,O=s.onError,I=s.onReady,t=a.loader,J=a.metrics,P=a.session,B=n(A)?A:j,Q=f(function(){if(r.state!==k.READY&&(r.state=k.READY,M(!0),I))try{I(a)}catch(b){console.warn("[IB] An error occurred while handling a ready event: ".concat(b))}},[r,I,a]),K=f(function(){try{window.removeEventListener("beforeunload",K),document.removeEventListener("onvisibilitychange",K)}finally{J.flush(a,!0).catch(function(){})}},[a,J]),L=f(function(){if(r.state!==k.READY)return r.loadTimedOut=!0,r.loadTimeEnd=new Date().getTime(),r.loadDuration=r.loadTimeEnd-r.loadTimeStart,function(){return clearTimeout(r.loadTimeoutTimer)}},[r]);return(t&&r.state===k.PRELOAD&&(r.state=k.WAIT,z?(t.init(a,z,y),F(b(b({},r),{state:k.READY})),C(a),u(),t.error&&D(t.error,a)):(!n(r.loadTimeoutTimer)&&n(B)&&(r.loadTimeoutTimer=setTimeout(L,B)),t.load(a,H,y).then(function(){if(r.loadTimedOut)throw a.init(q),C(a),F(b({},r)),u(),Error("[IB] Timed out waiting for site @ ".concat(r.loadDuration," ms."))}).then(function(){return C(a)}).then(function(){return F(b(b({},r),{state:k.READY}))}).then(u).then(function(){return t.error?D(t.error,a):void 0}).catch(function(b){return D(b,a)}))),g(function(){return window.addEventListener("beforeunload",K),document.addEventListener("onvisibilitychange",K),K},[K]),p(function(){E&&N(a)},[]),!0===G&&0===r.renders)?(++r.renders,setTimeout(function(){return F(b({},r))}),e.createElement(e.Fragment,null)):e.createElement(l.Provider,{value:a},E&&s.children)};export{a as InstantBanditComponent,a as InstantBandit} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InstantBandit=exports.InstantBanditComponent=void 0;var b=require("tslib"),c=b.__importStar(require("react")),d=require("../lib/constants"),e=require("../lib/types"),f=require("../lib/contexts"),g=require("../lib/utils"),h=require("../lib/defaults"),a=function(j){var l=function(){H()},t=function(a){if(g.isBrowserEnvironment&& !0!==i.recordedExposure){var b=a.experiment,c=a.variant;try{G.persistVariant(a,b.id,c.name)}catch(e){console.warn("[IB] Session not saved")}A.sinkEvent(a,d.DefaultMetrics.EXPOSURES),i.recordedExposure=!0}},u=function(a,b){if(void 0===a&&(a=null),a&&(console.warn("[IB] Component received error: ".concat(a)),F))try{F(a,b)}catch(c){console.warn("[IB] Additional error received invoking error handler: ".concat(c))}},m=(0,c.useState)(!1),v=m[0],D=m[1],n=(0,c.useState)({renders:0,recordedExposure:!1,state:e.LoadState.PRELOAD,loadTimeStart:new Date().getTime(),loadTimeEnd:0,loadDuration:0,loadTimedOut:!1,loadTimeoutTimer:null}),i=n[0],w=n[1],o=(0,c.useState)(function(){var c=j||{},d=c.options,e=c.siteName,a=(0,f.createBanditContext)(d),g=a.loader;return a.select=function(c){return b.__awaiter(void 0,void 0,void 0,function(){var d,f;return b.__generator(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,g.load(a,e,"string"==typeof c?c:null==c?void 0:c.name)];case 1:return d=i.sent(),E(b.__assign({},a)),[2,d];case 2:return u(f=i.sent(),a),console.warn("[IB] Error loading site: ".concat(f)),[2,h.DEFAULT_SITE];case 3:return[2]}})})},a}),a=o[0],E=o[1],x=j.defer,p=j.select,q=j.site,y=j.siteName,r=j.timeout,F=j.onError,z=j.onReady,k=a.loader,A=a.metrics,G=a.session,s=(0,g.exists)(r)?r:d.DEFAULT_TIMEOUT,H=(0,c.useCallback)(function(){if(i.state!==e.LoadState.READY&&(i.state=e.LoadState.READY,D(!0),z))try{z(a)}catch(b){console.warn("[IB] An error occurred while handling a ready event: ".concat(b))}},[i,z,a]),B=(0,c.useCallback)(function(){try{window.removeEventListener("beforeunload",B),document.removeEventListener("onvisibilitychange",B)}finally{A.flush(a,!0).catch(function(){})}},[a,A]),C=(0,c.useCallback)(function(){if(i.state!==e.LoadState.READY)return i.loadTimedOut=!0,i.loadTimeEnd=new Date().getTime(),i.loadDuration=i.loadTimeEnd-i.loadTimeStart,function(){return clearTimeout(i.loadTimeoutTimer)}},[i]);return(k&&i.state===e.LoadState.PRELOAD&&(i.state=e.LoadState.WAIT,q?(k.init(a,q,p),w(b.__assign(b.__assign({},i),{state:e.LoadState.READY})),t(a),l(),k.error&&u(k.error,a)):(!(0,g.exists)(i.loadTimeoutTimer)&&(0,g.exists)(s)&&(i.loadTimeoutTimer=setTimeout(C,s)),k.load(a,y,p).then(function(){if(i.loadTimedOut)throw a.init(h.DEFAULT_SITE),t(a),w(b.__assign({},i)),l(),Error("[IB] Timed out waiting for site @ ".concat(i.loadDuration," ms."))}).then(function(){return t(a)}).then(function(){return w(b.__assign(b.__assign({},i),{state:e.LoadState.READY}))}).then(l).then(function(){return k.error?u(k.error,a):void 0}).catch(function(b){return u(b,a)}))),(0,c.useEffect)(function(){return window.addEventListener("beforeunload",B),document.addEventListener("onvisibilitychange",B),B},[B]),(0,g.useIsomorphicLayoutEffect)(function(){v&&E(a)},[]),!0===x&&0===i.renders)?(++i.renders,setTimeout(function(){return w(b.__assign({},i))}),c.default.createElement(c.default.Fragment,null)):c.default.createElement(f.InstantBanditContext.Provider,{value:a},v&&j.children)};exports.InstantBanditComponent=a,exports.InstantBandit=a |
@@ -1,1 +0,1 @@ | ||
import a from"react";import{LoadState as b}from"../lib/types";import{useInstantBandit as c}from"../lib/hooks";export function Placeholder(d){var e=c().loader.state===b.READY;return a.createElement(a.Fragment,null,!e&&d.children)} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Placeholder=void 0;var a=require("tslib").__importDefault(require("react")),b=require("../lib/types"),c=require("../lib/hooks");exports.Placeholder=function(d){var e=(0,c.useInstantBandit)().loader.state===b.LoadState.READY;return a.default.createElement(a.default.Fragment,null,!e&&d.children)} |
@@ -1,1 +0,1 @@ | ||
export*from"./Default";export*from"./Placeholder";export*from"./Variant" | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var a=require("tslib");a.__exportStar(require("./Default"),exports),a.__exportStar(require("./Placeholder"),exports),a.__exportStar(require("./Variant"),exports) |
@@ -1,1 +0,1 @@ | ||
import a from"react";import{LoadState as b}from"../lib/types";import{useInstantBandit as c}from"../lib/hooks";export var Variant=function(d){var g=d.name,e=c(),h=e.loader,f=e.variant,i=f&&f.name===g,j=h.state===b.READY;return a.createElement(a.Fragment,null,i&&j&&d.children)} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Variant=void 0;var a=require("tslib").__importDefault(require("react")),b=require("../lib/types"),c=require("../lib/hooks");exports.Variant=function(d){var g=d.name,e=(0,c.useInstantBandit)(),h=e.loader,f=e.variant,i=f&&f.name===g,j=h.state===b.LoadState.READY;return a.default.createElement(a.default.Fragment,null,i&&j&&d.children)} |
@@ -1,1 +0,1 @@ | ||
import{InstantBandit as a}from"./components/InstantBanditComponent";import{Variant as b,Default as c}from"./components/primitives";export*from"./lib/defaults";export*from"./lib/hooks";export*from"./lib/models";export*from"./lib/types";export{a as InstantBandit,b as Variant,c as Default} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Default=exports.Variant=exports.InstantBandit=void 0;var a=require("tslib"),b=require("./components/InstantBanditComponent");Object.defineProperty(exports,"InstantBandit",{enumerable:!0,get:function(){return b.InstantBandit}});var c=require("./components/primitives");Object.defineProperty(exports,"Variant",{enumerable:!0,get:function(){return c.Variant}}),Object.defineProperty(exports,"Default",{enumerable:!0,get:function(){return c.Default}}),a.__exportStar(require("./lib/defaults"),exports),a.__exportStar(require("./lib/hooks"),exports),a.__exportStar(require("./lib/models"),exports),a.__exportStar(require("./lib/types"),exports) |
@@ -1,1 +0,1 @@ | ||
import{__assign as a}from"tslib";export function bandit(c,f,b){void 0===b&&(b=.2);var d,g=conversionRates(c,f),e=maxKey(g);return a(((d={})[e]=1-b,d),otherProbabilities(Object.keys(c),e,b))}export function otherProbabilities(a,c,d){var b=a.filter(function(a){return a!==c});return Object.fromEntries(b.map(function(a){return[a,d/b.length]}))}export function maxKey(a){return Object.entries(a).reduce(function(a,b){var e=a[0],c=a[1],f=b[0],d=b[1];return c>d?[e,c]:[f,d]})[0]}export function conversionRates(a,b){return Object.fromEntries(Object.entries(a).map(function(a){var c=a[0],d=a[1];return[c,(b[c]||0)/d,]}))} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.conversionRates=exports.maxKey=exports.otherProbabilities=exports.bandit=void 0;var d=require("tslib");function a(a,c,d){var b=a.filter(function(a){return a!==c});return Object.fromEntries(b.map(function(a){return[a,d/b.length]}))}function b(a){return Object.entries(a).reduce(function(a,b){var e=a[0],c=a[1],f=b[0],d=b[1];return c>d?[e,c]:[f,d]})[0]}function c(a,b){return Object.fromEntries(Object.entries(a).map(function(a){var c=a[0],d=a[1];return[c,(b[c]||0)/d,]}))}exports.bandit=function(f,i,e){void 0===e&&(e=.2);var g,j=c(f,i),h=b(j);return d.__assign(((g={})[h]=1-e,g),a(Object.keys(f),h,e))},exports.otherProbabilities=a,exports.maxKey=b,exports.conversionRates=c |
@@ -1,1 +0,1 @@ | ||
export var DEFAULT_NAME="default";export var DEFAULT_SITE_ID=DEFAULT_NAME;export var DEFAULT_SITE_NAME=DEFAULT_NAME;export var DEFAULT_EXPERIMENT_ID=DEFAULT_NAME;export var DEFAULT_EXPERIMENT_NAME=DEFAULT_NAME;export var DEFAULT_VARIANT_ID=DEFAULT_NAME;export var DEFAULT_VARIANT_NAME=DEFAULT_NAME;export var DEFAULT_ORIGIN="localhost";export var DEFAULT_BASE_URL="http://localhost:3000";export var DEFAULT_COOKIE_SETTINGS="Path=/; SameSite=Strict; Max-Age=2147483647; HttpOnly";export var DEFAULT_SITE_PATH="api/sites";export var DEFAULT_METRICS_PATH="api/metrics";export var NEXTJS_PUBLIC_PREFIX="NEXT_PUBLIC_";export var VARNAME_BASE_URL="IB_BASE_API_URL";export var VARNAME_BASE_URL_PUBLIC=NEXTJS_PUBLIC_PREFIX+VARNAME_BASE_URL;export var VARNAME_SITE_PATH="DEFAULT_SITE_PATH";export var VARNAME_METRICS_PATH="DEFAULT_METRICS_PATH";export var PARAM_TIMESTAMP="ts";export var PARAM_SELECT="select";export var HEADER_SESSION_ID="ibsession";export var DEFAULT_TIMEOUT=1e3;export var PROBABILITY_PRECISION=4;export var UUID_LENGTH=36;export var MAX_STORAGE_KEY_LENGTH=256;export var MAX_STORAGE_VALUE_LENGTH=1024;export var DefaultMetrics;!function(a){a.EXPOSURES="exposures",a.CONVERSIONS="conversions"}(DefaultMetrics||(DefaultMetrics={})) | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DefaultMetrics=exports.MAX_STORAGE_VALUE_LENGTH=exports.MAX_STORAGE_KEY_LENGTH=exports.UUID_LENGTH=exports.PROBABILITY_PRECISION=exports.DEFAULT_TIMEOUT=exports.HEADER_SESSION_ID=exports.PARAM_SELECT=exports.PARAM_TIMESTAMP=exports.VARNAME_METRICS_PATH=exports.VARNAME_SITE_PATH=exports.VARNAME_BASE_URL_PUBLIC=exports.VARNAME_BASE_URL=exports.NEXTJS_PUBLIC_PREFIX=exports.DEFAULT_METRICS_PATH=exports.DEFAULT_SITE_PATH=exports.DEFAULT_COOKIE_SETTINGS=exports.DEFAULT_BASE_URL=exports.DEFAULT_ORIGIN=exports.DEFAULT_VARIANT_NAME=exports.DEFAULT_VARIANT_ID=exports.DEFAULT_EXPERIMENT_NAME=exports.DEFAULT_EXPERIMENT_ID=exports.DEFAULT_SITE_NAME=exports.DEFAULT_SITE_ID=exports.DEFAULT_NAME=void 0,exports.DEFAULT_NAME="default",exports.DEFAULT_SITE_ID=exports.DEFAULT_NAME,exports.DEFAULT_SITE_NAME=exports.DEFAULT_NAME,exports.DEFAULT_EXPERIMENT_ID=exports.DEFAULT_NAME,exports.DEFAULT_EXPERIMENT_NAME=exports.DEFAULT_NAME,exports.DEFAULT_VARIANT_ID=exports.DEFAULT_NAME,exports.DEFAULT_VARIANT_NAME=exports.DEFAULT_NAME,exports.DEFAULT_ORIGIN="localhost",exports.DEFAULT_BASE_URL="http://localhost:3000",exports.DEFAULT_COOKIE_SETTINGS="Path=/; SameSite=Strict; Max-Age=2147483647; HttpOnly",exports.DEFAULT_SITE_PATH="api/sites",exports.DEFAULT_METRICS_PATH="api/metrics",exports.NEXTJS_PUBLIC_PREFIX="NEXT_PUBLIC_",exports.VARNAME_BASE_URL="IB_BASE_API_URL",exports.VARNAME_BASE_URL_PUBLIC=exports.NEXTJS_PUBLIC_PREFIX+exports.VARNAME_BASE_URL,exports.VARNAME_SITE_PATH="DEFAULT_SITE_PATH",exports.VARNAME_METRICS_PATH="DEFAULT_METRICS_PATH",exports.PARAM_TIMESTAMP="ts",exports.PARAM_SELECT="select",exports.HEADER_SESSION_ID="ibsession",exports.DEFAULT_TIMEOUT=1e3,exports.PROBABILITY_PRECISION=4,exports.UUID_LENGTH=36,exports.MAX_STORAGE_KEY_LENGTH=256,exports.MAX_STORAGE_VALUE_LENGTH=1024,function(a){a.EXPOSURES="exposures",a.CONVERSIONS="conversions"}(exports.DefaultMetrics||(exports.DefaultMetrics={})) |
@@ -1,1 +0,1 @@ | ||
import{__assign as a,__awaiter as e,__generator as f}from"tslib";import b from"react";import*as g from"./constants";import{getLocalStorageSessionProvider as h}from"./providers/session";import{getSiteProvider as i}from"./providers/site";import{DEFAULT_SITE_PROVIDER_OPTIONS as c}from"./providers/site";import{DEFAULT_METRICS_SINK_OPTIONS as d,getHttpMetricsSink as j}from"./providers/metrics";export function createBanditContext(d){var k=this,a=mergeBanditOptions(DEFAULT_BANDIT_OPTIONS,null!=d?d:{}),c=a.providers,b=c.loader(a),h=c.metrics(a),i=c.session(a),j={origin:"undefined"!=typeof location?location.origin:g.DEFAULT_ORIGIN,config:a,loader:b,metrics:h,session:i,get site(){return b.model},get experiment(){return b.experiment},get variant(){return b.variant},load:function(a){return e(k,void 0,void 0,function(){return f(this,function(c){switch(c.label){case 0:return[4,b.load(j,a)];case 1:return[2,c.sent()]}})})},init:function(a,c){return e(k,void 0,void 0,function(){return f(this,function(d){switch(d.label){case 0:return[4,b.init(j,a,c)];case 1:return[2,d.sent()]}})})},select:function(a){return e(k,void 0,void 0,function(){return f(this,function(c){return b.select(j,a),i.persistVariant(j,b.experiment.id,b.variant.name),[2,b.model]})})}};return j}export function mergeBanditOptions(a,b){var e,c=Object.assign({},a.providers,b.providers),d=Object.assign({},a,b,{providers:c});return Object.freeze(d)}export var DEFAULT_BANDIT_OPTIONS=a(a(a({},c),d),{providers:{loader:function(a){return i(a)},session:function(a){return h(a)},metrics:function(a){return j(a)}}});Object.freeze(DEFAULT_BANDIT_OPTIONS);export var InstantBanditContext=b.createContext(createBanditContext()) | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.InstantBanditContext=exports.DEFAULT_BANDIT_OPTIONS=exports.mergeBanditOptions=exports.createBanditContext=void 0;var a=require("tslib"),c=a.__importDefault(require("react")),g=a.__importStar(require("./constants")),h=require("./providers/session"),i=require("./providers/site"),d=require("./providers/site"),e=require("./providers/metrics");function b(e){var k=this,b=f(exports.DEFAULT_BANDIT_OPTIONS,null!=e?e:{}),d=b.providers,c=d.loader(b),h=d.metrics(b),i=d.session(b),j={origin:"undefined"!=typeof location?location.origin:g.DEFAULT_ORIGIN,config:b,loader:c,metrics:h,session:i,get site(){return c.model},get experiment(){return c.experiment},get variant(){return c.variant},load:function(b){return a.__awaiter(k,void 0,void 0,function(){return a.__generator(this,function(a){switch(a.label){case 0:return[4,c.load(j,b)];case 1:return[2,a.sent()]}})})},init:function(b,d){return a.__awaiter(k,void 0,void 0,function(){return a.__generator(this,function(a){switch(a.label){case 0:return[4,c.init(j,b,d)];case 1:return[2,a.sent()]}})})},select:function(b){return a.__awaiter(k,void 0,void 0,function(){return a.__generator(this,function(a){return c.select(j,b),i.persistVariant(j,c.experiment.id,c.variant.name),[2,c.model]})})}};return j}function f(a,b){var e,c=Object.assign({},a.providers,b.providers),d=Object.assign({},a,b,{providers:c});return Object.freeze(d)}exports.createBanditContext=b,exports.mergeBanditOptions=f,exports.DEFAULT_BANDIT_OPTIONS=a.__assign(a.__assign(a.__assign({},d.DEFAULT_SITE_PROVIDER_OPTIONS),e.DEFAULT_METRICS_SINK_OPTIONS),{providers:{loader:function(a){return(0,i.getSiteProvider)(a)},session:function(a){return(0,h.getLocalStorageSessionProvider)(a)},metrics:function(a){return(0,e.getHttpMetricsSink)(a)}}}),Object.freeze(exports.DEFAULT_BANDIT_OPTIONS),exports.InstantBanditContext=c.default.createContext(b()) |
@@ -1,1 +0,1 @@ | ||
import*as a from"./constants";import{deepFreeze as b,env as c}from"./utils";export var _a,DEFAULT_OPTIONS={baseUrl:null!==(_a=c(a.VARNAME_BASE_URL))&& void 0!==_a?_a:a.DEFAULT_BASE_URL};var d=a.DEFAULT_ORIGIN,e=a.DEFAULT_SITE_NAME,f=a.DEFAULT_EXPERIMENT_ID,g=a.DEFAULT_EXPERIMENT_NAME,h=a.DEFAULT_VARIANT_NAME;export var DEFAULT_SITE=b({name:e,origin:d,experiments:[{id:f,name:g,pValue:1,metrics:{},variants:[{name:h,prob:1,metrics:{},props:{}}]}]});export var DEFAULT_EXPERIMENT=DEFAULT_SITE.experiments[0];export var DEFAULT_VARIANT=DEFAULT_EXPERIMENT.variants[0];export var DEFAULT_METRICS=DEFAULT_VARIANT.metrics | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_METRICS=exports.DEFAULT_VARIANT=exports.DEFAULT_EXPERIMENT=exports.DEFAULT_SITE=exports.DEFAULT_OPTIONS=void 0;var b,a=require("tslib").__importStar(require("./constants")),c=require("./utils");exports.DEFAULT_OPTIONS={baseUrl:null!==(b=(0,c.env)(a.VARNAME_BASE_URL))&& void 0!==b?b:a.DEFAULT_BASE_URL};var d=a.DEFAULT_ORIGIN,e=a.DEFAULT_SITE_NAME,f=a.DEFAULT_EXPERIMENT_ID,g=a.DEFAULT_EXPERIMENT_NAME,h=a.DEFAULT_VARIANT_NAME;exports.DEFAULT_SITE=(0,c.deepFreeze)({name:e,origin:d,experiments:[{id:f,name:g,pValue:1,metrics:{},variants:[{name:h,prob:1,metrics:{},props:{}}]}]}),exports.DEFAULT_EXPERIMENT=exports.DEFAULT_SITE.experiments[0],exports.DEFAULT_VARIANT=exports.DEFAULT_EXPERIMENT.variants[0],exports.DEFAULT_METRICS=exports.DEFAULT_VARIANT.metrics |
@@ -1,1 +0,1 @@ | ||
import{useContext as a}from"react";import{InstantBanditContext as b}from"./contexts";export function useInstantBandit(){return a(b)} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useInstantBandit=void 0;var a=require("react"),b=require("./contexts");exports.useInstantBandit=function(){return(0,a.useContext)(b.InstantBanditContext)} |
@@ -1,1 +0,1 @@ | ||
export{} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}) |
@@ -1,1 +0,1 @@ | ||
import{__assign as a,__awaiter as e,__generator as f}from"tslib";import*as b from"../constants";import{DEFAULT_OPTIONS as c}from"../defaults";import{env as d,exists as g,getCookie as h}from"../utils";export var _a,DEFAULT_METRICS_SINK_OPTIONS=a(a({},c),{metricsPath:null!==(_a=d(b.VARNAME_METRICS_PATH))&& void 0!==_a?_a:b.DEFAULT_METRICS_PATH,batchSize:10,flushInterval:100});export function getHttpMetricsSink(a){var i=Object.assign({},DEFAULT_METRICS_SINK_OPTIONS,a),c=[],j=null,d={get pending(){return c.length},sink:function(b,e,a){if(void 0===a&&(a=!1),c.push(e),a)return d.flush(b);d.scheduleFlush(b)},sinkEvent:function(b,c,e,a){void 0===a&&(a=!1);try{var f={ts:new Date().getTime(),name:c,payload:e};d.sink(b,f,a)}catch(g){console.warn("[IB] Error sinking event: ".concat(g))}},scheduleFlush:function(a){!j&&(j=setTimeout(function(){return d.flush(a).catch(function(a){return console.warn(a)})},i.flushInterval))},flush:function(k,a){var l,m;return void 0===a&&(a=!1),e(this,void 0,void 0,function(){var e,n,o,p,q,r,s,t,u,v,w,x,y,z;return f(this,function(f){switch(f.label){case 0:if(e=i.baseUrl,n=i.batchSize,o=i.metricsPath,p=k.session,q=k.site,r=k.experiment,s=k.variant,!g(o)||""===o.trim())return console.debug("[IB] No metrics path configured"),c.splice(0,c.length),[2];t=a?c.length:Math.min(c.length,n),u=c.slice(0,t),v=null!==(m=null!==(l=p.id)&& void 0!==l?l:h(b.HEADER_SESSION_ID))&& void 0!==m?m:"",w={site:q.name,experiment:r.id,variant:s.name,entries:u},x=new URL(o,e),f.label=1;case 1:if(f.trys.push([1,5,6,7]),!(a&&"undefined"!=typeof navigator&& void 0!==navigator.sendBeacon))return[3,2];return sendBatchViaBeacon(x,w),[3,4];case 2:return[4,sendBatchViaFetch(x,v,w)];case 3:g((y=f.sent()).sid)&&k.session.save(k,y),f.label=4;case 4:return[3,7];case 5:return z=f.sent(),console.warn("Error occurred while flushing metrics: ".concat(z)),[3,7];case 6:return c.splice(0,t),j&&(clearTimeout(j),j=null),c.length>0&&d.scheduleFlush(k),[7];case 7:return[2]}})})}};return d}export function sendBatchViaBeacon(a,b){var c=new Blob([JSON.stringify(b)],{type:"application/json; charset=UTF-8"});return navigator.sendBeacon(a+"",c)}export function sendBatchViaFetch(a,c,d){return e(this,void 0,void 0,function(){var e,g,h,i,j;return f(this,function(f){switch(f.label){case 0:return[4,fetch(a.toString(),{method:"POST",headers:((j={Accept:"application/json","Content-Type":"application/json"})[b.HEADER_SESSION_ID]=c,j),body:JSON.stringify(d)})];case 1:if(g=(e=f.sent()).status,h=e.statusText,200!==g)return[3,3];return[4,e.json()];case 2:return[2,i=f.sent()];case 3:return[2,{status:g,statusText:h}]}})})} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.sendBatchViaFetch=exports.sendBatchViaBeacon=exports.getHttpMetricsSink=exports.DEFAULT_METRICS_SINK_OPTIONS=void 0;var a,b=require("tslib"),c=b.__importStar(require("../constants")),d=require("../defaults"),e=require("../utils");function f(a,b){var c=new Blob([JSON.stringify(b)],{type:"application/json; charset=UTF-8"});return navigator.sendBeacon(a+"",c)}function g(a,d,e){return b.__awaiter(this,void 0,void 0,function(){var f,g,h,i,j;return b.__generator(this,function(b){switch(b.label){case 0:return[4,fetch(a.toString(),{method:"POST",headers:((j={Accept:"application/json","Content-Type":"application/json"})[c.HEADER_SESSION_ID]=d,j),body:JSON.stringify(e)})];case 1:if(g=(f=b.sent()).status,h=f.statusText,200!==g)return[3,3];return[4,f.json()];case 2:return[2,i=b.sent()];case 3:return[2,{status:g,statusText:h}]}})})}exports.DEFAULT_METRICS_SINK_OPTIONS=b.__assign(b.__assign({},d.DEFAULT_OPTIONS),{metricsPath:null!==(a=(0,e.env)(c.VARNAME_METRICS_PATH))&& void 0!==a?a:c.DEFAULT_METRICS_PATH,batchSize:10,flushInterval:100}),exports.getHttpMetricsSink=function(a){var i=Object.assign({},exports.DEFAULT_METRICS_SINK_OPTIONS,a),d=[],j=null,h={get pending(){return d.length},sink:function(b,c,a){if(void 0===a&&(a=!1),d.push(c),a)return h.flush(b);h.scheduleFlush(b)},sinkEvent:function(b,c,d,a){void 0===a&&(a=!1);try{var e={ts:new Date().getTime(),name:c,payload:d};h.sink(b,e,a)}catch(f){console.warn("[IB] Error sinking event: ".concat(f))}},scheduleFlush:function(a){!j&&(j=setTimeout(function(){return h.flush(a).catch(function(a){return console.warn(a)})},i.flushInterval))},flush:function(k,a){var l,m;return void 0===a&&(a=!1),b.__awaiter(this,void 0,void 0,function(){var n,o,p,q,r,s,t,u,v,w,x,y,z,A;return b.__generator(this,function(b){switch(b.label){case 0:if(n=i.baseUrl,o=i.batchSize,p=i.metricsPath,q=k.session,r=k.site,s=k.experiment,t=k.variant,!(0,e.exists)(p)||""===p.trim())return console.debug("[IB] No metrics path configured"),d.splice(0,d.length),[2];u=a?d.length:Math.min(d.length,o),v=d.slice(0,u),w=null!==(m=null!==(l=q.id)&& void 0!==l?l:(0,e.getCookie)(c.HEADER_SESSION_ID))&& void 0!==m?m:"",x={site:r.name,experiment:s.id,variant:t.name,entries:v},y=new URL(p,n),b.label=1;case 1:if(b.trys.push([1,5,6,7]),!(a&&"undefined"!=typeof navigator&& void 0!==navigator.sendBeacon))return[3,2];return f(y,x),[3,4];case 2:return[4,g(y,w,x)];case 3:z=b.sent(),(0,e.exists)(z.sid)&&k.session.save(k,z),b.label=4;case 4:return[3,7];case 5:return A=b.sent(),console.warn("Error occurred while flushing metrics: ".concat(A)),[3,7];case 6:return d.splice(0,u),j&&(clearTimeout(j),j=null),d.length>0&&h.scheduleFlush(k),[7];case 7:return[2]}})})}};return h},exports.sendBatchViaBeacon=f,exports.sendBatchViaFetch=g |
@@ -1,1 +0,1 @@ | ||
import{exists as a,isBrowserEnvironment as b,makeNewSession as c,markVariantInSession as d}from"../utils";import{DEFAULT_EXPERIMENT as e,DEFAULT_SITE as f,DEFAULT_VARIANT as g}from"../defaults";import{HEADER_SESSION_ID as h}from"../constants";export function getLocalStorageKey(){return h}export function getLocalStorageSessionProvider(){var b=null;return{get id(){return b},getOrCreateSession:function(d,e){var c=i(d,e);return a(c.sid)&&(b=c.sid),c},persistVariant:function(a,b,c){return j(a,b,c)},hasSeen:function(a,b,c){return m(a,b,c)},save:function(e,a){b=a.sid;var c=getLocalStorageKey();try{localStorage.setItem(c,JSON.stringify(a))}catch(d){k(d)}return a}}}function i(j,e){if(!b)return Object.assign(c(),e);var d,g=j.site;a(g)||(g=f);var h=getLocalStorageKey(),i=localStorage.getItem(h);d=a(i)?JSON.parse(i):c(),e&&Object.assign(d,e);try{localStorage.setItem(h,JSON.stringify(d))}catch(l){k(l)}return d}function j(a,c,f){if(b&&(c!==e.id||f!==g.name)){var j=a.site,l=getLocalStorageKey(),h=i(a);d(h,j.name,c,f);try{localStorage.setItem(l,JSON.stringify(h))}catch(m){k(m)}}}function k(a){l(a)?console.debug("[IB] Storage quota error: ".concat(a)):console.warn("[IB] Error updating session: ".concat(a))}function l(b){if(!b||!a(b.code))return!1;switch(b.code){case 22:return!0;case 1014:return"NS_ERROR_DOM_QUOTA_REACHED"===b.name;default:return!1}}function m(e,g,k){if(!b)return!1;var c,d,h=e.site,j=i(e),f=null===(d=null===(c=j.selections)|| void 0===c?void 0:c[h.name])|| void 0===d?void 0:d[g];return a(f)&&a(f.find(function(a){return a===k}))} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLocalStorageSessionProvider=exports.getLocalStorageKey=void 0;var b=require("../utils"),c=require("../defaults"),d=require("../constants");function a(){return d.HEADER_SESSION_ID}function e(j,e){if(!b.isBrowserEnvironment)return Object.assign((0,b.makeNewSession)(),e);var d,g=j.site;(0,b.exists)(g)||(g=c.DEFAULT_SITE);var h=a(),i=localStorage.getItem(h);d=(0,b.exists)(i)?JSON.parse(i):(0,b.makeNewSession)(),e&&Object.assign(d,e);try{localStorage.setItem(h,JSON.stringify(d))}catch(k){f(k)}return d}exports.getLocalStorageKey=a;function f(a){g(a)?console.debug("[IB] Storage quota error: ".concat(a)):console.warn("[IB] Error updating session: ".concat(a))}function g(a){if(!a||!(0,b.exists)(a.code))return!1;switch(a.code){case 22:return!0;case 1014:return"NS_ERROR_DOM_QUOTA_REACHED"===a.name;default:return!1}}exports.getLocalStorageSessionProvider=function(g){var d=null;return{get id(){return d},getOrCreateSession:function(c,f){var a=e(c,f);return(0,b.exists)(a.sid)&&(d=a.sid),a},persistVariant:function(d,g,h){return function m(d,g,h){if(b.isBrowserEnvironment&&(g!==c.DEFAULT_EXPERIMENT.id||h!==c.DEFAULT_VARIANT.name)){var j=d.site,k=a(),i=e(d);(0,b.markVariantInSession)(i,j.name,g,h);try{localStorage.setItem(k,JSON.stringify(i))}catch(l){f(l)}}}(d,g,h)},hasSeen:function(a,c,d){return function j(d,g,k){if(!b.isBrowserEnvironment)return!1;var a,c,h=d.site,i=e(d),f=null===(c=null===(a=i.selections)|| void 0===a?void 0:a[h.name])|| void 0===c?void 0:c[g];return(0,b.exists)(f)&&(0,b.exists)(f.find(function(a){return a===k}))}(a,c,d)},save:function(g,b){d=b.sid;var c=a();try{localStorage.setItem(c,JSON.stringify(b))}catch(e){f(e)}return b}}} |
@@ -1,1 +0,1 @@ | ||
import{__assign as a,__awaiter as e,__generator as f}from"tslib";import*as b from"../constants";import{LoadState as g}from"../types";import{env as c,exists as h,isBrowserEnvironment as i}from"../utils";import{DEFAULT_EXPERIMENT as j,DEFAULT_OPTIONS as d,DEFAULT_SITE as k,DEFAULT_VARIANT as l}from"../defaults";export var _a,DEFAULT_SITE_PROVIDER_OPTIONS=a(a({},d),{sitePath:null!==(_a=c(b.VARNAME_SITE_PATH))&& void 0!==_a?_a:b.DEFAULT_SITE_PATH,appendTimestamp:!1});Object.freeze(DEFAULT_SITE_PROVIDER_OPTIONS);export function getSiteProvider(a){void 0===a&&(a={});var c=Object.assign({},DEFAULT_SITE_PROVIDER_OPTIONS,a);Object.freeze(c);var d=g.PRELOAD,m=null,n=k,o=j,p=l,q={get error(){return m},get origin(){if(i)return location.origin;return b.DEFAULT_ORIGIN},get model(){return n},get experiment(){return o},get variant(){return p},get state(){return d},load:function(h,a,i){return void 0===a&&(a=k.name),e(this,void 0,void 0,function(){var e,j,l,o,p,r,s;return f(this,function(f){switch(f.label){case 0:e="",f.label=1;case 1:return f.trys.push([1,5,7,8]),j=c.baseUrl,l=c.sitePath,e=(o=new URL([l,a].join("/"),j)).toString(),!0===c.appendTimestamp&&o.searchParams.append(b.PARAM_TIMESTAMP,new Date().getTime()+""),e=o.toString(),d=g.WAIT,[4,fetch(e)];case 2:return[4,(p=f.sent()).json()];case 3:return r=f.sent(),[4,q.init(h,r,i)];case 4:return n=f.sent(),[3,8];case 5:return m=s=f.sent(),console.warn("[IB] An error occurred while loading from '".concat(e,"': ").concat(s,". Default site will be used.")),[4,q.init(h,k,i)];case 6:return f.sent(),[3,8];case 7:return d=g.READY,[7];case 8:return[2,n]}})})},init:function(e,a,f){try{if(!a||"object"!=typeof a)throw Error("Invalid site configuration");m=null,d=g.SELECTING,n=Object.assign({},a);var b=q.select(e,f),h=b.experiment,i=b.variant;return o=Object.assign({},h),p=Object.assign({},i),d=g.READY,n}catch(c){m=c,n=k,o=j,p=l,console.warn("[IB] Error initializing. Default site will be used. Error was: ".concat(c))}finally{d=g.READY}return n||(n=k,o=j,p=l),n},select:function(s,d){var e,f,g,i,r;try{var c=null!==(e=null!=d?d:n.select)&& void 0!==e?e:void 0,b=null!==(g=null!==(f=getActiveExperiment(n,c))&& void 0!==f?f:getDefaultExperiment(n))&& void 0!==g?g:j,a=null,t=s.session;if(h(c)&&c){var u=q.selectSpecific(b,c);b=u.experiment,a=u.variant}else if(t){var v=t.getOrCreateSession(s).selections[n.name],x=null===(i=null==v?void 0:v[b.id])|| void 0===i?void 0:i.slice().reverse()[0];a=null!==(r=b.variants.find(function(a){return a.name===x}))&& void 0!==r?r:null}return a||(a=selectWithProbabilities(b)),a||(a=l),{experiment:b,variant:a}}catch(w){return m=w,n=k,o=j,p=l,console.warn("[IB] Error encountered while selecting variant '".concat(d,"': ").concat(w)),{experiment:j,variant:l}}},selectSpecific:function(c,d){var b,a=c.variants.find(function(a){return a.name===d});return a?{experiment:c,variant:a}:(a=null==(b=n.experiments.find(function(a){return a.id===j.id}))?void 0:b.variants.find(function(a){return a.name===l.name}),b&&!a)?{experiment:b,variant:l}:a?{experiment:c,variant:a}:{experiment:j,variant:l}}};return q}export function selectWithProbabilities(c){for(var h,d=c.variants,e=balanceProbabilities(d),f=null,i=Math.random(),j=0,g=Object.entries(e).sort(function(a,b){return a[1]-b[1]}),a=0,b=g;a<b.length&&"break"!==function(a){var b=a[0];if(i<=(j+=a[1]))return f=null!==(h=d.find(function(a){return a.name===b}))&& void 0!==h?h:null,"break"}(b[a]);a++);return f}export function balanceProbabilities(d){for(var f=d.reduce(function(b,c){var a;return b+(null!==(a=c.prob)&& void 0!==a?a:0)},0),c={},e=0,g=d;e<g.length;e++){var a=g[e];if((!h(a.prob)||isNaN(a.prob)||0===a.prob)&&(c[a.name]=0),0===f)c[a.name]=parseFloat((1/d.length).toPrecision(b.PROBABILITY_PRECISION));else{var i=1/f;c[a.name]=h(a.prob)?parseFloat((a.prob*i).toPrecision(b.PROBABILITY_PRECISION)):0}}return c}export function getActiveExperiment(e,f){var c,d,a=(null!==(c=e.experiments)&& void 0!==c?c:[]).filter(function(a){return!h(f)||a.variants.some(function(a){return a.name===f})}).filter(function(a){return!0!==a.inactive})[0];return a||(a=null===(d=e.experiments.filter(function(a){return a.id===b.DEFAULT_EXPERIMENT_ID}))|| void 0===d?void 0:d[0]),null!=a?a:null}export function getDefaultExperiment(c){var a,b;return null!==(b=null===(a=c.experiments.filter(function(a){return a.id===j.id}))|| void 0===a?void 0:a[0])&& void 0!==b?b:j} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getDefaultExperiment=exports.getActiveExperiment=exports.balanceProbabilities=exports.selectWithProbabilities=exports.getSiteProvider=exports.DEFAULT_SITE_PROVIDER_OPTIONS=void 0;var a,b=require("tslib"),c=b.__importStar(require("../constants")),j=require("../types"),d=require("../utils"),e=require("../defaults");function f(c){for(var i,d=c.variants,e=g(d),f=null,j=Math.random(),k=0,h=Object.entries(e).sort(function(a,b){return a[1]-b[1]}),a=0,b=h;a<b.length&&"break"!==function(a){var b=a[0];if(j<=(k+=a[1]))return f=null!==(i=d.find(function(a){return a.name===b}))&& void 0!==i?i:null,"break"}(b[a]);a++);return f}function g(e){for(var g=e.reduce(function(b,c){var a;return b+(null!==(a=c.prob)&& void 0!==a?a:0)},0),b={},f=0,h=e;f<h.length;f++){var a=h[f];if((!(0,d.exists)(a.prob)||isNaN(a.prob)||0===a.prob)&&(b[a.name]=0),0===g)b[a.name]=parseFloat((1/e.length).toPrecision(c.PROBABILITY_PRECISION));else{var i=1/g;b[a.name]=(0,d.exists)(a.prob)?parseFloat((a.prob*i).toPrecision(c.PROBABILITY_PRECISION)):0}}return b}function h(f,g){var b,e,a=(null!==(b=f.experiments)&& void 0!==b?b:[]).filter(function(a){return!(0,d.exists)(g)||a.variants.some(function(a){return a.name===g})}).filter(function(a){return!0!==a.inactive})[0];return a||(a=null===(e=f.experiments.filter(function(a){return a.id===c.DEFAULT_EXPERIMENT_ID}))|| void 0===e?void 0:e[0]),null!=a?a:null}function i(c){var a,b;return null!==(b=null===(a=c.experiments.filter(function(a){return a.id===e.DEFAULT_EXPERIMENT.id}))|| void 0===a?void 0:a[0])&& void 0!==b?b:e.DEFAULT_EXPERIMENT}exports.DEFAULT_SITE_PROVIDER_OPTIONS=b.__assign(b.__assign({},e.DEFAULT_OPTIONS),{sitePath:null!==(a=(0,d.env)(c.VARNAME_SITE_PATH))&& void 0!==a?a:c.DEFAULT_SITE_PATH,appendTimestamp:!1}),Object.freeze(exports.DEFAULT_SITE_PROVIDER_OPTIONS),exports.getSiteProvider=function(a){void 0===a&&(a={});var g=Object.assign({},exports.DEFAULT_SITE_PROVIDER_OPTIONS,a);Object.freeze(g);var k=j.LoadState.PRELOAD,l=null,m=e.DEFAULT_SITE,n=e.DEFAULT_EXPERIMENT,o=e.DEFAULT_VARIANT,p={get error(){return l},get origin(){if(d.isBrowserEnvironment)return location.origin;return c.DEFAULT_ORIGIN},get model(){return m},get experiment(){return n},get variant(){return o},get state(){return k},load:function(d,a,f){return void 0===a&&(a=e.DEFAULT_SITE.name),b.__awaiter(this,void 0,void 0,function(){var h,i,n,o,q,r,s;return b.__generator(this,function(b){switch(b.label){case 0:h="",b.label=1;case 1:return b.trys.push([1,5,7,8]),i=g.baseUrl,n=g.sitePath,h=(o=new URL([n,a].join("/"),i)).toString(),!0===g.appendTimestamp&&o.searchParams.append(c.PARAM_TIMESTAMP,new Date().getTime()+""),h=o.toString(),k=j.LoadState.WAIT,[4,fetch(h)];case 2:return[4,(q=b.sent()).json()];case 3:return r=b.sent(),[4,p.init(d,r,f)];case 4:return m=b.sent(),[3,8];case 5:return l=s=b.sent(),console.warn("[IB] An error occurred while loading from '".concat(h,"': ").concat(s,". Default site will be used.")),[4,p.init(d,e.DEFAULT_SITE,f)];case 6:return b.sent(),[3,8];case 7:return k=j.LoadState.READY,[7];case 8:return[2,m]}})})},init:function(d,a,f){try{if(!a||"object"!=typeof a)throw Error("Invalid site configuration");l=null,k=j.LoadState.SELECTING,m=Object.assign({},a);var b=p.select(d,f),g=b.experiment,h=b.variant;return n=Object.assign({},g),o=Object.assign({},h),k=j.LoadState.READY,m}catch(c){l=c,m=e.DEFAULT_SITE,n=e.DEFAULT_EXPERIMENT,o=e.DEFAULT_VARIANT,console.warn("[IB] Error initializing. Default site will be used. Error was: ".concat(c))}finally{k=j.LoadState.READY}return m||(m=e.DEFAULT_SITE,n=e.DEFAULT_EXPERIMENT,o=e.DEFAULT_VARIANT),m},select:function(t,g){var j,k,q,r,s;try{var c=null!==(j=null!=g?g:m.select)&& void 0!==j?j:void 0,b=null!==(q=null!==(k=h(m,c))&& void 0!==k?k:i(m))&& void 0!==q?q:e.DEFAULT_EXPERIMENT,a=null,u=t.session;if((0,d.exists)(c)&&c){var v=p.selectSpecific(b,c);b=v.experiment,a=v.variant}else if(u){var w=u.getOrCreateSession(t).selections[m.name],y=null===(r=null==w?void 0:w[b.id])|| void 0===r?void 0:r.slice().reverse()[0];a=null!==(s=b.variants.find(function(a){return a.name===y}))&& void 0!==s?s:null}return a||(a=f(b)),a||(a=e.DEFAULT_VARIANT),{experiment:b,variant:a}}catch(x){return l=x,m=e.DEFAULT_SITE,n=e.DEFAULT_EXPERIMENT,o=e.DEFAULT_VARIANT,console.warn("[IB] Error encountered while selecting variant '".concat(g,"': ").concat(x)),{experiment:e.DEFAULT_EXPERIMENT,variant:e.DEFAULT_VARIANT}}},selectSpecific:function(c,d){var b,a=c.variants.find(function(a){return a.name===d});return a?{experiment:c,variant:a}:(a=null==(b=m.experiments.find(function(a){return a.id===e.DEFAULT_EXPERIMENT.id}))?void 0:b.variants.find(function(a){return a.name===e.DEFAULT_VARIANT.name}),b&&!a)?{experiment:b,variant:e.DEFAULT_VARIANT}:a?{experiment:c,variant:a}:{experiment:e.DEFAULT_EXPERIMENT,variant:e.DEFAULT_VARIANT}}};return p},exports.selectWithProbabilities=f,exports.balanceProbabilities=g,exports.getActiveExperiment=h,exports.getDefaultExperiment=i |
@@ -1,1 +0,1 @@ | ||
import{__awaiter as c,__generator as d}from"tslib";import a from"fs";import e from"path";import{cwd as f}from"process";import b from"../environment";import{DEFAULT_SITE as g}from"../../defaults";var h=a.promises;export function getJsonSiteBackend(a){var e=function(a){console.warn("[IB] Error scanning sites: ".concat(a))};void 0===a&&(a={});var f=Object.assign({},DEFAULT_STATIC_SITE_BACKEND_OPTIONS,a),h={},i=0;return{connect:function(){return c(this,void 0,void 0,function(){var a;return d(this,function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),[4,scanSites(b.IB_STATIC_SITES_PATH,h,i)];case 1:return h=c.sent(),[3,3];case 2:return e(a=c.sent()),[3,3];case 3:return[2]}})})},getSiteConfig:function(a){return c(this,void 0,void 0,function(){var c,j,k,l,m,n,o;return d(this,function(d){return(c=a.siteName,j=f.refreshInterval,k=new Date().getTime(),l=j> -1,m=k-i>j,l&&m&&scanSites(b.IB_STATIC_SITES_PATH,h,i).then(function(a){return h=a}).then(function(){return i=k}).catch(e),n=null!=c?c:g.name,o=h[n])?(o.name!==n&&(console.warn("[IB] Site '".concat(n,"'.json doesn't match name '").concat(o.name,"' in contents.")),o.name=n),[2,o]):(console.warn("[IB] Could not find site '".concat(n,"'")),[2,g])})})}}}export function scanSites(g,a,b){return void 0===a&&(a={}),void 0===b&&(b=0),c(this,void 0,void 0,function(){var c,i,j,k,l,m,n,o,p,q,r,s,t,u,v;return d(this,function(d){switch(d.label){case 0:return d.trys.push([0,2,,3]),[4,h.stat(g)];case 1:return d.sent(),[3,3];case 2:return c=d.sent(),console.warn("[IB] Public sites folder does not exist"),[2,a];case 3:return[4,h.readdir(g)];case 4:j=(i=d.sent()).filter(function(a){return a.endsWith(".json")}),k=e.join(f(),g),l=0,m=j,d.label=5;case 5:if(!(l<m.length))return[3,11];return o=(n=m[l]).replace(".json",""),p=e.join(k,n),[4,h.stat(p)];case 6:if((r=(q=d.sent()).mtimeMs)<b)return[3,10];d.label=7;case 7:return d.trys.push([7,9,,10]),[4,h.readFile(p)];case 8:return u=JSON.parse(t=(s=d.sent()).toString("utf-8")),a[o]=u,[3,10];case 9:return v=d.sent(),console.warn("[IB] Error reading '".concat(g,"/").concat(n,"': ").concat(v)),[3,10];case 10:return l++,[3,5];case 11:return[2,a]}})})}export var DEFAULT_STATIC_SITE_BACKEND_OPTIONS={basePath:b.IB_STATIC_SITES_PATH,refreshInterval:1e4} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_STATIC_SITE_BACKEND_OPTIONS=exports.scanSites=exports.getJsonSiteBackend=void 0;var a=require("tslib"),b=a.__importDefault(require("fs")),e=a.__importDefault(require("path")),f=require("process"),c=a.__importDefault(require("../environment")),g=require("../../defaults"),h=b.default.promises;function d(d,b,c){return void 0===b&&(b={}),void 0===c&&(c=0),a.__awaiter(this,void 0,void 0,function(){var g,i,j,k,l,m,n,o,p,q,r,s,t,u,v;return a.__generator(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,h.stat(d)];case 1:return a.sent(),[3,3];case 2:return g=a.sent(),console.warn("[IB] Public sites folder does not exist"),[2,b];case 3:return[4,h.readdir(d)];case 4:j=(i=a.sent()).filter(function(a){return a.endsWith(".json")}),k=e.default.join((0,f.cwd)(),d),l=0,m=j,a.label=5;case 5:if(!(l<m.length))return[3,11];return o=(n=m[l]).replace(".json",""),p=e.default.join(k,n),[4,h.stat(p)];case 6:if((r=(q=a.sent()).mtimeMs)<c)return[3,10];a.label=7;case 7:return a.trys.push([7,9,,10]),[4,h.readFile(p)];case 8:return u=JSON.parse(t=(s=a.sent()).toString("utf-8")),b[o]=u,[3,10];case 9:return v=a.sent(),console.warn("[IB] Error reading '".concat(d,"/").concat(n,"': ").concat(v)),[3,10];case 10:return l++,[3,5];case 11:return[2,b]}})})}exports.getJsonSiteBackend=function(b){var e=function(a){console.warn("[IB] Error scanning sites: ".concat(a))};void 0===b&&(b={});var f=Object.assign({},exports.DEFAULT_STATIC_SITE_BACKEND_OPTIONS,b),h={},i=0;return{connect:function(){return a.__awaiter(this,void 0,void 0,function(){var b;return a.__generator(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,d(c.default.IB_STATIC_SITES_PATH,h,i)];case 1:return h=a.sent(),[3,3];case 2:return e(b=a.sent()),[3,3];case 3:return[2]}})})},getSiteConfig:function(b){return a.__awaiter(this,void 0,void 0,function(){var j,k,l,m,n,o,p;return a.__generator(this,function(a){return(j=b.siteName,k=f.refreshInterval,l=new Date().getTime(),m=k> -1,n=l-i>k,m&&n&&d(c.default.IB_STATIC_SITES_PATH,h,i).then(function(a){return h=a}).then(function(){return i=l}).catch(e),o=null!=j?j:g.DEFAULT_SITE.name,p=h[o])?(p.name!==o&&(console.warn("[IB] Site '".concat(o,"'.json doesn't match name '").concat(p.name,"' in contents.")),p.name=o),[2,p]):(console.warn("[IB] Could not find site '".concat(o,"'")),[2,g.DEFAULT_SITE])})})}}},exports.scanSites=d,exports.DEFAULT_STATIC_SITE_BACKEND_OPTIONS={basePath:c.default.IB_STATIC_SITES_PATH,refreshInterval:1e4} |
@@ -1,1 +0,1 @@ | ||
import{__awaiter as a,__generator as b}from"tslib";import{randomUUID as c}from"crypto";import d from"ioredis";import e from"../environment";import{makeKey as f,toNumber as g}from"../server-utils";import{exists as h,markVariantInSession as i}from"../../utils";import{UUID_LENGTH as j}from"../../constants";export var DEFAULT_REDIS_OPTIONS={lazyConnect:!0,disconnectWaitDuration:50,retryStrategy:function(a){var b=parseInt(e.IB_REDIS_RETRY_COUNT+""),c=parseInt(e.IB_REDIS_RETRY_INTERVAL+"");return(console.info("[IB] Connecting to Redis attempt # ".concat(a," out of ").concat(b)),a>=b)?null:c}};export function getRedisBackend(c){void 0===c&&(c={});var e=Object.freeze(Object.assign({},DEFAULT_REDIS_OPTIONS,c)),f=new d(e),g=!1;return{get client(){return f},get connected(){return g},connect:function(){return a(this,void 0,void 0,function(){return b(this,function(a){return[2,new Promise(function(a){if(g){a();return}switch(f.status){case"connecting":case"connect":case"ready":a();return;default:console.info("[IB] Connecting to redis..."),f.on("error",function(a){console.error("[IB] Error connecting to Redis: ".concat(a)),g=!1}).on("close",function(){g=!1,console.log("[IB] Redis connection closed")}).on("connect",function(){g=!0,console.log("[IB] Redis connection opened")}).connect().catch(function(a){}),a();return}})]})})},disconnect:function(){return a(this,void 0,void 0,function(){return b(this,function(a){switch(a.label){case 0:if(a.trys.push([0,,3,6]),console.debug("[IB] Disconnecting from redis..."),"ready"!==f.status)return[3,2];return[4,f.quit()];case 1:a.sent(),a.label=2;case 2:return g=!1,f.disconnect(),[3,6];case 3:if("ready"!==f.status)return[3,5];return[4,new Promise(function(a){return setTimeout(a,e.disconnectWaitDuration)})];case 4:return a.sent(),[3,3];case 5:return[7];case 6:return[2]}})})},getMetricsForSite:function(c,d){return a(this,void 0,void 0,function(){return b(this,function(a){return g?[2,getMetricsForSite(f,c,d)]:[2,new Map]})})},getMetricsBucket:function(c,d,e){return a(this,void 0,void 0,function(){return b(this,function(a){return g?[2,getMetricsBucket(f,c,d,e)]:[2,{}]})})},ingestBatch:function(c,d){return a(this,void 0,void 0,function(){return b(this,function(a){return g?[2,ingestBatch(f,c,d)]:[2]})})},getOrCreateSession:function(c){return a(this,void 0,void 0,function(){return b(this,function(a){if(!g)throw Error("Not connected to Redis session store");return[2,getOrCreateSession(f,c)]})})},markVariantSeen:function(c,d,e,h){return a(this,void 0,void 0,function(){return b(this,function(a){return g?[2,markVariantSeen(f,c,d,e,h)]:(i(c,d,e,h),[2,c])})})}}}export function getMetricsForSite(c,d,e){return a(this,void 0,void 0,function(){var a,f,g,h,i,j,k,l;return b(this,function(b){switch(b.label){case 0:a=new Map,f=0,g=e,b.label=1;case 1:if(!(f<g.length))return[3,6];i=0,j=(h=g[f]).variants,b.label=2;case 2:if(!(i<j.length))return[3,5];return k=j[i],[4,getMetricsBucket(c,d.name,h.id,k.name)];case 3:l=b.sent(),a.set(k,l),b.label=4;case 4:return i++,[3,2];case 5:return f++,[3,1];case 6:return[2,a]}})})}export function getOrCreateSession(d,e){return a(this,void 0,void 0,function(){var a,g,i,k,l,m,n,o,p;return b(this,function(b){switch(b.label){case 0:if(a=e.siteName,g=e.sid,i=f(["sessions"]),k=null,!(h(g)&&g.length===j))return[3,2];return o=f(["session",g]),[4,d.get(o)];case 1:if(h(l=b.sent()))return[2,k=JSON.parse(l)];console.warn("[IB] Invalid or unknown session '".concat(o,"'")),b.label=2;case 2:if(h(k))return[3,6];if(!h(a))throw Error("Invalid session scope");m=JSON.stringify(k={sid:g=c(),selections:{}}),n=d.multi(),b.label=3;case 3:return b.trys.push([3,5,,6]),o=f(["session",k.sid]),n.sadd(i,k.sid),n.set(o,m),[4,n.exec()];case 4:return b.sent(),[3,6];case 5:return p=b.sent(),console.warn("[IB] Error saving session '".concat(g,"': ").concat(p)),[3,6];case 6:return[2,k]}})})}export function markVariantSeen(c,d,e,g,h){return a(this,void 0,void 0,function(){var a,j,k;return b(this,function(b){switch(b.label){case 0:i(d,e,g,h),a=JSON.stringify(d),j=f(["session",d.sid]),b.label=1;case 1:return b.trys.push([1,3,,4]),[4,c.set(j,a)];case 2:return b.sent(),[3,4];case 3:return k=b.sent(),console.warn("[IB] Error saving session '".concat(d.sid,"': ").concat(k)),[3,4];case 4:return[2,d]}})})}export function ingestBatch(c,d,e){var f;return a(this,void 0,void 0,function(){var a,g,i,j,k,l,m,n,o,p;return b(this,function(b){switch(b.label){case 0:if(!h(a=d.sid))throw Error("Missing session");if(g=e.site,i=e.experiment,j=e.variant,k=e.entries,!(null!==(f=d.session)&& void 0!==f))return[3,1];return m=f,[3,3];case 1:return[4,getOrCreateSession(c,d)];case 2:m=b.sent(),b.label=3;case 3:return[4,markVariantSeen(c,l=m,g,i,j)];case 4:b.sent(),n=c.pipeline(),o=0,k.filter(isValidMetricsSample).forEach(function(a){var b=a.ts,c=a.name;!(b<o)&&(incrementMetricInPipeline(n,g,i,j,c,1),o=b)}),b.label=5;case 5:return b.trys.push([5,7,,8]),[4,n.exec()];case 6:return b.sent(),[3,8];case 7:return p=b.sent(),console.error("[IB] Error while pipelining ".concat(k.length," for '").concat(a,"'")),[3,8];case 8:return[2]}})})}export function isValidMetricsSample(a){var c=a.ts,b=a.payload;return"number"==typeof c&&!("string"==typeof b&&b.length>parseInt(e.IB_MAX_METRICS_PAYLOAD_LEN+""))}export function incrementMetricInPipeline(b,c,g,h,d,a){if(void 0===a&&(a=1),null==c)throw Error("Missing site ID in incrementExposure");var e=f([c,g,h,"metrics"]);return a%1==0?b.hincrby(e,d,a):b.hincrbyfloat(e,d,a),b}export function getMetricsBucket(c,d,e,i){return a(this,void 0,void 0,function(){var a,j,k;return b(this,function(b){switch(b.label){case 0:return a=f([d,e,i,"metrics"]),[4,c.hgetall(a)];case 1:if(!h(j=b.sent()))return[2,{}];return k={},Object.keys(j).forEach(function(a){return k[a]=g(j[a])}),[2,k]}})})} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMetricsBucket=exports.incrementMetricInPipeline=exports.isValidMetricsSample=exports.ingestBatch=exports.markVariantSeen=exports.getOrCreateSession=exports.getMetricsForSite=exports.getRedisBackend=exports.DEFAULT_REDIS_OPTIONS=void 0;var a=require("tslib"),i=require("crypto"),j=a.__importDefault(require("ioredis")),k=a.__importDefault(require("../environment")),l=require("../server-utils"),m=require("../../utils"),n=require("../../constants");function b(b,c,d){return a.__awaiter(this,void 0,void 0,function(){var e,f,g,i,j,k,l,m;return a.__generator(this,function(a){switch(a.label){case 0:e=new Map,f=0,g=d,a.label=1;case 1:if(!(f<g.length))return[3,6];j=0,k=(i=g[f]).variants,a.label=2;case 2:if(!(j<k.length))return[3,5];return l=k[j],[4,h(b,c.name,i.id,l.name)];case 3:m=a.sent(),e.set(l,m),a.label=4;case 4:return j++,[3,2];case 5:return f++,[3,1];case 6:return[2,e]}})})}function c(b,c){return a.__awaiter(this,void 0,void 0,function(){var d,e,f,g,h,j,k,o,p;return a.__generator(this,function(a){switch(a.label){case 0:if(d=c.siteName,e=c.sid,f=(0,l.makeKey)(["sessions"]),g=null,!((0,m.exists)(e)&&e.length===n.UUID_LENGTH))return[3,2];return o=(0,l.makeKey)(["session",e]),[4,b.get(o)];case 1:if(h=a.sent(),(0,m.exists)(h))return[2,g=JSON.parse(h)];console.warn("[IB] Invalid or unknown session '".concat(o,"'")),a.label=2;case 2:if((0,m.exists)(g))return[3,6];if(!(0,m.exists)(d))throw Error("Invalid session scope");j=JSON.stringify(g={sid:e=(0,i.randomUUID)(),selections:{}}),k=b.multi(),a.label=3;case 3:return a.trys.push([3,5,,6]),o=(0,l.makeKey)(["session",g.sid]),k.sadd(f,g.sid),k.set(o,j),[4,k.exec()];case 4:return a.sent(),[3,6];case 5:return p=a.sent(),console.warn("[IB] Error saving session '".concat(e,"': ").concat(p)),[3,6];case 6:return[2,g]}})})}function d(b,c,d,e,f){return a.__awaiter(this,void 0,void 0,function(){var g,h,i;return a.__generator(this,function(a){switch(a.label){case 0:(0,m.markVariantInSession)(c,d,e,f),g=JSON.stringify(c),h=(0,l.makeKey)(["session",c.sid]),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,b.set(h,g)];case 2:return a.sent(),[3,4];case 3:return i=a.sent(),console.warn("[IB] Error saving session '".concat(c.sid,"': ").concat(i)),[3,4];case 4:return[2,c]}})})}function e(b,e,h){var i;return a.__awaiter(this,void 0,void 0,function(){var j,k,l,n,o,p,q,r,s,t;return a.__generator(this,function(a){switch(a.label){case 0:if(j=e.sid,!(0,m.exists)(j))throw Error("Missing session");if(k=h.site,l=h.experiment,n=h.variant,o=h.entries,!(null!==(i=e.session)&& void 0!==i))return[3,1];return q=i,[3,3];case 1:return[4,c(b,e)];case 2:q=a.sent(),a.label=3;case 3:return[4,d(b,p=q,k,l,n)];case 4:a.sent(),r=b.pipeline(),s=0,o.filter(f).forEach(function(a){var b=a.ts,c=a.name;!(b<s)&&(g(r,k,l,n,c,1),s=b)}),a.label=5;case 5:return a.trys.push([5,7,,8]),[4,r.exec()];case 6:return a.sent(),[3,8];case 7:return t=a.sent(),console.error("[IB] Error while pipelining ".concat(o.length," for '").concat(j,"'")),[3,8];case 8:return[2]}})})}function f(a){var c=a.ts,b=a.payload;return"number"==typeof c&&!("string"==typeof b&&b.length>parseInt(k.default.IB_MAX_METRICS_PAYLOAD_LEN+""))}function g(b,c,f,g,d,a){if(void 0===a&&(a=1),null==c)throw Error("Missing site ID in incrementExposure");var e=(0,l.makeKey)([c,f,g,"metrics"]);return a%1==0?b.hincrby(e,d,a):b.hincrbyfloat(e,d,a),b}function h(b,c,d,e){return a.__awaiter(this,void 0,void 0,function(){var f,g,h;return a.__generator(this,function(a){switch(a.label){case 0:return f=(0,l.makeKey)([c,d,e,"metrics"]),[4,b.hgetall(f)];case 1:if(g=a.sent(),!(0,m.exists)(g))return[2,{}];return h={},Object.keys(g).forEach(function(a){return h[a]=(0,l.toNumber)(g[a])}),[2,h]}})})}exports.DEFAULT_REDIS_OPTIONS={lazyConnect:!0,disconnectWaitDuration:50,retryStrategy:function(a){var b=parseInt(k.default.IB_REDIS_RETRY_COUNT+""),c=parseInt(k.default.IB_REDIS_RETRY_INTERVAL+"");return(console.info("[IB] Connecting to Redis attempt # ".concat(a," out of ").concat(b)),a>=b)?null:c}},exports.getRedisBackend=function(f){void 0===f&&(f={});var g=Object.freeze(Object.assign({},exports.DEFAULT_REDIS_OPTIONS,f)),i=new j.default(g),k=!1;return{get client(){return i},get connected(){return k},connect:function(){return a.__awaiter(this,void 0,void 0,function(){return a.__generator(this,function(a){return[2,new Promise(function(a){if(k){a();return}switch(i.status){case"connecting":case"connect":case"ready":a();return;default:console.info("[IB] Connecting to redis..."),i.on("error",function(a){console.error("[IB] Error connecting to Redis: ".concat(a)),k=!1}).on("close",function(){k=!1,console.log("[IB] Redis connection closed")}).on("connect",function(){k=!0,console.log("[IB] Redis connection opened")}).connect().catch(function(a){}),a();return}})]})})},disconnect:function(){return a.__awaiter(this,void 0,void 0,function(){return a.__generator(this,function(a){switch(a.label){case 0:if(a.trys.push([0,,3,6]),console.debug("[IB] Disconnecting from redis..."),"ready"!==i.status)return[3,2];return[4,i.quit()];case 1:a.sent(),a.label=2;case 2:return k=!1,i.disconnect(),[3,6];case 3:if("ready"!==i.status)return[3,5];return[4,new Promise(function(a){return setTimeout(a,g.disconnectWaitDuration)})];case 4:return a.sent(),[3,3];case 5:return[7];case 6:return[2]}})})},getMetricsForSite:function(c,d){return a.__awaiter(this,void 0,void 0,function(){return a.__generator(this,function(a){return k?[2,b(i,c,d)]:[2,new Map]})})},getMetricsBucket:function(b,c,d){return a.__awaiter(this,void 0,void 0,function(){return a.__generator(this,function(a){return k?[2,h(i,b,c,d)]:[2,{}]})})},ingestBatch:function(b,c){return a.__awaiter(this,void 0,void 0,function(){return a.__generator(this,function(a){return k?[2,e(i,b,c)]:[2]})})},getOrCreateSession:function(b){return a.__awaiter(this,void 0,void 0,function(){return a.__generator(this,function(a){if(!k)throw Error("Not connected to Redis session store");return[2,c(i,b)]})})},markVariantSeen:function(b,c,e,f){return a.__awaiter(this,void 0,void 0,function(){return a.__generator(this,function(a){return k?[2,d(i,b,c,e,f)]:((0,m.markVariantInSession)(b,c,e,f),[2,b])})})}}},exports.getMetricsForSite=b,exports.getOrCreateSession=c,exports.markVariantSeen=d,exports.ingestBatch=e,exports.isValidMetricsSample=f,exports.incrementMetricInPipeline=g,exports.getMetricsBucket=h |
@@ -1,1 +0,1 @@ | ||
import{DEFAULT_BASE_URL as a,DEFAULT_COOKIE_SETTINGS as c}from"../constants";var b={IB_MODE:process.env.NODE_ENV,IB_BASE_API_URL:a,IB_COOKIE_SETTINGS:c,IB_ORIGINS_ALLOWLIST:"production"===process.env.NODE_ENV?"":a,IB_REDIS_RETRY_INTERVAL:1e3,IB_REDIS_RETRY_COUNT:10,IB_STATIC_SITES_PATH:"./public/sites",IB_MAX_METRICS_PAYLOAD_LEN:1024},d=Object.assign({},b,{isDev:function(){return"development"===d.IB_MODE},isTest:function(){return"test"===d.IB_MODE},isProduction:function(){return"production"===d.IB_MODE}});Object.keys(b).filter(function(a){return void 0!==process.env[a]}).forEach(function(a){return d[a]=process.env[a]});export default d | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var a=require("../constants"),b={IB_MODE:process.env.NODE_ENV,IB_BASE_API_URL:a.DEFAULT_BASE_URL,IB_COOKIE_SETTINGS:a.DEFAULT_COOKIE_SETTINGS,IB_ORIGINS_ALLOWLIST:"production"===process.env.NODE_ENV?"":a.DEFAULT_BASE_URL,IB_REDIS_RETRY_INTERVAL:1e3,IB_REDIS_RETRY_COUNT:10,IB_STATIC_SITES_PATH:"./public/sites",IB_MAX_METRICS_PAYLOAD_LEN:1024},c=Object.assign({},b,{isDev:function(){return"development"===c.IB_MODE},isTest:function(){return"test"===c.IB_MODE},isProduction:function(){return"production"===c.IB_MODE}});Object.keys(b).filter(function(a){return void 0!==process.env[a]}).forEach(function(a){return c[a]=process.env[a]}),exports.default=c |
@@ -1,1 +0,1 @@ | ||
import{__awaiter as b,__generator as c,__spreadArray as d}from"tslib";import a from"./environment";import{exists as e,getBaseUrl as f}from"../utils";import{getJsonSiteBackend as g}from"./backends/json-sites";import{normalizeOrigins as h}from"./server-utils";import{bandit as i}from"../bandit";import{getRedisBackend as j}from"./backends/redis";export var _a,banditServer,DEFAULT_SERVER_OPTIONS={clientOrigins:null!==(_a=a.IB_ORIGINS_ALLOWLIST)&& void 0!==_a?_a:""};export function buildInstantBanditServer(o){var k,r,s,d=Object.assign({},DEFAULT_SERVER_OPTIONS,o),i=null;d.models||(d.models=g()),d.metrics||(d.metrics=i=j()),d.sessions||(d.sessions=e(i)?i:i=j()),Object.freeze(d);var l=d.metrics,m=d.models,n=d.sessions,p=a.isDev()?[f()]:[],q=h(null!==(k=d.clientOrigins)&& void 0!==k?k:[],p),t=[l,m,n];return{get metrics(){return l},get models(){return m},get sessions(){return n},get origins(){return q},isBackendConnected:function(a){return!e(a.connected)||a.connected},init:function(){return b(this,void 0,void 0,function(){return c(this,function(a){switch(a.label){case 0:if(r)return[2,r];return r=Promise.all(t.filter(e).map(function(b){var a;return null===(a=b.connect)|| void 0===a?void 0:a.call(b)})).catch(function(a){return console.warn("[IB]: Error initializing: ".concat(a))}).then(function(){}),log("Server initializing...."),[4,r];case 1:return a.sent(),log("Server initialized"),[2]}})})},shutdown:function(){return b(this,void 0,void 0,function(){return c(this,function(a){switch(a.label){case 0:if(s)return[2,s];return s=Promise.all(t.filter(e).map(function(b){var a;return null===(a=b.disconnect)|| void 0===a?void 0:a.call(b)})).catch(function(a){return console.warn("[IB]: Error shutting down: ".concat(a))}).then(function(){}),log("Server shutting down...."),[4,s];case 1:return a.sent(),log("Server shut down"),[2]}})})},getSite:function(a){return b(this,void 0,void 0,function(){var b,d,e;return c(this,function(c){switch(c.label){case 0:return[4,(b=m.getSiteConfig)(a)];case 1:return[4,embedProbabilities(a,d=c.sent(),l)];case 2:return[2,{responseHeaders:{},site:e=c.sent()}]}})})}}}export function embedProbabilities(d,e,f){var g,h;return b(this,void 0,void 0,function(){var b,d,j,k,l,m,n,o,p,q,r,s,t,u,v,w;return c(this,function(c){switch(c.label){case 0:return d=(b=JSON.parse(JSON.stringify(e))).experiments,[4,f.getMetricsForSite(b,d)];case 1:for(k=0,j=c.sent(),l=d;k<l.length;k++){for(q=0,n=(m=l[k]).variants,o={},p={},r=n;q<r.length;q++)s=r[q],j.has(s)&&(t=j.get(s),a.isDev()&&(s.metrics=t),o[s.name]=null!==(g=t.exposures)&& void 0!==g?g:0,p[s.name]=null!==(h=t.conversions)&& void 0!==h?h:0);for(w in u=void 0,u=Object.keys(o).length>0&&Object.keys(p).length>0?i(o,p||{}):{},m.metrics={},v=function(b){var a=n.find(function(a){return a.name===b});a&&(a.prob=u[b])},u)v(w)}return[2,b]}})})}export var TAG="[IB][server]";export var log=function(){for(var b=[],a=0;a<arguments.length;a++)b[a]=arguments[a];console.info.apply(console,d([TAG],b,!0))};export function getBanditServer(b){return a.isDev()&&global.defaultBanditServer&&(banditServer=global.defaultBanditServer),banditServer||(console.debug("[IB] Creating default InstantBanditServer..."),banditServer=buildInstantBanditServer(b)),a.isDev()&&(global.defaultBanditServer=banditServer),banditServer} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getBanditServer=exports.log=exports.TAG=exports.embedProbabilities=exports.buildInstantBanditServer=exports.DEFAULT_SERVER_OPTIONS=void 0;var a,f,b=require("tslib"),c=b.__importDefault(require("./environment")),g=require("../utils"),h=require("./backends/json-sites"),i=require("./server-utils"),j=require("../bandit"),k=require("./backends/redis");function d(n){var f,q,r,a=Object.assign({},exports.DEFAULT_SERVER_OPTIONS,n),d=null;a.models||(a.models=(0,h.getJsonSiteBackend)()),a.metrics||(a.metrics=d=(0,k.getRedisBackend)()),a.sessions||(a.sessions=(0,g.exists)(d)?d:d=(0,k.getRedisBackend)()),Object.freeze(a);var j=a.metrics,l=a.models,m=a.sessions,o=c.default.isDev()?[(0,g.getBaseUrl)()]:[],p=(0,i.normalizeOrigins)(null!==(f=a.clientOrigins)&& void 0!==f?f:[],o),s=[j,l,m];return{get metrics(){return j},get models(){return l},get sessions(){return m},get origins(){return p},isBackendConnected:function(a){return!(0,g.exists)(a.connected)||a.connected},init:function(){return b.__awaiter(this,void 0,void 0,function(){return b.__generator(this,function(a){switch(a.label){case 0:if(q)return[2,q];return q=Promise.all(s.filter(g.exists).map(function(b){var a;return null===(a=b.connect)|| void 0===a?void 0:a.call(b)})).catch(function(a){return console.warn("[IB]: Error initializing: ".concat(a))}).then(function(){}),(0,exports.log)("Server initializing...."),[4,q];case 1:return a.sent(),(0,exports.log)("Server initialized"),[2]}})})},shutdown:function(){return b.__awaiter(this,void 0,void 0,function(){return b.__generator(this,function(a){switch(a.label){case 0:if(r)return[2,r];return r=Promise.all(s.filter(g.exists).map(function(b){var a;return null===(a=b.disconnect)|| void 0===a?void 0:a.call(b)})).catch(function(a){return console.warn("[IB]: Error shutting down: ".concat(a))}).then(function(){}),(0,exports.log)("Server shutting down...."),[4,r];case 1:return a.sent(),(0,exports.log)("Server shut down"),[2]}})})},getSite:function(a){return b.__awaiter(this,void 0,void 0,function(){var c,d,f;return b.__generator(this,function(b){switch(b.label){case 0:return[4,(c=l.getSiteConfig)(a)];case 1:return[4,e(a,d=b.sent(),j)];case 2:return[2,{responseHeaders:{},site:f=b.sent()}]}})})}}}function e(a,d,e){var f,g;return b.__awaiter(this,void 0,void 0,function(){var a,h,i,k,l,m,n,o,p,q,r,s,t,u,v,w;return b.__generator(this,function(b){switch(b.label){case 0:return h=(a=JSON.parse(JSON.stringify(d))).experiments,[4,e.getMetricsForSite(a,h)];case 1:for(k=0,i=b.sent(),l=h;k<l.length;k++){for(q=0,n=(m=l[k]).variants,o={},p={},r=n;q<r.length;q++)s=r[q],i.has(s)&&(t=i.get(s),c.default.isDev()&&(s.metrics=t),o[s.name]=null!==(f=t.exposures)&& void 0!==f?f:0,p[s.name]=null!==(g=t.conversions)&& void 0!==g?g:0);for(w in u=void 0,u=Object.keys(o).length>0&&Object.keys(p).length>0?(0,j.bandit)(o,p||{}):{},m.metrics={},v=function(b){var a=n.find(function(a){return a.name===b});a&&(a.prob=u[b])},u)v(w)}return[2,a]}})})}exports.DEFAULT_SERVER_OPTIONS={clientOrigins:null!==(a=c.default.IB_ORIGINS_ALLOWLIST)&& void 0!==a?a:""},exports.buildInstantBanditServer=d,exports.embedProbabilities=e,exports.TAG="[IB][server]",exports.log=function(){for(var c=[],a=0;a<arguments.length;a++)c[a]=arguments[a];console.info.apply(console,b.__spreadArray([exports.TAG],c,!0))},exports.getBanditServer=function(a){return c.default.isDev()&&global.defaultBanditServer&&(f=global.defaultBanditServer),f||(console.debug("[IB] Creating default InstantBanditServer..."),f=d(a)),c.default.isDev()&&(global.defaultBanditServer=f),f} |
@@ -1,1 +0,1 @@ | ||
import b from"./environment";import{buildInstantBanditServer as g}from"./server-core";import{getJsonSiteBackend as d}from"./backends/json-sites";import{getRedisBackend as e}from"./backends/redis";var a,h,c=e(),f=d(),i={clientOrigins:null!==(a=b.IB_ORIGINS_ALLOWLIST)&& void 0!==a?a:b.IB_BASE_API_URL,sessions:c,metrics:c,models:f};export function getInternalDevServer(a){return void 0===a&&(a=i),b.isDev()&&global.internalBanditServer&&(h=global.internalBanditServer),h||(console.debug("[IB] Creating internal InstantBanditServer helper..."),h=g(a)),b.isDev()&&(global.internalBanditServer=h),h} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getInternalDevServer=void 0;var a,g,b=require("tslib").__importDefault(require("./environment")),h=require("./server-core"),d=require("./backends/json-sites"),e=require("./backends/redis"),c=(0,e.getRedisBackend)(),f=(0,d.getJsonSiteBackend)(),i={clientOrigins:null!==(a=b.default.IB_ORIGINS_ALLOWLIST)&& void 0!==a?a:b.default.IB_BASE_API_URL,sessions:c,metrics:c,models:f};exports.getInternalDevServer=function(a){return void 0===a&&(a=i),b.default.isDev()&&global.internalBanditServer&&(g=global.internalBanditServer),g||(console.debug("[IB] Creating internal InstantBanditServer helper..."),g=(0,h.buildInstantBanditServer)(a)),b.default.isDev()&&(global.internalBanditServer=g),g} |
@@ -1,1 +0,1 @@ | ||
import{__awaiter as a,__generator as b}from"tslib";import{HEADER_SESSION_ID as c}from"../constants";import{createBanditContext as d,DEFAULT_BANDIT_OPTIONS as e}from"../contexts";import{exists as f,makeNewSession as g}from"../utils";import{validateUserRequest as h}from"./server-utils";export function serverSideRenderedSite(i,j,k){return a(this,void 0,void 0,function(){var a,l,m,n,o,p,q,r,s,t,u,v,w,x;return b(this,function(b){switch(b.label){case 0:return[4,i.init()];case 1:return b.sent(),[4,h({allowNoSession:!0,allowedOrigins:i.origins,headers:k.headers,siteName:j,url:k.url})];case 2:a=b.sent(),f(k.cookies[c])&&(a.sid=k.cookies[c]),l=a.sid,m=i.sessions,b.label=3;case 3:if(b.trys.push([3,7,,8]),!(f(l)&&i.isBackendConnected(i.sessions)))return[3,5];return[4,m.getOrCreateSession(a)];case 4:return n=b.sent(),[3,6];case 5:n=g(),b.label=6;case 6:return[3,8];case 7:return o=b.sent(),console.log("[IB] Error fetching session for '".concat(l,"': ").concat(o)),n=g(),[3,8];case 8:return q=(p=e.providers).loader,r=p.metrics,s=i.isBackendConnected(i.sessions)?d({providers:{loader:q,metrics:r,session:function(){return{id:n.sid,getOrCreateSession:function(){return n},hasSeen:function(){return!1},persistVariant:function(){},save:function(){return n}}}}}):d(),[4,i.getSite(a)];case 9:return t=b.sent().site,[4,s.init(t)];case 10:return u=b.sent(),v=s.experiment,w=s.variant,[4,i.sessions.markVariantSeen(n,u.name,v.id,w.name).catch(function(a){return console.warn("[IB]: Error marking variant '".concat(w.name,"' seen: ").concat(a))})];case 11:return b.sent(),[2,{site:u,select:(x=!1===i.isBackendConnected(m))?null:w.name,defer:x}]}})})} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.serverSideRenderedSite=void 0;var a=require("tslib"),b=require("../constants"),c=require("../contexts"),d=require("../utils"),e=require("./server-utils");exports.serverSideRenderedSite=function(f,g,h){return a.__awaiter(this,void 0,void 0,function(){var i,j,k,l,m,n,o,p,q,r,s,t,u,v;return a.__generator(this,function(a){switch(a.label){case 0:return[4,f.init()];case 1:return a.sent(),[4,(0,e.validateUserRequest)({allowNoSession:!0,allowedOrigins:f.origins,headers:h.headers,siteName:g,url:h.url})];case 2:i=a.sent(),(0,d.exists)(h.cookies[b.HEADER_SESSION_ID])&&(i.sid=h.cookies[b.HEADER_SESSION_ID]),j=i.sid,k=f.sessions,a.label=3;case 3:if(a.trys.push([3,7,,8]),!((0,d.exists)(j)&&f.isBackendConnected(f.sessions)))return[3,5];return[4,k.getOrCreateSession(i)];case 4:return l=a.sent(),[3,6];case 5:l=(0,d.makeNewSession)(),a.label=6;case 6:return[3,8];case 7:return m=a.sent(),console.log("[IB] Error fetching session for '".concat(j,"': ").concat(m)),l=(0,d.makeNewSession)(),[3,8];case 8:return o=(n=c.DEFAULT_BANDIT_OPTIONS.providers).loader,p=n.metrics,q=f.isBackendConnected(f.sessions)?(0,c.createBanditContext)({providers:{loader:o,metrics:p,session:function(){return{id:l.sid,getOrCreateSession:function(){return l},hasSeen:function(){return!1},persistVariant:function(){},save:function(){return l}}}}}):(0,c.createBanditContext)(),[4,f.getSite(i)];case 9:return r=a.sent().site,[4,q.init(r)];case 10:return s=a.sent(),t=q.experiment,u=q.variant,[4,f.sessions.markVariantSeen(l,s.name,t.id,u.name).catch(function(a){return console.warn("[IB]: Error marking variant '".concat(u.name,"' seen: ").concat(a))})];case 11:return a.sent(),[2,{site:s,select:(v=!1===f.isBackendConnected(k))?null:u.name,defer:v}]}})})} |
@@ -1,1 +0,1 @@ | ||
import{HEADER_SESSION_ID as a}from"../constants" | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("../constants") |
@@ -1,1 +0,1 @@ | ||
import{__awaiter as a,__generator as b}from"tslib";import{randomBytes as c,randomUUID as d}from"crypto";import e from"./environment";import*as f from"../constants";import{exists as g,getCookie as h,makeNewSession as i}from"../utils";import{DEFAULT_SITE as j}from"../defaults";export function emitCookie(c,a){var b=e.IB_COOKIE_SETTINGS;return"".concat(f.HEADER_SESSION_ID,"=").concat(a.sid,"; ").concat(b)}export function normalizeOrigins(a,b){if(void 0===b&&(b=[]),!g(a))return new Map;var d=(Array.isArray(a)?a:[a]).concat(b).join(",").split(",").map(function(a){return a.trim()}).map(function(a){return a.toLowerCase()}).map(function(a){return a}),c=new Map;return d.reduce(function(b,a){return c.set(a,{name:a})},c),c}export function validateUserRequest(c){return a(this,void 0,void 0,function(){var a,d,e,f,h,i,k,l;return b(this,function(b){switch(b.label){case 0:if(a=c.headers,d=c.allowedOrigins,e=c.allowNoSession,f=c.requireOrigin,h=c.siteName,(null!==(i=g(a.origin)?a.origin:null)|| !0===f)&&!(k=validateClientReportedOrigin(d,i)))throw console.warn("[IB] Invalid request for '".concat(c.url,"' from origin '").concat(i,"'")),Error("Invalid origin");return[4,getSessionIdFromHeaders(a)];case 1:if(l=b.sent(),!e&&!g(l))throw Error("Missing session");return[2,{sid:l||"",origin:null!=i?i:"null",headers:a,siteName:h||j.name,session:null}]}})})}export function createNewClientSession(){return a(this,void 0,void 0,function(){var a,c;return b(this,function(b){return[2,c=i(a=d())]})})}export function getSessionIdFromHeaders(c){var d;return a(this,void 0,void 0,function(){var a;return b(this,function(b){return g(a=h(f.HEADER_SESSION_ID,c.cookie))||(a=null!==(d=c[f.HEADER_SESSION_ID])&& void 0!==d?d:null),[2,a]})})}export function validateClientReportedOrigin(b,a){return g(a)||(a="null"),b.has(a)}export function validateMetricsBatch(a,b){if(!g(a.sid))throw Error("Missing or invalid session for metrics");return b}export function randomId(a){return void 0===a&&(a=16),c(a).toString("base64url")}export function makeKey(a){if(a.length<1)throw Error("Expected key fragments");return a.reduce(function(a,b,c){if(!g(b))return a;if((a+=b.length+c)>f.MAX_STORAGE_KEY_LENGTH)throw Error("Maximum storage key size exceeded at length ".concat(a));return a},0),a.map(function(a){return a.replaceAll(":","_")}).join(":")}export function toNumber(a){if("string"==typeof a)return a.indexOf(".")> -1?parseFloat(a):parseInt(a);if("number"==typeof a)return a;if(null==a)return 0;throw Error("Invalid value '".concat(a,"' interpreted as number"))} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.toNumber=exports.makeKey=exports.randomId=exports.validateMetricsBatch=exports.validateClientReportedOrigin=exports.getSessionIdFromHeaders=exports.createNewClientSession=exports.validateUserRequest=exports.normalizeOrigins=exports.emitCookie=void 0;var a=require("tslib"),d=require("crypto"),e=a.__importDefault(require("./environment")),f=a.__importStar(require("../constants")),g=require("../utils"),h=require("../defaults");function b(b){var c;return a.__awaiter(this,void 0,void 0,function(){var d;return a.__generator(this,function(a){return d=(0,g.getCookie)(f.HEADER_SESSION_ID,b.cookie),(0,g.exists)(d)||(d=null!==(c=b[f.HEADER_SESSION_ID])&& void 0!==c?c:null),[2,d]})})}function c(b,a){return(0,g.exists)(a)||(a="null"),b.has(a)}exports.emitCookie=function(c,a){var b=e.default.IB_COOKIE_SETTINGS;return"".concat(f.HEADER_SESSION_ID,"=").concat(a.sid,"; ").concat(b)},exports.normalizeOrigins=function(a,b){if(void 0===b&&(b=[]),!(0,g.exists)(a))return new Map;var d=(Array.isArray(a)?a:[a]).concat(b).join(",").split(",").map(function(a){return a.trim()}).map(function(a){return a.toLowerCase()}).map(function(a){return a}),c=new Map;return d.reduce(function(b,a){return c.set(a,{name:a})},c),c},exports.validateUserRequest=function(d){return a.__awaiter(this,void 0,void 0,function(){var e,f,i,j,k,l,m,n;return a.__generator(this,function(a){switch(a.label){case 0:if(e=d.headers,f=d.allowedOrigins,i=d.allowNoSession,j=d.requireOrigin,k=d.siteName,(null!==(l=(0,g.exists)(e.origin)?e.origin:null)|| !0===j)&&!(m=c(f,l)))throw console.warn("[IB] Invalid request for '".concat(d.url,"' from origin '").concat(l,"'")),Error("Invalid origin");return[4,b(e)];case 1:if(n=a.sent(),!i&&!(0,g.exists)(n))throw Error("Missing session");return[2,{sid:n||"",origin:null!=l?l:"null",headers:e,siteName:k||h.DEFAULT_SITE.name,session:null}]}})})},exports.createNewClientSession=function(){return a.__awaiter(this,void 0,void 0,function(){var b,c;return a.__generator(this,function(a){return b=(0,d.randomUUID)(),[2,c=(0,g.makeNewSession)(b)]})})},exports.getSessionIdFromHeaders=b,exports.validateClientReportedOrigin=c,exports.validateMetricsBatch=function(a,b){var c=a.sid;if(!(0,g.exists)(c))throw Error("Missing or invalid session for metrics");return b},exports.randomId=function(a){return void 0===a&&(a=16),(0,d.randomBytes)(a).toString("base64url")},exports.makeKey=function(a){if(a.length<1)throw Error("Expected key fragments");return a.reduce(function(a,b,c){if(!(0,g.exists)(b))return a;if((a+=b.length+c)>f.MAX_STORAGE_KEY_LENGTH)throw Error("Maximum storage key size exceeded at length ".concat(a));return a},0),a.map(function(a){return a.replaceAll(":","_")}).join(":")},exports.toNumber=function(a){if("string"==typeof a)return a.indexOf(".")> -1?parseFloat(a):parseInt(a);if("number"==typeof a)return a;if(null==a)return 0;throw Error("Invalid value '".concat(a,"' interpreted as number"))} |
@@ -1,1 +0,1 @@ | ||
export var LoadState;!function(a){a.PRELOAD="pre",a.WAIT="wait-for-data",a.SELECTING="selecting",a.READY="ready"}(LoadState||(LoadState={}));export var Algorithm;!function(a){a.DEFAULT="default",a.RANDOM="random",a.MAB_EPSILON_GREEDY="mab-epsilon-greedy"}(Algorithm||(Algorithm={})) | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Algorithm=exports.LoadState=void 0,function(a){a.PRELOAD="pre",a.WAIT="wait-for-data",a.SELECTING="selecting",a.READY="ready"}(exports.LoadState||(exports.LoadState={})),function(a){a.DEFAULT="default",a.RANDOM="random",a.MAB_EPSILON_GREEDY="mab-epsilon-greedy"}(exports.Algorithm||(exports.Algorithm={})) |
@@ -1,1 +0,1 @@ | ||
import{__awaiter as c,__generator as d}from"tslib";import{useEffect as a,useLayoutEffect as b}from"react";import*as e from"./constants";export function makeNewSession(a){return void 0===a&&(a=""),{sid:a,selections:{}}}export function markVariantInSession(e,f,d,g){var h,b=e.selections;b||(b=e.selections={});var c=b[f];c||(c=b[f]=((h={})[d]=[],h));var a=c[d];exists(a)||(a=c[d]=[]);var i=a.indexOf(g);i> -1&&a.splice(i,1),a.push(g)}export function deepFreeze(a,b){return(void 0===b&&(b=new WeakMap),exists(a))?(b.set(a,!0),Object.getOwnPropertyNames(a).filter(function(c){return!b.has(a[c])}).filter(function(b){return a[b]&&"object"==typeof a[b]}).forEach(function(c){return deepFreeze(a[c],b)}),Object.freeze(a)):a}export function exists(a){return null!=a}export function env(a){return"undefined"==typeof process?void 0:isBrowserEnvironment?process.env[e.NEXTJS_PUBLIC_PREFIX+a]:process.env[a]}export function getCookie(d,a){void 0===a&&(a="");var c="";if("undefined"==typeof document&&""===a)return null;var b=(c=""!==a?a:document.cookie).split(";").map(function(a){return a.trim()}).filter(function(a){return 0===a.indexOf(d)}).map(function(a){return a.substring(d.length+1,a.length)}).pop();return null!=b?b:null}export function getBaseUrl(){var a;return null!==(a=env(e.VARNAME_BASE_URL))&& void 0!==a?a:e.DEFAULT_BASE_URL}export var isBrowserEnvironment="undefined"!=typeof window;export var useIsomorphicLayoutEffect=isBrowserEnvironment?b:a;export var flushPromises=function(){return c(void 0,void 0,void 0,function(){return d(this,function(a){return[2,new Promise(function(a){f(a)})]})})};var f="function"==typeof setImmediate?setImmediate:setTimeout | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.flushPromises=exports.useIsomorphicLayoutEffect=exports.isBrowserEnvironment=exports.getBaseUrl=exports.getCookie=exports.env=exports.exists=exports.deepFreeze=exports.markVariantInSession=exports.makeNewSession=void 0;var b=require("tslib"),a=require("react"),f=b.__importStar(require("./constants"));function c(a,b){return(void 0===b&&(b=new WeakMap),function(a){return null!=a}(a))?(b.set(a,!0),Object.getOwnPropertyNames(a).filter(function(c){return!b.has(a[c])}).filter(function(b){return a[b]&&"object"==typeof a[b]}).forEach(function(d){return c(a[d],b)}),Object.freeze(a)):a}function d(a){return null!=a}function e(a){return"undefined"==typeof process?void 0:exports.isBrowserEnvironment?process.env[f.NEXTJS_PUBLIC_PREFIX+a]:process.env[a]}exports.makeNewSession=function(a){return void 0===a&&(a=""),{sid:a,selections:{}}},exports.markVariantInSession=function(e,f,d,g){var h,b=e.selections;b||(b=e.selections={});var c=b[f];c||(c=b[f]=((h={})[d]=[],h));var i,a=c[d];i=a,null!=i||(a=c[d]=[]);var j=a.indexOf(g);j> -1&&a.splice(j,1),a.push(g)},exports.deepFreeze=c,exports.exists=d,exports.env=e,exports.getCookie=function(d,a){void 0===a&&(a="");var c="";if("undefined"==typeof document&&""===a)return null;var b=(c=""!==a?a:document.cookie).split(";").map(function(a){return a.trim()}).filter(function(a){return 0===a.indexOf(d)}).map(function(a){return a.substring(d.length+1,a.length)}).pop();return null!=b?b:null},exports.getBaseUrl=function(){var a;return null!==(a=e(f.VARNAME_BASE_URL))&& void 0!==a?a:f.DEFAULT_BASE_URL},exports.isBrowserEnvironment="undefined"!=typeof window,exports.useIsomorphicLayoutEffect=exports.isBrowserEnvironment?a.useLayoutEffect:a.useEffect,exports.flushPromises=function(){return b.__awaiter(void 0,void 0,void 0,function(){return b.__generator(this,function(a){return[2,new Promise(function(a){g(a)})]})})};var g="function"==typeof setImmediate?setImmediate:setTimeout |
@@ -1,1 +0,1 @@ | ||
import a from"./lib/server/environment";export*from"./lib/server/environment";export*from"./lib/server/server-core";export*from"./lib/server/server-rendering";export*from"./lib/server/server-types";export*from"./lib/server/server-utils";export*from"./lib/server/backends/json-sites";export*from"./lib/server/backends/redis";export{createSiteEndpoint}from"./pages/api/sites/[siteName]";export{createMetricsEndpoint}from"./pages/api/metrics";export{a as env} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createMetricsEndpoint=exports.createSiteEndpoint=exports.env=void 0;var a=require("tslib"),b=a.__importDefault(require("./lib/server/environment"));exports.env=b.default,a.__exportStar(require("./lib/server/environment"),exports),a.__exportStar(require("./lib/server/server-core"),exports),a.__exportStar(require("./lib/server/server-rendering"),exports),a.__exportStar(require("./lib/server/server-types"),exports),a.__exportStar(require("./lib/server/server-utils"),exports),a.__exportStar(require("./lib/server/backends/json-sites"),exports),a.__exportStar(require("./lib/server/backends/redis"),exports);var c=require("./pages/api/sites/[siteName]");Object.defineProperty(exports,"createSiteEndpoint",{enumerable:!0,get:function(){return c.createSiteEndpoint}});var d=require("./pages/api/metrics");Object.defineProperty(exports,"createMetricsEndpoint",{enumerable:!0,get:function(){return d.createMetricsEndpoint}}) |
{ | ||
"name": "@instantdomain/bandit", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances 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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
80333
58
675
25