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

@hackler/sdk-core

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hackler/sdk-core - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0-rc.1

lib/internal/evaluation/Bucketer.d.ts

62

lib/HackleClient.d.ts
import AutoCloseable from "./external/js/lang/AutoCloseable";
import { Decision, User, UserEvent } from "./internal/model/model";
import { Decision, FeatureFlagDecision, User, UserEvent } from "./internal/model/model";
export default interface HackleClient extends AutoCloseable {
/**
* Decide the variation to expose to the user for experiment.
* Returns the default variation if the variation cannot be decided.
* Determine the variation to expose to the user for experiment.
*
* @param experimentKey the unique key for the experiment.
* @param user the identifier of your customer. id (e.g. user_email, account_id, etc.) MUST NOT be null. (e.g. { id: "userId"} )
* @param defaultVariation the default variation of the experiment. (Optional)
* This method return the {"A"} if:
* - The experiment key is invalid
* - The experiment has not started yet
* - The user is not allocated to the experiment
* - The determined variation has been dropped
*
* @return the decided variation for the user, or the default variation.
* @param experimentKey the unique key of the experiment.
* @param user the user to participate in the experiment. MUST NOT be null.
* @param defaultVariation the default variation of the experiment.
*
* @return string the decided variation for the user, or the default variation.
*/
variation(experimentKey: number, user: User, defaultVariation?: string): string;
variation(experimentKey: number, user: User | string, defaultVariation?: string): string;
/**
* Decide the variation to expose to the user for experiment, and returns an object that
* describes the way the variation was decided.
* Determine the variation to expose to the user for experiment, and returns an object that
* describes the way the variation was determined.
*
* @param experimentKey the unique key for the experiment.
* @param experimentKey the unique key of the experiment.
* @param user the user to participate in the experiment. MUST NOT be null. (e.g. { id: "userId"} )
* @param defaultVariation the default variation of the experiment. MUST NOT be null.
*
* @return a [Decision] object
* @return {Decision} object
*/
variationDetail(experimentKey: number, user: User, defaultVariation?: string): Decision;
variationDetail(experimentKey: number, user: User | string, defaultVariation?: string): Decision;
/**
* Records the event performed by the user.
* Determine whether the feature is turned on to the user.
*
* @param event the unique key of the event. MUST NOT be null.
* @param user the identifier of user that performed the event. id MUST NOT be null. (e.g. { id: "userId"} )
* @param featureKey the unique key for the feature.
* @param user the user requesting the feature.
*
* @return boolean True if the feature is on. False if the feature is off.
*
* @since 2.0.0
*/
track(event: string | UserEvent, user: User): void;
isFeatureOn(featureKey: number, user: User | string): boolean;
/**
* Determine whether the feature is turned on to the user, and returns an object that
* describes the way the value was determined.
*
* @param featureKey the unique key for the feature.
* @param user the identifier of user.
*
* @return {FeatureFlagDecision}
*
* @since 2.0.0
*/
featureFlagDetail(featureKey: number, user: User | string): FeatureFlagDecision;
/**
* Records the event that occurred by the user.
*
* @param event the unique key of the event that occurred. MUST NOT be null.
* @param user the user that occurred the event. MUST NOT be null.
*/
track(event: UserEvent | string, user: User | string): void;
onReady(block: () => void, timeout?: number): void;
}
//# sourceMappingURL=HackleClient.d.ts.map
/// <reference types="node" />
import PollingWorkspaceFetcher from "../workspace/PollingWorkspaceFetcher";
import EventProcessor from "../event/EventProcessor";
import { Decision, Properties, User, UserEvent, VariationKey } from "../model/model";
import { Decision, FeatureFlagDecision, Properties, User, UserEvent, VariationKey } from "../model/model";
import { EventEmitter } from "events";
import WorkspaceFetcher from "../workspace/WorkspaceFetcher";
export default class HackleInternalClient {

@@ -10,8 +10,8 @@ private workspaceFetcher;

private eventEmitter;
private allocator;
private evaluator;
private readonly readyPromise;
constructor(workspaceFetcher: PollingWorkspaceFetcher, eventProcessor: EventProcessor, eventEmitter: EventEmitter);
_variation(experimentKey: number, user: User, hackleProperties?: Properties, defaultVariation?: VariationKey): Decision;
private __variation;
_track(event: string | UserEvent, user: User, hackleProperties?: Properties): void;
constructor(workspaceFetcher: WorkspaceFetcher, eventProcessor: EventProcessor, eventEmitter: EventEmitter);
_experiment(experimentKey: number, user: User, hackleProperties: Properties, defaultVariation: VariationKey): Decision;
_featureFlag(featureKey: number, user: User, hackleProperties: Properties): FeatureFlagDecision;
_track(event: UserEvent, user: User, hackleProperties?: Properties): void;
_onReady(block: () => void, timeout?: number): void;

@@ -18,0 +18,0 @@ _close(): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Allocator_1 = require("../allocation/Allocator");
var model_1 = require("../model/model");

@@ -8,6 +7,7 @@ var Event_1 = require("../event/Event");

var logger_1 = require("../logger");
var Evaluator_1 = require("../evaluation/Evaluator");
var log = logger_1.default.log;
var HackleInternalClient = /** @class */ (function () {
function HackleInternalClient(workspaceFetcher, eventProcessor, eventEmitter) {
this.allocator = new Allocator_1.default();
this.evaluator = new Evaluator_1.default();
this.workspaceFetcher = workspaceFetcher;

@@ -24,31 +24,20 @@ this.eventProcessor = eventProcessor;

}
HackleInternalClient.prototype._variation = function (experimentKey, user, hackleProperties, defaultVariation) {
if (defaultVariation === void 0) { defaultVariation = "A"; }
var decision = this.__variation(experimentKey, user, hackleProperties, defaultVariation);
log.debug("Decision : " + JSON.stringify(decision));
return decision;
};
HackleInternalClient.prototype.__variation = function (experimentKey, user, hackleProperties, defaultVariation) {
if (defaultVariation === void 0) { defaultVariation = "A"; }
HackleInternalClient.prototype._experiment = function (experimentKey, user, hackleProperties, defaultVariation) {
if (!experimentKey) {
log.error("Experiment Key Is Not Empty");
return model_1.Decision.of(defaultVariation, model_1.DecisionReason.EXCEPTION);
log.error("experimentKey must not be empty");
return model_1.Decision.of(defaultVariation, model_1.DecisionReason.INVALID_INPUT);
}
var userId;
var properties;
if (user) {
userId = user.id;
properties = user.properties;
if (!userId || typeof userId !== "string") {
log.error("Id must not be null. or Id must be string type");
return model_1.Decision.of(defaultVariation, model_1.DecisionReason.EXCEPTION);
if (!user.id || typeof user.id !== "string") {
log.error("user.id must not be null and must be string type");
return model_1.Decision.of(defaultVariation, model_1.DecisionReason.INVALID_INPUT);
}
}
else {
log.error("User must not be null.");
return model_1.Decision.of(defaultVariation, model_1.DecisionReason.EXCEPTION);
log.error("user must not be null.");
return model_1.Decision.of(defaultVariation, model_1.DecisionReason.INVALID_INPUT);
}
var workspace = this.workspaceFetcher.get();
if (!workspace) {
log.warn("SDK not ready");
log.warn("SDK not ready.");
return model_1.Decision.of(defaultVariation, model_1.DecisionReason.SDK_NOT_READY);

@@ -61,22 +50,47 @@ }

}
var allocation = this.allocator.allocate(experiment, userId);
if (allocation instanceof Allocator_1.Allocation.NotAllocated) {
return model_1.Decision.of(defaultVariation, allocation.decisionReason);
var evaluation = this.evaluator.evaluate(experiment, user, defaultVariation);
this.eventProcessor.process(Event_1.default.exposure(experiment, user, evaluation, hackleProperties));
return model_1.Decision.of(evaluation.variationKey, evaluation.reason);
};
HackleInternalClient.prototype._featureFlag = function (featureKey, user, hackleProperties) {
if (!featureKey) {
log.error("featureKey must not be empty");
return model_1.FeatureFlagDecision.off(model_1.DecisionReason.INVALID_INPUT);
}
else if (allocation instanceof Allocator_1.Allocation.ForcedAllocated) {
return model_1.Decision.of(allocation.variationKey, allocation.decisionReason);
if (user) {
if (!user.id || typeof user.id !== "string") {
log.error("user.id must not be null and must be string type");
return model_1.FeatureFlagDecision.off(model_1.DecisionReason.INVALID_INPUT);
}
}
else if (allocation instanceof Allocator_1.Allocation.Allocated) {
this.eventProcessor.process(Event_1.default.exposure(experiment, allocation.variation, userId, hackleProperties));
return model_1.Decision.of(allocation.variation.key, allocation.decisionReason);
else {
log.error("user must not be null.");
return model_1.FeatureFlagDecision.off(model_1.DecisionReason.INVALID_INPUT);
}
return model_1.Decision.of(defaultVariation, model_1.DecisionReason.EXCEPTION);
var workspace = this.workspaceFetcher.get();
if (!workspace) {
log.warn("SDK not ready.");
return model_1.FeatureFlagDecision.off(model_1.DecisionReason.SDK_NOT_READY);
}
var featureFlag = workspace.getFeatureFlagOrNull(featureKey);
if (!featureFlag) {
log.warn("FeatureFlag does not exist.");
return model_1.FeatureFlagDecision.off(model_1.DecisionReason.EXPERIMENT_NOT_FOUND);
}
var evaluation = this.evaluator.evaluate(featureFlag, user, "A");
this.eventProcessor.process(Event_1.default.exposure(featureFlag, user, evaluation, hackleProperties));
if (evaluation.variationKey === "A") {
return model_1.FeatureFlagDecision.off(evaluation.reason);
}
else {
return model_1.FeatureFlagDecision.on(evaluation.reason);
}
};
HackleInternalClient.prototype._track = function (event, user, hackleProperties) {
if (!event) {
log.warn("event key or event must not be null.");
log.warn("event must not be null.");
return;
}
if (typeof event !== "string" && typeof event !== "object") {
log.warn("Event must be string or event type.");
if (typeof event !== "object") {
log.warn("Event must be event type.");
return;

@@ -90,8 +104,4 @@ }

}
var userId;
var properties;
if (user) {
userId = user.id;
properties = user.properties;
if (!userId || typeof userId !== "string") {
if (!user.id || typeof user.id !== "string") {
log.error("Id must not be null. or Id must be string type");

@@ -110,10 +120,4 @@ return;

}
if (typeof event === "string") {
var eventType = workspace.getEventTypeOrNull(event);
this.eventProcessor.process(Event_1.default.track(eventType, userId, 0.0, {}, hackleProperties));
}
else {
var eventType = workspace.getEventTypeOrNull(event.key);
this.eventProcessor.process(Event_1.default.track(eventType, userId, event.value || 0.0, event.properties || {}, hackleProperties));
}
var eventType = workspace.getEventTypeOrNull(event.key);
this.eventProcessor.process(Event_1.default.track(eventType, event, user, hackleProperties));
};

@@ -120,0 +124,0 @@ HackleInternalClient.prototype._onReady = function (block, timeout) {

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

export declare const WORKSPACE_FETCH_URL = "https://sdk.hackle.io/api/v1/workspaces";
export declare const EVENT_DISPATCH_URL = "https://event.hackle.io/api/v1/events";
export declare const WORKSPACE_FETCH_URL = "https://sdk.hackle.io/api/v2/workspaces";
export declare const EVENT_DISPATCH_URL = "https://event.hackle.io/api/v2/events";
export declare const SDK_KEY_HEADER = "X-HACKLE-SDK-KEY";

@@ -4,0 +4,0 @@ export declare const SDK_NAME_HEADER = "X-HACKLE-SDK-NAME";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ERROR_RETRY_BASE_WAIT_SECONDS_BY_ERROR_COUNT = exports.DEFAULT_ON_READY_TIMEOUT = exports.DEFAULT_FLUSH_INTERVAL = exports.BATCH_SIZE = exports.DEFAULT_MAX_QUEUE_SIZE = exports.REQUEST_TIME_OUT = exports.DEFAULT_POOL_INTERVAL = exports.SDK_VERSION_HEADER = exports.SDK_NAME_HEADER = exports.SDK_KEY_HEADER = exports.EVENT_DISPATCH_URL = exports.WORKSPACE_FETCH_URL = void 0;
exports.WORKSPACE_FETCH_URL = "https://sdk.hackle.io/api/v1/workspaces";
exports.EVENT_DISPATCH_URL = "https://event.hackle.io/api/v1/events";
exports.WORKSPACE_FETCH_URL = "https://sdk.hackle.io/api/v2/workspaces";
exports.EVENT_DISPATCH_URL = "https://event.hackle.io/api/v2/events";
exports.SDK_KEY_HEADER = "X-HACKLE-SDK-KEY";

@@ -7,0 +7,0 @@ exports.SDK_NAME_HEADER = "X-HACKLE-SDK-NAME";

@@ -10,6 +10,9 @@ import { Double, Long, Properties } from "../model/model";

userId: string;
userProperties: Properties;
experimentId: Long;
experimentKey: Long;
variationId: Long;
experimentType: string;
variationId?: Long;
variationKey: string;
decisionReason: string;
hackleProperties?: Properties;

@@ -20,2 +23,3 @@ }

userId: string;
userProperties: Properties;
eventTypeId: Long;

@@ -22,0 +26,0 @@ eventTypeKey: string;

@@ -1,10 +0,11 @@

import { Double, EventType, Experiment, Long, Properties, UserId, Variation } from "../model/model";
import { DecisionReason, EventType, Experiment, Long, Properties, User, UserEvent, VariationId, VariationKey } from "../model/model";
import { ExposureEventDto, TrackEventDto } from "./dto";
import { Evaluation } from "../evaluation/Evaluator";
export default class Event {
timestamp: Long;
userId: UserId;
user: User;
hackleProperties?: Properties;
constructor(timestamp: Long, userId: UserId, hackleProperties: Properties);
static exposure(experiment: Experiment, variation: Variation, userId: UserId, hackleProperties?: Properties): Exposure;
static track(eventType: EventType, userId: UserId, value: Double, properties: Properties, hackleProperties?: Properties): Track;
constructor(timestamp: Long, user: User, hackleProperties: Properties);
static exposure(experiment: Experiment, user: User, evaluation: Evaluation, hackleProperties?: Properties): Exposure;
static track(eventType: EventType, event: UserEvent, user: User, hackleProperties?: Properties): Track;
static isExposure(event: Event): event is Exposure;

@@ -15,19 +16,18 @@ static isTrack(event: Event): event is Track;

timestamp: Long;
userId: UserId;
user: User;
hackleProperties?: Properties;
experiment: Experiment;
variation: Variation;
constructor(timestamp: Long, userId: UserId, experiment: Experiment, variation: Variation, hackleProperties: Properties);
variationId?: VariationId;
variationKey: VariationKey;
decisionReason: DecisionReason;
constructor(timestamp: Long, user: User, experiment: Experiment, variationId: VariationId | undefined, variationKey: VariationKey, decisionReason: DecisionReason, hackleProperties: Properties);
toDto(): ExposureEventDto;
}
export declare class Track extends Event {
timestamp: Long;
userId: UserId;
eventType: EventType;
event: UserEvent;
hackleProperties?: Properties;
eventType: EventType;
value: Double;
properties: Properties;
constructor(timestamp: Long, userId: UserId, eventType: EventType, value: Double, properties: Properties, hackleProperties: Properties);
constructor(timestamp: Long, user: User, eventType: EventType, event: UserEvent, hackleProperties: Properties);
toDto(): TrackEventDto;
}
//# sourceMappingURL=Event.d.ts.map

@@ -5,15 +5,16 @@ "use strict";

var tslib_1 = require("tslib");
var PropertyUtil_1 = require("../util/PropertyUtil");
var Event = /** @class */ (function () {
function Event(timestamp, userId, hackleProperties) {
function Event(timestamp, user, hackleProperties) {
this.timestamp = timestamp;
this.userId = userId;
this.user = user;
this.hackleProperties = hackleProperties;
}
Event.exposure = function (experiment, variation, userId, hackleProperties) {
Event.exposure = function (experiment, user, evaluation, hackleProperties) {
if (hackleProperties === void 0) { hackleProperties = {}; }
return new Exposure(new Date().getTime(), userId, experiment, variation, hackleProperties);
return new Exposure(new Date().getTime(), user, experiment, evaluation.variationId, evaluation.variationKey, evaluation.reason, hackleProperties);
};
Event.track = function (eventType, userId, value, properties, hackleProperties) {
Event.track = function (eventType, event, user, hackleProperties) {
if (hackleProperties === void 0) { hackleProperties = {}; }
return new Track(new Date().getTime(), userId, eventType, value, properties, hackleProperties);
return new Track(new Date().getTime(), user, eventType, event, hackleProperties);
};

@@ -31,8 +32,8 @@ Event.isExposure = function (event) {

tslib_1.__extends(Exposure, _super);
function Exposure(timestamp, userId, experiment, variation, hackleProperties) {
var _this = _super.call(this, timestamp, userId, hackleProperties) || this;
_this.timestamp = timestamp;
_this.userId = userId;
function Exposure(timestamp, user, experiment, variationId, variationKey, decisionReason, hackleProperties) {
var _this = _super.call(this, timestamp, user, hackleProperties) || this;
_this.experiment = experiment;
_this.variation = variation;
_this.variationId = variationId;
_this.variationKey = variationKey;
_this.decisionReason = decisionReason;
return _this;

@@ -43,7 +44,10 @@ }

timestamp: this.timestamp,
userId: this.userId,
userId: this.user.id,
userProperties: PropertyUtil_1.default.filteredProperties(this.user.properties || {}),
experimentId: this.experiment.id,
experimentKey: this.experiment.key,
variationId: this.variation.id,
variationKey: this.variation.key,
experimentType: this.experiment.type,
variationId: this.variationId,
variationKey: this.variationKey,
decisionReason: this.decisionReason.toString(),
hackleProperties: this.hackleProperties

@@ -57,9 +61,6 @@ };

tslib_1.__extends(Track, _super);
function Track(timestamp, userId, eventType, value, properties, hackleProperties) {
var _this = _super.call(this, timestamp, userId, hackleProperties) || this;
_this.timestamp = timestamp;
_this.userId = userId;
function Track(timestamp, user, eventType, event, hackleProperties) {
var _this = _super.call(this, timestamp, user, hackleProperties) || this;
_this.eventType = eventType;
_this.value = value;
_this.properties = properties;
_this.event = event;
return _this;

@@ -70,7 +71,8 @@ }

timestamp: this.timestamp,
userId: this.userId,
userId: this.user.id,
userProperties: this.user.properties || {},
eventTypeId: this.eventType.id,
eventTypeKey: this.eventType.key,
value: this.value,
properties: this.properties,
value: this.event.value || 0,
properties: PropertyUtil_1.default.filteredProperties(this.event.properties || {}),
hackleProperties: this.hackleProperties

@@ -77,0 +79,0 @@ };

@@ -50,4 +50,3 @@ "use strict";

}
catch (e) {
}
catch (e) { }
return Promise.resolve();

@@ -64,5 +63,6 @@ };

return (eventA.timestamp == eventB.timestamp &&
eventA.userId == eventB.userId);
eventA.user.id == eventB.user.id &&
eventA.user.properties == eventB.user.properties);
}
exports.areEventContextsEqual = areEventContextsEqual;
//# sourceMappingURL=EventProcessor.js.map

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

/// <reference types="node" />
import http from "http";
export interface Response {

@@ -14,4 +12,8 @@ statusCode?: number;

}
export declare function getRequest(requestUrl: string, headers: Headers): Request;
export declare function postRequest(requestUrl: string, data: any, headers: Headers, callback: any): http.ClientRequest;
export interface getRequest {
(requestUrl: string, headers: Headers): Request;
}
export interface postRequest {
(requestUrl: string, data: any, headers: Headers, callback: any): void;
}
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.postRequest = exports.getRequest = void 0;
var tslib_1 = require("tslib");
var http_1 = require("http");
var https_1 = require("https");
var url_1 = require("url");
var config_1 = require("../config");
function getRequest(requestUrl, headers) {
var parsedUrl = url_1.default.parse(requestUrl);
var requester;
if (parsedUrl.protocol === "http:") {
requester = http_1.default.request;
}
else if (parsedUrl.protocol === "https:") {
requester = https_1.default.request;
}
else {
return {
responsePromise: Promise.reject(new Error("Unknown Error")),
abort: function () {
}
};
}
var requestOptions = {
hostname: parsedUrl.hostname,
path: parsedUrl.path,
port: parsedUrl.port,
protocol: parsedUrl.protocol,
method: "GET",
headers: tslib_1.__assign(tslib_1.__assign({}, headers), { "Content-Type": "application/json" })
};
var request = requester(requestOptions);
var responsePromise = new Promise(function (resolve, reject) {
var timeout = setTimeout(function () {
request.abort();
reject(new Error("Request time out"));
}, config_1.REQUEST_TIME_OUT);
request.once("response", function (incomingMessage) {
if (request.aborted) {
return;
}
var response = incomingMessage;
response.setEncoding("utf8");
var responseData = "";
response.on("data", function (chunk) {
if (!request.aborted) {
responseData += chunk;
}
});
response.on("end", function () {
clearTimeout(timeout);
resolve({
statusCode: incomingMessage.statusCode,
body: responseData
});
});
});
request.on("error", function (err) {
clearTimeout(timeout);
if (err instanceof Error) {
reject(err);
}
else if (typeof err === "string") {
reject(new Error(err));
}
else {
reject(new Error("Request error"));
}
});
});
request.end();
return {
abort: function () {
request.abort();
},
responsePromise: responsePromise
};
}
exports.getRequest = getRequest;
function postRequest(requestUrl, data, headers, callback) {
var parsedUrl = url_1.default.parse(requestUrl);
var dataString = JSON.stringify(data);
var requestOptions = {
host: parsedUrl.host,
path: parsedUrl.path,
method: "POST",
headers: tslib_1.__assign(tslib_1.__assign({}, headers), { "content-type": "application/json", "content-length": dataString.length.toString() })
};
var requestCallback = function (response) {
if (response && response.statusCode && response.statusCode >= 200 && response.statusCode < 400) {
callback(response);
}
};
var request = (parsedUrl.protocol === "http:" ? http_1.default : https_1.default).request(requestOptions, requestCallback);
request.on("error", function (err) {
});
request.write(dataString);
request.end();
return request;
}
exports.postRequest = postRequest;
//# sourceMappingURL=index.js.map

@@ -9,3 +9,3 @@ "use strict";

INFO: 3,
DEBUG: 4,
DEBUG: 4
};

@@ -12,0 +12,0 @@ var Logger = /** @class */ (function () {

@@ -23,2 +23,12 @@ export declare type Int = number;

/**
* An object that contains the decided flag and the reason for the feature flag decision.
*/
export declare class FeatureFlagDecision {
isOn: boolean;
reason: DecisionReason;
constructor(isOn: boolean, reason: DecisionReason);
static on(reason: DecisionReason): FeatureFlagDecision;
static off(reason: DecisionReason): FeatureFlagDecision;
}
/**
* Describes the reason for the [Variation] decision.

@@ -29,3 +39,2 @@ */

* Indicates that the sdk is not ready to use. e.g. invalid SDK key.
* Returns the default variation.
*/

@@ -35,8 +44,14 @@ static SDK_NOT_READY: string;

* Indicates that no experiment was found for the experiment key provided by the caller.
* Returns the default variation.
*/
static EXPERIMENT_NOT_FOUND: string;
/**
* Indicates that the experiment is in draft.
*/
static EXPERIMENT_DRAFT: string;
/**
* Indicates that the experiment was paused.
*/
static EXPERIMENT_PAUSED: string;
/**
* Indicates that the experiment was completed.
* Returns the winner variation.
*/

@@ -46,3 +61,2 @@ static EXPERIMENT_COMPLETED: string;

* Indicates that the user has been overridden as a specific variation.
* Returns the overridden variation.
*/

@@ -52,3 +66,2 @@ static OVERRIDDEN: string;

* Indicates that the experiment is running but the user is not allocated to the experiment.
* Returns the default variation.
*/

@@ -58,3 +71,2 @@ static TRAFFIC_NOT_ALLOCATED: string;

* Indicates that the original decided variation has been dropped.
* Returns the default variation.
*/

@@ -64,3 +76,2 @@ static VARIATION_DROPPED: string;

* Indicates that the user has been allocated to the experiment.
* Returns the allocated variation.
*/

@@ -70,50 +81,951 @@ static TRAFFIC_ALLOCATED: string;

* Indicates that the variation could not be decided due to an unexpected exception.
* Returns the default variation.
*/
static EXCEPTION: string;
/**
* Indicates that the input value is invalid.
*/
static INVALID_INPUT: string;
}
export declare type ExperimentType = "AB_TEST" | "FEATURE_FLAG";
export declare class Experiment {
id: ExperimentId;
key: ExperimentKey;
constructor(id: ExperimentId, key: ExperimentKey);
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
constructor(id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides);
static Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
};
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Completed: any;
};
};
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
};
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Paused: any;
Completed: any;
};
};
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Completed: any;
};
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Paused: any;
Completed: any;
};
Completed: any;
};
};
static Running: {
new (id: ExperimentId, key: ExperimentKey, bucket: Bucket, variations: Map<VariationId, Variation>, userOverrides: UserOverrides): {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
bucket: Bucket;
type: ExperimentType;
variations: Map<VariationId, Variation>;
userOverrides: UserOverrides;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
};
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Completed: any;
};
};
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
};
Running: any;
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Running: any;
Paused: any;
Completed: any;
};
};
Completed: {
new (id: ExperimentId, key: ExperimentKey, winnerVariationKey: VariationKey): {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
winnerVariationKey: VariationKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Completed: any;
};
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Running: any;
Paused: any;
Completed: any;
};
Completed: any;
};
};
static Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
};
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Paused: any;
Completed: any;
};
};
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
};
Running: any;
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Running: any;
Paused: any;
Completed: any;
};
};
Paused: any;
Completed: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Paused: any;
Completed: any;
};
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Running: any;
Paused: any;
Completed: any;
};
Paused: any;
Completed: any;
};
};
static Completed: {
new (id: ExperimentId, key: ExperimentKey, winnerVariationKey: VariationKey): {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides, _winnerVariationId: Long): {
winnerVariationKey: VariationKey;
id: ExperimentId;
key: ExperimentKey;
winnerVariationKey: VariationKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Completed: any;
};
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Paused: any;
Completed: any;
};
Completed: any;
};
Running: {
new (id: ExperimentId, key: ExperimentKey, bucket: Bucket, variations: Map<VariationId, Variation>, userOverrides: UserOverrides): {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
bucket: Bucket;
type: ExperimentType;
variations: Map<VariationId, Variation>;
userOverrides: UserOverrides;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Completed: any;
};
Running: any;
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Running: any;
Paused: any;
Completed: any;
};
Completed: any;
};
Paused: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Paused: any;
Completed: any;
};
Running: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, bucket: Bucket, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
bucket: Bucket;
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: {
new (id: ExperimentId, key: ExperimentKey, type: ExperimentType, variations: Map<VariationId, Variation>, overrides: UserOverrides): {
id: ExperimentId;
key: ExperimentKey;
type: ExperimentType;
variations: Map<VariationId, Variation>;
overrides: UserOverrides;
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
};
Draft: any;
Running: any;
Paused: any;
Completed: any;
};
Running: any;
Paused: any;
Completed: any;
};
Paused: any;
Completed: any;
};
Completed: any;
};
getVariation(variationId: VariationId): Variation | undefined;
getOverriddenVariation(user: User): Variation | undefined;
}

