New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

autotune

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autotune - npm Package Compare versions

Comparing version 2.0.45 to 2.0.46

1

dist/BrowserEnvironment.d.ts

@@ -11,2 +11,3 @@ import { Environment } from "./Environment";

startHTMLExperiments(): void;
autocomplete(complete: (payoff: number) => void): void;
}

@@ -83,2 +83,11 @@ "use strict";

};
BrowserEnvironment.prototype.autocomplete = function (complete) {
var _loop_1 = function (delay, reward) {
setTimeout(function () { return complete(reward); }, delay * 1000);
};
for (var _i = 0, _a = [[10, 0.1], [60, 0.2]]; _i < _a.length; _i++) {
var _b = _a[_i], delay = _b[0], reward = _b[1];
_loop_1(delay, reward);
}
};
return BrowserEnvironment;

@@ -85,0 +94,0 @@ }());

@@ -23,2 +23,3 @@ import { Outcome } from "./common/ClientConfig";

private queuedStartedExperiments;
private preinitialized;
constructor(environment: Environment, appKey: string, then: (c: Client) => void, outcomes?: Outcomes);

@@ -25,0 +26,0 @@ log(...args: any[]): void;

@@ -34,2 +34,3 @@ "use strict";

this.queuedStartedExperiments = {};
this.preinitialized = false;
this.serializeStateDebounced = debounce_1.debounce(function () {

@@ -90,2 +91,3 @@ _this.log("Writing state", _this.serialized);

this.log("Initialize", appKey);
this.preinitialized = outcomes !== undefined;
this.serialized = {

@@ -172,3 +174,6 @@ lastInitialized: 0,

});
this.environment.startHTMLExperiments();
if (this.preinitialized) {
this.environment.startHTMLExperiments();
this.environment.autocomplete(function (payoff) { return _this.completeDefaults(payoff, undefined); });
}
}