@@ -120,0 +1032,0 @@ export declare class Variation {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventType = exports.Slot = exports.Bucket = exports.UserOverrides = exports.Variation = exports.Experiment = exports.DecisionReason = exports.Decision = void 0;
exports.EventType = exports.Slot = exports.Bucket = exports.UserOverrides = exports.Variation = exports.Experiment = exports.DecisionReason = exports.FeatureFlagDecision = exports.Decision = void 0;
var tslib_1 = require("tslib");

@@ -20,2 +20,19 @@ /**

/**
* An object that contains the decided flag and the reason for the feature flag decision.
*/
var FeatureFlagDecision = /** @class */ (function () {
function FeatureFlagDecision(isOn, reason) {
this.isOn = isOn;
this.reason = reason;
}
FeatureFlagDecision.on = function (reason) {
return new FeatureFlagDecision(true, reason);
};
FeatureFlagDecision.off = function (reason) {
return new FeatureFlagDecision(false, reason);
};
return FeatureFlagDecision;
}());
exports.FeatureFlagDecision = FeatureFlagDecision;
/**
* Describes the reason for the [Variation] decision.

@@ -28,3 +45,2 @@ */

* Indicates that the sdk is not ready to use. e.g. invalid SDK key.
* Returns the default variation.
*/

@@ -34,8 +50,14 @@ DecisionReason.SDK_NOT_READY = "SDK_NOT_READY";

* Indicates that no experiment was found for the experiment key provided by the caller.
* Returns the default variation.
*/
DecisionReason.EXPERIMENT_NOT_FOUND = "EXPERIMENT_NOT_FOUND";
/**
* Indicates that the experiment is in draft.
*/
DecisionReason.EXPERIMENT_DRAFT = "EXPERIMENT_DRAFT";
/**
* Indicates that the experiment was paused.
*/
DecisionReason.EXPERIMENT_PAUSED = "EXPERIMENT_PAUSED";
/**
* Indicates that the experiment was completed.
* Returns the winner variation.
*/

@@ -45,3 +67,2 @@ DecisionReason.EXPERIMENT_COMPLETED = "EXPERIMENT_COMPLETED";

* Indicates that the user has been overridden as a specific variation.
* Returns the overridden variation.
*/

@@ -51,3 +72,2 @@ DecisionReason.OVERRIDDEN = "OVERRIDDEN";

* Indicates that the experiment is running but the user is not allocated to the experiment.
* Returns the default variation.
*/

@@ -57,3 +77,2 @@ DecisionReason.TRAFFIC_NOT_ALLOCATED = "TRAFFIC_NOT_ALLOCATED";

* Indicates that the original decided variation has been dropped.
* Returns the default variation.
*/

@@ -63,3 +82,2 @@ DecisionReason.VARIATION_DROPPED = "VARIATION_DROPPED";

* Indicates that the user has been allocated to the experiment.
* Returns the allocated variation.
*/

@@ -69,5 +87,8 @@ DecisionReason.TRAFFIC_ALLOCATED = "TRAFFIC_ALLOCATED";

* Indicates that the variation could not be decided due to an unexpected exception.
* Returns the default variation.
*/
DecisionReason.EXCEPTION = "EXCEPTION";
/**
* Indicates that the input value is invalid.
*/
DecisionReason.INVALID_INPUT = "INVALID_INPUT";
return DecisionReason;

@@ -77,29 +98,45 @@ }());