@@ -175,0 +180,0 @@ catch (e) {

33

dist/Client.test.js

@@ -25,2 +25,3 @@ "use strict";

this.htmlExperimentsStarted = false;
this.autocompleteCalled = false;
this.startExperimentsData = undefined;

@@ -44,3 +45,3 @@ this.completeExperimentsData = undefined;

};
TestEnvironment.test = function (name, outcomes, clientContext, fn) {
TestEnvironment.test = function (name, settings, fn) {
for (var _i = 0, _a = [false, true]; _i < _a.length; _i++) {

@@ -59,3 +60,3 @@ var allowStartExperiments = _a[_i];

withs.push("completeExperiments");
var env = new TestEnvironment(outcomes, clientContext, allowStartExperiments, allowSetLocalStorage, allowCompleteExperiments);
var env = new TestEnvironment(settings.outcomes, settings.clientContext, allowStartExperiments, allowSetLocalStorage, allowCompleteExperiments);
var suffix = withs.length === 0 ? "" : " with " + withs.join(",");

@@ -177,2 +178,5 @@ var fullName = name + suffix;

};
TestEnvironment.prototype.autocomplete = function (complete) {
this.autocompleteCalled = true;
};
TestEnvironment.prototype.checkStartExperiments = function (options, pick, pickedBest) {

@@ -224,3 +228,2 @@ var data = this.startExperimentsData;

expect(env.numOutcomesRequested).toBe(1);
expect(env.htmlExperimentsStarted).toBe(true);
}

@@ -254,3 +257,3 @@ function checkState(localStorage, pick) {

}
TestEnvironment.test("can init when network fails", undefined, defaultClientContext, function (env) {
TestEnvironment.test("can init when network fails", { clientContext: defaultClientContext }, function (env) {
checkInit(env);

@@ -261,3 +264,3 @@ jest.advanceTimersByTime(200);

});
TestEnvironment.test("can init with network", {}, defaultClientContext, function (env) {
TestEnvironment.test("can init with network", { outcomes: {}, clientContext: defaultClientContext }, function (env) {
checkInit(env);

@@ -271,4 +274,10 @@ jest.advanceTimersByTime(200);

});
TestEnvironment.test("can run experiment when network fails", undefined, defaultClientContext, function (env) {
TestEnvironment.test("doesn't start HTML experiments or autocompletion when outcomes not preloaded", { clientContext: defaultClientContext }, function (env) {
checkInit(env);
jest.advanceTimersByTime(200);
expect(env.htmlExperimentsStarted).toBe(false);
expect(env.autocompleteCalled).toBe(false);
});
TestEnvironment.test("can run experiment when network fails", { clientContext: defaultClientContext }, function (env) {
checkInit(env);
var options = makeOptions(2);

@@ -283,3 +292,11 @@ var ex = env.getClient().experiment(experimentName, options);

});
TestEnvironment.test("single node", makeOutcomes(2, leaf(1)), defaultClientContext, function (env) {
test("html experiments and autocompletions begin when outcomes preloaded", function () {
var preloadedOutcomes = {};
var env = new TestEnvironment({}, defaultClientContext, true, true, true);
var client = new Client_1.Client(env, appKey, function () { return null; }, preloadedOutcomes);
env.setClient(client);
expect(env.htmlExperimentsStarted).toBe(true);
expect(env.autocompleteCalled).toBe(true);
});
TestEnvironment.test("single node", { outcomes: makeOutcomes(2, leaf(1)), clientContext: defaultClientContext }, function (env) {
checkInit(env);

@@ -297,3 +314,3 @@ var ex = env.getClient().experiment(experimentName, env.getOptions());

var _loop_1 = function (complete) {
TestEnvironment.test(name + (complete ? " with completion" : ""), outcomes, clientContext, function (env) {
TestEnvironment.test(name + (complete ? " with completion" : ""), { outcomes: outcomes, clientContext: clientContext }, function (env) {
checkInit(env);

@@ -300,0 +317,0 @@ var ex = env.getClient().experiment(experimentName, env.getOptions());

@@ -10,2 +10,3 @@ export interface Environment {

startHTMLExperiments(): void;
autocomplete(complete: (payoff: number) => void): void;
}

@@ -84,2 +84,11 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.autotune = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

};
BrowserEnvironment.prototype.autocomplete = function (complete) {
var _loop_1 = function (delay, reward) {
setTimeout(function () { return complete(reward); }, delay * 1000);
};
for (var _i = 0, _a = [[10, 0.1], [60, 0.2]]; _i < _a.length; _i++) {
var _b = _a[_i], delay = _b[0], reward = _b[1];
_loop_1(delay, reward);
}
};
return BrowserEnvironment;

@@ -123,2 +132,3 @@ }());

this.queuedStartedExperiments = {};
this.preinitialized = false;
this.serializeStateDebounced = debounce_1.debounce(function () {

@@ -179,2 +189,3 @@ _this.log("Writing state", _this.serialized);

this.log("Initialize", appKey);
this.preinitialized = outcomes !== undefined;
this.serialized = {

@@ -261,3 +272,6 @@ lastInitialized: 0,

});
this.environment.startHTMLExperiments();
if (this.preinitialized) {
this.environment.startHTMLExperiments();
this.environment.autocomplete(function (payoff) { return _this.completeDefaults(payoff, undefined); });
}
}

@@ -264,0 +278,0 @@ catch (e) {

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

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).autotune=e()}}(function(){return function r(a,s,u){function c(t,e){if(!s[t]){if(!a[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(p)return p(t,!0);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}var i=s[t]={exports:{}};a[t][0].call(i.exports,function(e){return c(a[t][1][e]||e)},i,i.exports,r,a,s,u)}return s[t].exports}for(var p="function"==typeof require&&require,e=0;e<u.length;e++)c(u[e]);return c}({1:[function(e,t,n){"use strict";n.__esModule=!0;var o=e("./html"),i=!!("undefined"!=typeof window)&&("localhost"===window.location.hostname||-1!==window.location.search.indexOf("autotune-debug")),r=function(){function e(){}return e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i&&console.log.apply(console,["AUTOTUNE"].concat(e))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.error.apply(console,["AUTOTUNE"].concat(e))},e.prototype.getTimeZoneOffset=function(){return(new Date).getTimezoneOffset()},e.prototype.getLocalLanguage=function(){try{var e=navigator;return e.language||e.userLanguage}catch(e){return}},e.prototype.http=function(e,t,n,o,i){if("undefined"==typeof XMLHttpRequest)return i(new Error("Not running in browser"));try{var r=new XMLHttpRequest;r.open(e,t,!0),r.setRequestHeader("Content-Type","application/json"),r.onerror=function(){return i(new Error(r.statusText))},r.onreadystatechange=function(){4===r.readyState&&(200===r.status?o(JSON.parse(r.responseText)):i(new Error("Request failed with status "+r.status)))},void 0!==n?r.send(JSON.stringify(n)):r.send()}catch(e){return i(e)}},e.prototype.getLocalStorage=function(e){var t=localStorage[e];if("string"==typeof t)return t},e.prototype.setLocalStorage=function(e,t){localStorage[e]=t},e.prototype.startHTMLExperiments=function(){o.startHTMLExperiments()},e}();n.BrowserEnvironment=r},{"./html":7}],2:[function(e,t,n){"use strict";n.__esModule=!0;var a=e("./common/ClientAPI"),u=e("./common/models"),p=e("./util"),c=e("./debounce"),s=e("./DecisionTree");function f(e){return"https://2vyiuehl9j.execute-api.us-east-2.amazonaws.com/prod/"+e}n.apiURL=f;var l=function(e,t,n){void 0===t&&(t=void 0),void 0===n&&(n=1),this.optionNames=e,this.bestOption=t,this.epsilon=n};n.ExperimentOptions=l;var o=function(){function e(e,t,n,o){var s=this;this.environment=e,this.appKey=t,this.experimentOptions={},this.experiments={},this.defaultCompletions={},this.queuedCompletedExperiments={},this.queuedStartedExperiments={},this.serializeStateDebounced=c.debounce(function(){s.log("Writing state",s.serialized);try{var e=u.Convert.serializedStateToJson(s.serialized);s.environment.setLocalStorage(s.storageKey("state"),e)}catch(e){s.error("Could not save state:",e.message)}},100),this.startExperimentsDebounced=c.debounce(function(){var e=p.mapObject(s.queuedStartedExperiments,function(e){return{instanceKey:e.key,options:e.options.optionNames,pick:e.pick,pickedBest:e.pickedBest}});s.log("Starting experiments",e),s.queuedStartedExperiments={};var t={version:2,appKey:s.appKey,experiments:e,ctx:s.getClientContext()};s.environment.http("POST",f("startExperiments"),t,function(){},function(e){return s.error("Failed to start experiments",e)})},100),this.completeExperimentsDebounced=c.debounce(function(e){var t=p.getOwnPropertyValues(s.queuedCompletedExperiments);s.queuedCompletedExperiments={};for(var n={},o=0,i=t;o<i.length;o++){var r=i[o];void 0!==r.payoff&&(n[r.key]={pick:r.pick,payoff:r.payoff})}function a(){void 0!==e&&e()}s.log("Completing experiments",n),s.environment.http("POST",f("completeExperiments"),{version:1,appKey:s.appKey,experiments:n},function(){return a()},function(e){s.error("Failed to complete experiments",e),a()})},10),this.log("Initialize",t),this.serialized={lastInitialized:0,experimentPicks:{}};try{var i=e.getLocalStorage(this.storageKey("state"));void 0!==i&&(this.serialized=u.Convert.toSerializedState(i))}catch(e){}var r=(new Date).getTime();864e5<r-this.serialized.lastInitialized&&(this.log("Starting a new session"),this.serialized.experimentPicks={}),this.serialized.lastInitialized=r,this.serializeStateDebounced(),void 0===o?e.http("GET",a.outcomesUrl(t),void 0,function(e){s.log("Got outcomes",e),s.finishInit(e),n(s)},function(e){s.error("Could not get outcomes",e),s.finishInit({}),n(s)}):this.finishInit(o)}return e.prototype.log=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];(e=this.environment).log.apply(e,t)},e.prototype.error=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];(e=this.environment).error.apply(e,t)},e.prototype.getClientContext=function(){if(void 0===this.clientContext){this.clientContext={tzo:this.environment.getTimeZoneOffset()};var e=this.environment.getLocalLanguage();void 0!==e&&(this.clientContext.lang=e)}return this.clientContext},e.prototype.startExperiment=function(e){this.queuedStartedExperiments[e.name]=e,this.startExperimentsDebounced()},e.prototype.completeExperiment=function(e,t){this.queuedCompletedExperiments[e.name]=e,this.completeExperimentsDebounced(t)},e.prototype.completeDefaults=function(t,n){var o=this.defaultCompletions;Object.getOwnPropertyNames(o).forEach(function(e){return o[e].complete(t,n)})},e.prototype.finishInit=function(i){var r=this;try{var a=this.getClientContext();Object.getOwnPropertyNames(i).forEach(function(e){if(void 0===r.experimentOptions[e]){var t=s.lookupBestOption(a,i[e]),n=t.option,o=t.epsilon;r.experimentOptions[e]=new l(i[e].options,n,o)}}),this.environment.startHTMLExperiments()}catch(e){this.error("Couldn't finish init",e)}},e.prototype.experiment=function(e,t){var n=this.experiments[e];if(void 0!==n)return n;var o=this.experimentOptions[e];return void 0===o&&(o=this.experimentOptions[e]=new l(t)),n=this.experiments[e]=new i(this,e,o),this.defaultCompletions[e]=n,this.startExperiment(n),n},e.prototype.storageKey=function(e){return"autotune.v1."+this.appKey+"."+e},e.prototype.loadPick=function(e){return this.serialized.experimentPicks[e]},e.prototype.savePick=function(e,t){this.serialized.experimentPicks[e]=t,this.serializeStateDebounced()},e}();n.Client=o;var i=function(){function e(e,t,n){this.client=e,this.name=t,this.options=n,this.key=p.uuidv4();var o=this.options,i=o.optionNames,r=o.bestOption,a=o.epsilon,s=this.client.loadPick(this.name);if(void 0!==s&&-1!==i.indexOf(s))this.pick=s,this.pickedBest=s===r;else{var u=void 0===r||-1===i.indexOf(r)||Math.random()<a,c=void 0;c=u||void 0===r?i[Math.floor(Math.random()*i.length)]:r,this.client.savePick(this.name,c),this.pick=c,this.pickedBest=!u}}return e.prototype.complete=function(e,t){void 0===e&&(e=1),this.payoff=e,this.client.completeExperiment(this,t)},e}();n.Experiment=i},{"./DecisionTree":3,"./common/ClientAPI":4,"./common/models":5,"./debounce":6,"./util":9}],3:[function(e,t,n){"use strict";n.__esModule=!0,n.lookupBestOption=function(r,e){if(void 0===e)return{};var a=e.options;return function e(t){if(void 0!==t.best)return{option:a[t.best],epsilon:t.eps};if(void 0===t.at||void 0===t.op||void 0===t.v)return{};var n,o=r[t.at];switch("string"==typeof t.v?"string"!=typeof o&&(o="null"):"number"!=typeof o&&(o=0),t.op){case"lt":n=o<t.v;break;case"eq":n=o===t.v;break;default:return{}}var i=n?t.l:t.r;return void 0===i?{}:e(i)}(e.tree)}},{}],4:[function(e,t,n){"use strict";function o(e){return"https://s3.us-east-2.amazonaws.com/js.autotune.xyz/"+e}n.__esModule=!0,n.s3Url=o,n.outcomesUrl=function(e){return o(e+".json")},n.clientUrl=function(e){return o(e+".js")}},{}],5:[function(e,t,n){"use strict";n.__esModule=!0,function(e){function s(e,t){if("any"===e)return!0;if(null===e)return null===t;if(!1===e)return!1;for(;"object"==typeof e&&void 0!==e.ref;)e=u[e.ref];return Array.isArray(e)?(n=t,-1!==e.indexOf(n)):"object"==typeof e?e.hasOwnProperty("unionMembers")?(r=e.unionMembers,a=t,r.some(function(e){return s(e,a)})):e.hasOwnProperty("arrayItems")?(o=e.arrayItems,i=t,Array.isArray(i)&&i.every(function(e){return s(o,e)})):!!e.hasOwnProperty("props")&&function(n,o,i){if(null===i||"object"!=typeof i||Array.isArray(i))return!1;return Object.getOwnPropertyNames(i).every(function(e){var t=i[e];return Object.prototype.hasOwnProperty.call(n,e)?s(n[e],t):s(o,t)})}(e.props,e.additional,t):typeof e==typeof t;var n,o,i,r,a}e.toSerializedState=function(e){return function(e,t){if(!s(t,e))throw Error("Invalid value");return e}(JSON.parse(e),{ref:"SerializedState"})},e.serializedStateToJson=function(e){return JSON.stringify(e,null,2)};var t,n,o,u={SerializedState:(t={experimentPicks:(o="",{props:{},additional:o}),lastInitialized:0},n="any",{props:t,additional:n})}}(n.Convert||(n.Convert={}))},{}],6:[function(e,t,n){"use strict";n.__esModule=!0,n.debounce=function(i,r,a){var s;return void 0===r&&(r=50),void 0===a&&(a={isImmediate:!1}),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=this,o=a.isImmediate&&void 0===s;void 0!==s&&clearTimeout(s),s=setTimeout(function(){s=void 0,a.isImmediate||i.apply(n,e)},r),o&&i.apply(n,e)}}},{}],7:[function(e,t,n){"use strict";n.__esModule=!0;var c=e("."),p=e("./util");function f(e){return e.getAttribute("option")||p.hash(e.outerHTML).toString()}n.startHTMLExperiments=function(){function e(){var e;!function(){var i,e,r,t,a=(r={},t=document.querySelectorAll("[data-experiment]"),p.each(t,function(e){var t=e.getAttribute("data-experiment"),n=e.getAttribute("data-option");if(null!==t&&null!==n){var o=r[t];void 0===o&&(o=r[t]={options:[],nodes:[]}),-1===o.options.indexOf(n)&&o.options.push(n),o.nodes.push(e)}}),r),o=(i={},e=document.getElementsByTagName("autotune"),p.each(e,function(e){var t=e.getAttribute("experiment")||p.hash(e.innerHTML).toString(),n={node:e,options:p.map(e.children,f)},o=i[t]||[];o.push(n),i[t]=o}),i);Object.getOwnPropertyNames(a).forEach(function(e){var t=a[e],n=t.options,o=t.nodes,i=c.oneOf(e,n);o.forEach(function(e){e.getAttribute("data-option")!==i&&e.remove()})}),Object.getOwnPropertyNames(o).forEach(function(e){var t={};o[e].forEach(function(e){e.options.forEach(function(e){return t[e]=null})});var n=c.oneOf(e,Object.getOwnPropertyNames(t));o[e].forEach(function(e){p.map(e.node.children,function(e){return e}).forEach(function(e){f(e)!==n&&e.remove()})})});var s,n,u=(s={},n=document.querySelectorAll("[autotune-class],[data-autotune-class]"),p.each(n,function(e){var t=(e.getAttribute("autotune-class")||e.getAttribute("data-autotune-class")||"").split(" "),n=e.getAttribute("autotune-experiment")||e.getAttribute("data-autotune-experiment")||p.hash(e.innerHTML)+"-class";s[n]={options:t,node:e}}),s);Object.getOwnPropertyNames(u).forEach(function(e){var t=u[e],n=c.oneOf(e,t.options);t.node.classList.add(n)})}(),e=document.querySelectorAll("a[autotune],a[data-autotune],button[autotune],button[data-autotune]"),p.each(e,function(t){var n=t.onclick;t.onclick=function(e){e.preventDefault(),c.complete(function(){"function"==typeof n?n.bind(t)(e):t instanceof HTMLAnchorElement&&(window.location.href=t.href)})}})}"complete"===document.readyState?e():document.addEventListener("DOMContentLoaded",function(){e()})}},{".":8,"./util":9}],8:[function(e,t,n){"use strict";n.__esModule=!0;var r,o=e("./Client"),a=new(e("./BrowserEnvironment").BrowserEnvironment);function i(e,t,n){void 0===r?r=new o.Client(a,e,t,n):a.error("autotune initialized more than once")}if(n.initialize=i,n.flipCoin=function(e){return void 0===r?(a.error("autotune must be initialized before calling flipCoin"),!0):"true"===r.experiment(e,["true","false"]).pick},n.oneOf=function(e,t){var n,o,i="[object Array]"===Object.prototype.toString.call(t);return n=i?t:Object.getOwnPropertyNames(t),void 0===r?(a.error("autotune must be initialized before calling oneOf"),o=n[0]):o=r.experiment(e,n).pick,i?o:t[o]},n.complete=function(e,t){var n,o;void 0!==r?(n="number"==typeof e?e:1,o="function"==typeof e?e:t,r.completeDefaults(n,o)):a.error("autotune must be initialized before calling complete")},"undefined"!=typeof window&&void 0!==window.autotuneConfig){var s=window.autotuneConfig;i(s.appKey,function(){},s.outcomes)}},{"./BrowserEnvironment":1,"./Client":2}],9:[function(e,t,n){"use strict";function o(e,t){for(var n=[],o=0;o<e.length;o++)n.push(t(e.item(o),o));return n}n.__esModule=!0,n.uuidv4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},n.getOwnPropertyValues=function(t){return Object.getOwnPropertyNames(t).map(function(e){return t[e]})},n.mapObject=function(t,n){var o={};return Object.getOwnPropertyNames(t).forEach(function(e){return o[e]=n(t[e],e)}),o},n.map=o,n.each=function(e,n){o(e,function(e,t){n(e,t)})},n.hash=function(e){for(var t=0,n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t&=t;return Math.abs(t)}},{}]},{},[8])(8)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).autotune=t()}}(function(){return function r(a,u,s){function c(e,t){if(!u[e]){if(!a[e]){var n="function"==typeof require&&require;if(!t&&n)return n(e,!0);if(p)return p(e,!0);var o=new Error("Cannot find module '"+e+"'");throw o.code="MODULE_NOT_FOUND",o}var i=u[e]={exports:{}};a[e][0].call(i.exports,function(t){return c(a[e][1][t]||t)},i,i.exports,r,a,u,s)}return u[e].exports}for(var p="function"==typeof require&&require,t=0;t<s.length;t++)c(s[t]);return c}({1:[function(t,e,n){"use strict";n.__esModule=!0;var o=t("./html"),i=!!("undefined"!=typeof window)&&("localhost"===window.location.hostname||-1!==window.location.search.indexOf("autotune-debug")),r=function(){function t(){}return t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];i&&console.log.apply(console,["AUTOTUNE"].concat(t))},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.error.apply(console,["AUTOTUNE"].concat(t))},t.prototype.getTimeZoneOffset=function(){return(new Date).getTimezoneOffset()},t.prototype.getLocalLanguage=function(){try{var t=navigator;return t.language||t.userLanguage}catch(t){return}},t.prototype.http=function(t,e,n,o,i){if("undefined"==typeof XMLHttpRequest)return i(new Error("Not running in browser"));try{var r=new XMLHttpRequest;r.open(t,e,!0),r.setRequestHeader("Content-Type","application/json"),r.onerror=function(){return i(new Error(r.statusText))},r.onreadystatechange=function(){4===r.readyState&&(200===r.status?o(JSON.parse(r.responseText)):i(new Error("Request failed with status "+r.status)))},void 0!==n?r.send(JSON.stringify(n)):r.send()}catch(t){return i(t)}},t.prototype.getLocalStorage=function(t){var e=localStorage[t];if("string"==typeof e)return e},t.prototype.setLocalStorage=function(t,e){localStorage[t]=e},t.prototype.startHTMLExperiments=function(){o.startHTMLExperiments()},t.prototype.autocomplete=function(n){for(var t=function(t,e){setTimeout(function(){return n(e)},1e3*t)},e=0,o=[[10,.1],[60,.2]];e<o.length;e++){var i=o[e];t(i[0],i[1])}},t}();n.BrowserEnvironment=r},{"./html":7}],2:[function(t,e,n){"use strict";n.__esModule=!0;var a=t("./common/ClientAPI"),s=t("./common/models"),p=t("./util"),c=t("./debounce"),u=t("./DecisionTree");function f(t){return"https://2vyiuehl9j.execute-api.us-east-2.amazonaws.com/prod/"+t}n.apiURL=f;var l=function(t,e,n){void 0===e&&(e=void 0),void 0===n&&(n=1),this.optionNames=t,this.bestOption=e,this.epsilon=n};n.ExperimentOptions=l;var o=function(){function t(t,e,n,o){var u=this;this.environment=t,this.appKey=e,this.experimentOptions={},this.experiments={},this.defaultCompletions={},this.queuedCompletedExperiments={},this.queuedStartedExperiments={},this.preinitialized=!1,this.serializeStateDebounced=c.debounce(function(){u.log("Writing state",u.serialized);try{var t=s.Convert.serializedStateToJson(u.serialized);u.environment.setLocalStorage(u.storageKey("state"),t)}catch(t){u.error("Could not save state:",t.message)}},100),this.startExperimentsDebounced=c.debounce(function(){var t=p.mapObject(u.queuedStartedExperiments,function(t){return{instanceKey:t.key,options:t.options.optionNames,pick:t.pick,pickedBest:t.pickedBest}});u.log("Starting experiments",t),u.queuedStartedExperiments={};var e={version:2,appKey:u.appKey,experiments:t,ctx:u.getClientContext()};u.environment.http("POST",f("startExperiments"),e,function(){},function(t){return u.error("Failed to start experiments",t)})},100),this.completeExperimentsDebounced=c.debounce(function(t){var e=p.getOwnPropertyValues(u.queuedCompletedExperiments);u.queuedCompletedExperiments={};for(var n={},o=0,i=e;o<i.length;o++){var r=i[o];void 0!==r.payoff&&(n[r.key]={pick:r.pick,payoff:r.payoff})}function a(){void 0!==t&&t()}u.log("Completing experiments",n),u.environment.http("POST",f("completeExperiments"),{version:1,appKey:u.appKey,experiments:n},function(){return a()},function(t){u.error("Failed to complete experiments",t),a()})},10),this.log("Initialize",e),this.preinitialized=void 0!==o,this.serialized={lastInitialized:0,experimentPicks:{}};try{var i=t.getLocalStorage(this.storageKey("state"));void 0!==i&&(this.serialized=s.Convert.toSerializedState(i))}catch(t){}var r=(new Date).getTime();864e5<r-this.serialized.lastInitialized&&(this.log("Starting a new session"),this.serialized.experimentPicks={}),this.serialized.lastInitialized=r,this.serializeStateDebounced(),void 0===o?t.http("GET",a.outcomesUrl(e),void 0,function(t){u.log("Got outcomes",t),u.finishInit(t),n(u)},function(t){u.error("Could not get outcomes",t),u.finishInit({}),n(u)}):this.finishInit(o)}return t.prototype.log=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];(t=this.environment).log.apply(t,e)},t.prototype.error=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];(t=this.environment).error.apply(t,e)},t.prototype.getClientContext=function(){if(void 0===this.clientContext){this.clientContext={tzo:this.environment.getTimeZoneOffset()};var t=this.environment.getLocalLanguage();void 0!==t&&(this.clientContext.lang=t)}return this.clientContext},t.prototype.startExperiment=function(t){this.queuedStartedExperiments[t.name]=t,this.startExperimentsDebounced()},t.prototype.completeExperiment=function(t,e){this.queuedCompletedExperiments[t.name]=t,this.completeExperimentsDebounced(e)},t.prototype.completeDefaults=function(e,n){var o=this.defaultCompletions;Object.getOwnPropertyNames(o).forEach(function(t){return o[t].complete(e,n)})},t.prototype.finishInit=function(i){var r=this;try{var a=this.getClientContext();Object.getOwnPropertyNames(i).forEach(function(t){if(void 0===r.experimentOptions[t]){var e=u.lookupBestOption(a,i[t]),n=e.option,o=e.epsilon;r.experimentOptions[t]=new l(i[t].options,n,o)}}),this.preinitialized&&(this.environment.startHTMLExperiments(),this.environment.autocomplete(function(t){return r.completeDefaults(t,void 0)}))}catch(t){this.error("Couldn't finish init",t)}},t.prototype.experiment=function(t,e){var n=this.experiments[t];if(void 0!==n)return n;var o=this.experimentOptions[t];return void 0===o&&(o=this.experimentOptions[t]=new l(e)),n=this.experiments[t]=new i(this,t,o),this.defaultCompletions[t]=n,this.startExperiment(n),n},t.prototype.storageKey=function(t){return"autotune.v1."+this.appKey+"."+t},t.prototype.loadPick=function(t){return this.serialized.experimentPicks[t]},t.prototype.savePick=function(t,e){this.serialized.experimentPicks[t]=e,this.serializeStateDebounced()},t}();n.Client=o;var i=function(){function t(t,e,n){this.client=t,this.name=e,this.options=n,this.key=p.uuidv4();var o=this.options,i=o.optionNames,r=o.bestOption,a=o.epsilon,u=this.client.loadPick(this.name);if(void 0!==u&&-1!==i.indexOf(u))this.pick=u,this.pickedBest=u===r;else{var s=void 0===r||-1===i.indexOf(r)||Math.random()<a,c=void 0;c=s||void 0===r?i[Math.floor(Math.random()*i.length)]:r,this.client.savePick(this.name,c),this.pick=c,this.pickedBest=!s}}return t.prototype.complete=function(t,e){void 0===t&&(t=1),this.payoff=t,this.client.completeExperiment(this,e)},t}();n.Experiment=i},{"./DecisionTree":3,"./common/ClientAPI":4,"./common/models":5,"./debounce":6,"./util":9}],3:[function(t,e,n){"use strict";n.__esModule=!0,n.lookupBestOption=function(r,t){if(void 0===t)return{};var a=t.options;return function t(e){if(void 0!==e.best)return{option:a[e.best],epsilon:e.eps};if(void 0===e.at||void 0===e.op||void 0===e.v)return{};var n,o=r[e.at];switch("string"==typeof e.v?"string"!=typeof o&&(o="null"):"number"!=typeof o&&(o=0),e.op){case"lt":n=o<e.v;break;case"eq":n=o===e.v;break;default:return{}}var i=n?e.l:e.r;return void 0===i?{}:t(i)}(t.tree)}},{}],4:[function(t,e,n){"use strict";function o(t){return"https://s3.us-east-2.amazonaws.com/js.autotune.xyz/"+t}n.__esModule=!0,n.s3Url=o,n.outcomesUrl=function(t){return o(t+".json")},n.clientUrl=function(t){return o(t+".js")}},{}],5:[function(t,e,n){"use strict";n.__esModule=!0,function(t){function u(t,e){if("any"===t)return!0;if(null===t)return null===e;if(!1===t)return!1;for(;"object"==typeof t&&void 0!==t.ref;)t=s[t.ref];return Array.isArray(t)?(n=e,-1!==t.indexOf(n)):"object"==typeof t?t.hasOwnProperty("unionMembers")?(r=t.unionMembers,a=e,r.some(function(t){return u(t,a)})):t.hasOwnProperty("arrayItems")?(o=t.arrayItems,i=e,Array.isArray(i)&&i.every(function(t){return u(o,t)})):!!t.hasOwnProperty("props")&&function(n,o,i){if(null===i||"object"!=typeof i||Array.isArray(i))return!1;return Object.getOwnPropertyNames(i).every(function(t){var e=i[t];return Object.prototype.hasOwnProperty.call(n,t)?u(n[t],e):u(o,e)})}(t.props,t.additional,e):typeof t==typeof e;var n,o,i,r,a}t.toSerializedState=function(t){return function(t,e){if(!u(e,t))throw Error("Invalid value");return t}(JSON.parse(t),{ref:"SerializedState"})},t.serializedStateToJson=function(t){return JSON.stringify(t,null,2)};var e,n,o,s={SerializedState:(e={experimentPicks:(o="",{props:{},additional:o}),lastInitialized:0},n="any",{props:e,additional:n})}}(n.Convert||(n.Convert={}))},{}],6:[function(t,e,n){"use strict";n.__esModule=!0,n.debounce=function(i,r,a){var u;return void 0===r&&(r=50),void 0===a&&(a={isImmediate:!1}),function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=this,o=a.isImmediate&&void 0===u;void 0!==u&&clearTimeout(u),u=setTimeout(function(){u=void 0,a.isImmediate||i.apply(n,t)},r),o&&i.apply(n,t)}}},{}],7:[function(t,e,n){"use strict";n.__esModule=!0;var c=t("."),p=t("./util");function f(t){return t.getAttribute("option")||p.hash(t.outerHTML).toString()}n.startHTMLExperiments=function(){function t(){var t;!function(){var i,t,r,e,a=(r={},e=document.querySelectorAll("[data-experiment]"),p.each(e,function(t){var e=t.getAttribute("data-experiment"),n=t.getAttribute("data-option");if(null!==e&&null!==n){var o=r[e];void 0===o&&(o=r[e]={options:[],nodes:[]}),-1===o.options.indexOf(n)&&o.options.push(n),o.nodes.push(t)}}),r),o=(i={},t=document.getElementsByTagName("autotune"),p.each(t,function(t){var e=t.getAttribute("experiment")||p.hash(t.innerHTML).toString(),n={node:t,options:p.map(t.children,f)},o=i[e]||[];o.push(n),i[e]=o}),i);Object.getOwnPropertyNames(a).forEach(function(t){var e=a[t],n=e.options,o=e.nodes,i=c.oneOf(t,n);o.forEach(function(t){t.getAttribute("data-option")!==i&&t.remove()})}),Object.getOwnPropertyNames(o).forEach(function(t){var e={};o[t].forEach(function(t){t.options.forEach(function(t){return e[t]=null})});var n=c.oneOf(t,Object.getOwnPropertyNames(e));o[t].forEach(function(t){p.map(t.node.children,function(t){return t}).forEach(function(t){f(t)!==n&&t.remove()})})});var u,n,s=(u={},n=document.querySelectorAll("[autotune-class],[data-autotune-class]"),p.each(n,function(t){var e=(t.getAttribute("autotune-class")||t.getAttribute("data-autotune-class")||"").split(" "),n=t.getAttribute("autotune-experiment")||t.getAttribute("data-autotune-experiment")||p.hash(t.innerHTML)+"-class";u[n]={options:e,node:t}}),u);Object.getOwnPropertyNames(s).forEach(function(t){var e=s[t],n=c.oneOf(t,e.options);e.node.classList.add(n)})}(),t=document.querySelectorAll("a[autotune],a[data-autotune],button[autotune],button[data-autotune]"),p.each(t,function(e){var n=e.onclick;e.onclick=function(t){t.preventDefault(),c.complete(function(){"function"==typeof n?n.bind(e)(t):e instanceof HTMLAnchorElement&&(window.location.href=e.href)})}})}"complete"===document.readyState?t():document.addEventListener("DOMContentLoaded",function(){t()})}},{".":8,"./util":9}],8:[function(t,e,n){"use strict";n.__esModule=!0;var r,o=t("./Client"),a=new(t("./BrowserEnvironment").BrowserEnvironment);function i(t,e,n){void 0===r?r=new o.Client(a,t,e,n):a.error("autotune initialized more than once")}if(n.initialize=i,n.flipCoin=function(t){return void 0===r?(a.error("autotune must be initialized before calling flipCoin"),!0):"true"===r.experiment(t,["true","false"]).pick},n.oneOf=function(t,e){var n,o,i="[object Array]"===Object.prototype.toString.call(e);return n=i?e:Object.getOwnPropertyNames(e),void 0===r?(a.error("autotune must be initialized before calling oneOf"),o=n[0]):o=r.experiment(t,n).pick,i?o:e[o]},n.complete=function(t,e){var n,o;void 0!==r?(n="number"==typeof t?t:1,o="function"==typeof t?t:e,r.completeDefaults(n,o)):a.error("autotune must be initialized before calling complete")},"undefined"!=typeof window&&void 0!==window.autotuneConfig){var u=window.autotuneConfig;i(u.appKey,function(){},u.outcomes)}},{"./BrowserEnvironment":1,"./Client":2}],9:[function(t,e,n){"use strict";function o(t,e){for(var n=[],o=0;o<t.length;o++)n.push(e(t.item(o),o));return n}n.__esModule=!0,n.uuidv4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})},n.getOwnPropertyValues=function(e){return Object.getOwnPropertyNames(e).map(function(t){return e[t]})},n.mapObject=function(e,n){var o={};return Object.getOwnPropertyNames(e).forEach(function(t){return o[t]=n(e[t],t)}),o},n.map=o,n.each=function(t,n){o(t,function(t,e){n(t,e)})},n.hash=function(t){for(var e=0,n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n),e&=e;return Math.abs(e)}},{}]},{},[8])(8)});
{
"name": "autotune",
"license": "Apache-2.0",
"version": "2.0.45",
"version": "2.0.46",
"description": "Automatically tune JavaScript apps",

@@ -6,0 +6,0 @@ "main": "dist/index.js",

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

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