var Experiment = /** @class */ (function () {
function Experiment(id, key) {
function Experiment(id, key, type, variations, overrides) {
this.id = id;
this.key = key;
this.type = type;
this.variations = variations;
this.overrides = overrides;
}
Experiment.prototype.getVariation = function (variationId) {
return this.variations.get(variationId);
};
Experiment.prototype.getOverriddenVariation = function (user) {
var overriddenVariation = this.overrides.get(user.id);
return overriddenVariation && this.getVariation(overriddenVariation.id);
};
Experiment.Draft = /** @class */ (function (_super) {
tslib_1.__extends(Draft, _super);
function Draft(id, key, type, variations, overrides) {
return _super.call(this, id, key, type, variations, overrides) || this;
}
return Draft;
}(Experiment));
Experiment.Running = /** @class */ (function (_super) {
tslib_1.__extends(Running, _super);
function Running(id, key, bucket, variations, userOverrides) {
var _this = _super.call(this, id, key) || this;
_this.id = id;
_this.key = key;
function Running(id, key, type, bucket, variations, overrides) {
var _this = _super.call(this, id, key, type, variations, overrides) || this;
_this.bucket = bucket;
_this.variations = variations;
_this.userOverrides = userOverrides;
return _this;
}
Running.prototype.getVariation = function (variationId) {
return this.variations.get(variationId);
};
return Running;
}(Experiment));
Experiment.Paused = /** @class */ (function (_super) {
tslib_1.__extends(Paused, _super);
function Paused(id, key, type, variations, overrides) {
return _super.call(this, id, key, type, variations, overrides) || this;
}
return Paused;
}(Experiment));
Experiment.Completed = /** @class */ (function (_super) {
tslib_1.__extends(Completed, _super);
function Completed(id, key, winnerVariationKey) {
var _this = _super.call(this, id, key) || this;
_this.id = id;
_this.key = key;
_this.winnerVariationKey = winnerVariationKey;
function Completed(id, key, type, variations, overrides, _winnerVariationId) {
var _a;
var _this = _super.call(this, id, key, type, variations, overrides) || this;
_this.winnerVariationKey = (_a = variations.get(_winnerVariationId)) === null || _a === void 0 ? void 0 : _a.key;
return _this;

@@ -106,0 +143,0 @@ }

import { List, Long } from "../model/model";
export interface WorkspaceDto {
experiments: List<ExperimentDto>;
completedExperiments: List<CompletedExperimentDto>;
featureFlags: List<ExperimentDto>;
buckets: List<BucketDto>;

@@ -11,5 +11,7 @@ events: List<EventTypeDto>;

key: Long;
status: string;
bucketId: Long;
variations: List<VariationDto>;
execution: ExecutionDto;
winnerVariationId?: Long;
}

@@ -21,8 +23,2 @@ export interface VariationDto {

}
export interface CompletedExperimentDto {
experimentId: Long;
experimentKey: Long;
winnerVariationId: Long;
winnerVariationKey: string;
}
export interface ExecutionDto {

@@ -29,0 +25,0 @@ status: string;

@@ -5,5 +5,7 @@ import { EventKey, EventType, Experiment, ExperimentKey } from "../model/model";

private experiments;
private featureFlags;
private eventTypes;
constructor(experiments: Map<ExperimentKey, Experiment>, eventTypes: Map<EventKey, EventType>);
constructor(experiments: Map<ExperimentKey, Experiment>, featureFlags: Map<ExperimentKey, Experiment>, eventTypes: Map<EventKey, EventType>);
getExperimentOrNull(experimentKey: ExperimentKey): Experiment | undefined;
getFeatureFlagOrNull(featureKey: ExperimentKey): Experiment | undefined;
getEventTypeOrNull(eventKey: EventKey): EventType;

@@ -10,0 +12,0 @@ static from(dto: WorkspaceDto): Workspace;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var model_1 = require("../model/model");
var Workspace = /** @class */ (function () {
function Workspace(experiments, eventTypes) {
function Workspace(experiments, featureFlags, eventTypes) {
this.experiments = experiments;
this.featureFlags = featureFlags;
this.eventTypes = eventTypes;

@@ -13,2 +13,5 @@ }

};
Workspace.prototype.getFeatureFlagOrNull = function (featureKey) {
return this.featureFlags.get(featureKey);
};
Workspace.prototype.getEventTypeOrNull = function (eventKey) {

@@ -31,8 +34,8 @@ var eventType = this.eventTypes.get(eventKey);

}, new Map());
var running = dto.experiments.reduce(function (m, it) {
m.set(it.key, experimentDtoToExperiment.call(it, buckets.get(it.bucketId)));
var experiment = dto.experiments.reduce(function (m, it) {
m.set(it.key, experimentDtoToExperiment.call(it, "AB_TEST", buckets.get(it.bucketId)));
return m;
}, new Map());
var completed = dto.completedExperiments.reduce(function (m, it) {
m.set(it.experimentKey, completedExperimentToExperiment.call(it));
var featureFlags = dto.featureFlags.reduce(function (m, it) {
m.set(it.key, experimentDtoToExperiment.call(it, "FEATURE_FLAG", buckets.get(it.bucketId)));
return m;

@@ -44,3 +47,3 @@ }, new Map());

}, new Map());
return new Workspace(new Map(tslib_1.__spread(running, completed)), eventTypes);
return new Workspace(new Map(experiment), new Map(featureFlags), eventTypes);
};

@@ -50,3 +53,3 @@ return Workspace;

exports.default = Workspace;
function experimentDtoToExperiment(bucket) {
function experimentDtoToExperiment(type, bucket) {
var variations = this.variations.reduce(function (m, it) {

@@ -56,10 +59,19 @@ m.set(it.id, new model_1.Variation(it.id, it.key, it.status === "DROPPED"));

}, new Map());
return new model_1.Experiment.Running(this.id, this.key, bucket, variations, new model_1.UserOverrides(this.execution.userOverrides.reduce(function (m, it) {
var overrides = new model_1.UserOverrides(this.execution.userOverrides.reduce(function (m, it) {
m.set(it.userId, variations.get(it.variationId));
return m;
}, new Map())));
}, new Map()));
switch (this.execution.status) {
case "READY":
return new model_1.Experiment.Draft(this.id, this.key, type, variations, overrides);
case "RUNNING":
return new model_1.Experiment.Running(this.id, this.key, type, bucket, variations, overrides);
case "PAUSED":
return new model_1.Experiment.Paused(this.id, this.key, type, variations, overrides);
case "STOPPED":
return new model_1.Experiment.Completed(this.id, this.key, type, variations, overrides, this.winnerVariationId);
default:
return undefined;
}
}
function completedExperimentToExperiment() {
return new model_1.Experiment.Completed(this.experimentId, this.experimentKey, this.winnerVariationKey);
}
//# sourceMappingURL=Workspace.js.map
{
"name": "@hackler/sdk-core",
"version": "1.2.0",
"version": "2.0.0-rc.1",
"description": "JavaScript SDK-core",

@@ -29,2 +29,4 @@ "author": {

"clean": "rm -rf ./lib && rm -rf tsconfig.tsbuildinfo",
"test": "jest --detectOpenHandles --forceExit",
"test:watch": "jest --watch",
"compile": "tsc",

@@ -55,6 +57,2 @@ "watch": "tsc --watch",

},
"devDependencies": {
"@types/uuid": "^8.3.0",
"typescript": "4.0.5"
},
"gitHead": "959780544e27e38fc3d41b494ebea49cab0ef4bb",

@@ -65,3 +63,17 @@ "dependencies": {

"uuid": "^8.3.2"
},
"devDependencies": {
"@types/jest": "^26.0.24",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"@typescript-eslint/parser": "^3.6.0",
"eslint": "^7.4.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"jest": "^27.0.6",
"prettier": "^2.0.5",
"ts-jest": "^27.0.4",
"ts-node": "^10.1.0",
"typescript": "^4.0.5"
}
}

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

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

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

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

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