kameleoon-client-javascript
Advanced tools
Comparing version 1.0.9 to 2.0.0
@@ -1,15 +0,11 @@ | ||
import { ConfigurationInterface, ConfigurationExperimentsInterface, ConfigurationFeatureFlagsInterface, AutomationExperimentInterface, AutomationFeatureFlagInterface, ConfigurationSettings } from '../interfaces/interfaces'; | ||
import { ConfigurationInterface, ConfigurationCampaignInterface, ConfigurationFeatureFlagsV2Interface, ConfigurationSettings, ConfigurationAPIInterface } from "../interfaces/interfaces"; | ||
declare class Configuration implements ConfigurationInterface { | ||
settings: ConfigurationSettings; | ||
updateTime: number; | ||
experiments: ConfigurationExperimentsInterface; | ||
featureFlags: ConfigurationFeatureFlagsInterface; | ||
experiments: ConfigurationCampaignInterface; | ||
featureFlags: ConfigurationCampaignInterface; | ||
featureFlagsV2: ConfigurationFeatureFlagsV2Interface; | ||
configuration: any; | ||
constructor(siteCode: string, actions: { | ||
configuration: ConfigurationSettings; | ||
experiments: AutomationExperimentInterface[]; | ||
featureFlags: AutomationFeatureFlagInterface[]; | ||
updateTime: number; | ||
}); | ||
constructor(configuration: ConfigurationAPIInterface); | ||
} | ||
export default Configuration; |
@@ -8,17 +8,24 @@ "use strict"; | ||
var featureFlag_1 = __importDefault(require("./featureFlag")); | ||
var featureFlagV2_1 = require("./featureFlagV2"); | ||
var Configuration = /** @class */ (function () { | ||
function Configuration(siteCode, actions) { | ||
this.updateTime = actions.updateTime ? actions.updateTime : new Date().getTime(); | ||
this.configuration = actions; | ||
this.settings = actions.configuration; | ||
this.experiments = actions.experiments.filter(function (experiment) { return experiment.siteCode == siteCode; }) | ||
.reduce(function (obj, experiment) { | ||
function Configuration(configuration) { | ||
this.updateTime = new Date().getTime(); | ||
this.settings = configuration.configuration; | ||
this.experiments = configuration.experiments.reduce(function (obj, experiment) { | ||
obj[experiment.id] = new experiment_1.default(experiment); | ||
return obj; | ||
}, {}); | ||
this.featureFlags = actions.featureFlags.filter(function (ff) { return ff.siteCode == siteCode; }) | ||
.reduce(function (obj, ff) { | ||
this.featureFlags = configuration.featureFlags.reduce(function (obj, ff) { | ||
obj[ff.id] = new featureFlag_1.default(ff); | ||
return obj; | ||
}, {}); | ||
if (configuration.featureFlagConfigurations) { | ||
this.featureFlagsV2 = configuration.featureFlagConfigurations.reduce(function (obj, ff) { | ||
obj[ff.id] = new featureFlagV2_1.FeatureFlagV2(ff); | ||
return obj; | ||
}, {}); | ||
} | ||
else { | ||
this.featureFlagsV2 = {}; | ||
} | ||
} | ||
@@ -25,0 +32,0 @@ return Configuration; |
import TargetingSegment from "../targeting/targetingSegment"; | ||
import Variation from "./variation"; | ||
import { AutomationExperimentInterface, SiteEnabledInterface } from '../interfaces/interfaces'; | ||
import { ExperimentInterface, SiteEnabledInterface } from "../interfaces/interfaces"; | ||
declare class Experiment implements SiteEnabledInterface { | ||
@@ -8,7 +8,6 @@ variationConfigurations: { | ||
}; | ||
forceTargeting?: boolean; | ||
targetingSegment?: TargetingSegment; | ||
siteEnabled: boolean; | ||
constructor(experiment: AutomationExperimentInterface); | ||
constructor(experiment: ExperimentInterface); | ||
} | ||
export default Experiment; |
@@ -36,3 +36,3 @@ "use strict"; | ||
respoolTime: respoolTimeValue, | ||
customJson: customJson | ||
customJson: customJson, | ||
}); | ||
@@ -39,0 +39,0 @@ }); |
import TargetingSegment from "../targeting/targetingSegment"; | ||
import Variation from "./variation"; | ||
import { AutomationFeatureFlagInterface, SiteEnabledInterface } from '../interfaces/interfaces'; | ||
import { FeatureFlagInterface, SiteEnabledInterface } from "../interfaces/interfaces"; | ||
declare class FeatureFlag implements SiteEnabledInterface { | ||
static readonly STATUS_ACTIVE = "ACTIVE"; | ||
static readonly FEATURE_STATUS_DEACTIVATED = "DEACTIVATED"; | ||
id: string; | ||
status: string; | ||
@@ -12,3 +13,2 @@ featureStatus: string; | ||
}; | ||
forceTargeting?: boolean; | ||
targetingSegment?: TargetingSegment; | ||
@@ -21,5 +21,5 @@ identificationKey: string; | ||
siteEnabled: boolean; | ||
constructor(featureFlag: AutomationFeatureFlagInterface); | ||
constructor(featureFlag: FeatureFlagInterface); | ||
isScheduleActive: () => boolean; | ||
} | ||
export default FeatureFlag; |
@@ -15,3 +15,4 @@ "use strict"; | ||
var currentStatus = _this.status == FeatureFlag.STATUS_ACTIVE; | ||
if (_this.featureStatus == FeatureFlag.FEATURE_STATUS_DEACTIVATED || _this.schedules.length == 0) { | ||
if (_this.featureStatus == FeatureFlag.FEATURE_STATUS_DEACTIVATED || | ||
_this.schedules.length == 0) { | ||
return currentStatus; | ||
@@ -21,4 +22,7 @@ } | ||
// need to find if currentTime is in any period -> active or not -> not activate | ||
return _this.schedules.filter(function (schedule) { return schedule.dateStart < currentTime && currentTime < schedule.dateEnd; }).length > 0; | ||
return (_this.schedules.filter(function (schedule) { | ||
return schedule.dateStart < currentTime && currentTime < schedule.dateEnd; | ||
}).length > 0); | ||
}; | ||
this.id = featureFlag.id; | ||
this.variationConfigurations = {}; | ||
@@ -52,3 +56,3 @@ this.identificationKey = featureFlag.identificationKey; | ||
respoolTime: respoolTimeValue, | ||
customJson: customJson | ||
customJson: customJson, | ||
}); | ||
@@ -60,3 +64,5 @@ }); | ||
_this.schedules.push({ | ||
dateStart: schedule.dateStart ? Date.parse(schedule.dateStart) : -Infinity, | ||
dateStart: schedule.dateStart | ||
? Date.parse(schedule.dateStart) | ||
: -Infinity, | ||
dateEnd: schedule.dateEnd ? Date.parse(schedule.dateEnd) : Infinity, | ||
@@ -84,3 +90,3 @@ }); | ||
respoolTime: respoolTimeValue, | ||
customJson: customJson | ||
customJson: customJson, | ||
}); | ||
@@ -87,0 +93,0 @@ } |
import { CustomJsonType } from "../types"; | ||
export interface VariationInterface { | ||
id: string; | ||
deviation: number; | ||
respoolTime?: number; | ||
customJson?: any; | ||
readonly id: string; | ||
readonly deviation: number; | ||
readonly respoolTime?: number; | ||
readonly customJson?: any; | ||
} | ||
@@ -8,0 +8,0 @@ declare class Variation implements VariationInterface { |
@@ -1,2 +0,2 @@ | ||
import { DataInterface } from './interfaces/interfaces'; | ||
import { DataInterface } from "./interfaces/interfaces"; | ||
export declare class CustomData implements DataInterface { | ||
@@ -26,5 +26,5 @@ id: number; | ||
title: string; | ||
referrer?: number; | ||
referrers: Array<number>; | ||
nonce: string; | ||
constructor(url: string, title: string, referrer?: number); | ||
constructor(url: string, title: string, referrers: Array<number>); | ||
obtainFullPostTextLine: () => string; | ||
@@ -46,2 +46,7 @@ } | ||
} | ||
export declare class UserAgent implements DataInterface { | ||
value: string; | ||
constructor(value: string); | ||
obtainFullPostTextLine: () => string; | ||
} | ||
export declare enum DeviceType { | ||
@@ -65,2 +70,3 @@ Phone = "PHONE", | ||
BrowserType: typeof BrowserType; | ||
UserAgent: typeof UserAgent; | ||
PageView: typeof PageView; | ||
@@ -67,0 +73,0 @@ Device: typeof Device; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DeviceType = exports.Device = exports.Conversion = exports.PageView = exports.BrowserType = exports.Browser = exports.CustomData = void 0; | ||
exports.DeviceType = exports.UserAgent = exports.Device = exports.Conversion = exports.PageView = exports.BrowserType = exports.Browser = exports.CustomData = void 0; | ||
var nonce_1 = require("./nonce"); | ||
@@ -10,3 +10,8 @@ var CustomData = /** @class */ (function () { | ||
var encodedValue = encodeURIComponent(JSON.stringify([[_this.value, 1]])); | ||
return "eventType=customData&index=" + _this.id + "&valueToCount=" + encodedValue + "&overwrite=true&nonce=" + _this.nonce; | ||
return ("eventType=customData&index=" + | ||
_this.id + | ||
"&valueToCount=" + | ||
encodedValue + | ||
"&overwrite=true&nonce=" + | ||
_this.nonce); | ||
}; | ||
@@ -27,3 +32,6 @@ this.id = id; | ||
} | ||
return "eventType=staticData&browser=" + _this.browser + "&nonce=" + _this.nonce; | ||
return ("eventType=staticData&browserIndex=" + | ||
_this.browser + | ||
"&nonce=" + | ||
_this.nonce); | ||
}; | ||
@@ -46,10 +54,19 @@ this.browser = browser; | ||
var PageView = /** @class */ (function () { | ||
function PageView(url, title, referrer) { | ||
function PageView(url, title, referrers) { | ||
var _this = this; | ||
this.obtainFullPostTextLine = function () { | ||
return "eventType=page&href=" + encodeURIComponent(_this.url) + "&title=" + _this.title + "&keyPages=[]" + (_this.referrer == null ? "" : "&referrers=[" + _this.referrer + "]") + "&nonce=" + _this.nonce; | ||
var _a, _b; | ||
return ("eventType=page&href=" + | ||
encodeURIComponent(_this.url) + | ||
"&title=" + | ||
_this.title + | ||
(((_b = (_a = _this.referrers) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 | ||
? "&referrersIndices=[" + _this.referrers + "]" | ||
: "") + | ||
"&nonce=" + | ||
_this.nonce); | ||
}; | ||
this.url = url; | ||
this.title = title; | ||
this.referrer = referrer; | ||
this.referrers = referrers; | ||
this.nonce = (0, nonce_1.obtainNonce)(); | ||
@@ -66,3 +83,10 @@ } | ||
this.obtainFullPostTextLine = function () { | ||
return "eventType=conversion&goalId=" + _this.goalId.toString() + "&revenue=" + _this.revenue.toString() + "&negative=" + _this.negative.toString() + "&nonce=" + _this.nonce; | ||
return ("eventType=conversion&goalId=" + | ||
_this.goalId.toString() + | ||
"&revenue=" + | ||
_this.revenue.toString() + | ||
"&negative=" + | ||
_this.negative.toString() + | ||
"&nonce=" + | ||
_this.nonce); | ||
}; | ||
@@ -81,3 +105,3 @@ this.goalId = goalId; | ||
this.obtainFullPostTextLine = function () { | ||
return "eventType=staticData&deviceType=" + _this.device + "&nonce=" + _this.nonce; | ||
return ("eventType=staticData&deviceType=" + _this.device + "&nonce=" + _this.nonce); | ||
}; | ||
@@ -90,2 +114,12 @@ this.device = device; | ||
exports.Device = Device; | ||
var UserAgent = /** @class */ (function () { | ||
function UserAgent(value) { | ||
this.obtainFullPostTextLine = function () { | ||
return ""; | ||
}; | ||
this.value = value; | ||
} | ||
return UserAgent; | ||
}()); | ||
exports.UserAgent = UserAgent; | ||
var DeviceType; | ||
@@ -98,3 +132,10 @@ (function (DeviceType) { | ||
exports.default = { | ||
browsers: { "CHROME": 0, "INTERNET_EXPLORER": 1, "FIREFOX": 2, "SAFARI": 3, "OPERA": 4, "OTHER": 5 }, | ||
browsers: { | ||
CHROME: 0, | ||
INTERNET_EXPLORER: 1, | ||
FIREFOX: 2, | ||
SAFARI: 3, | ||
OPERA: 4, | ||
OTHER: 5, | ||
}, | ||
Conversion: Conversion, | ||
@@ -104,5 +145,6 @@ CustomData: CustomData, | ||
BrowserType: BrowserType, | ||
UserAgent: UserAgent, | ||
PageView: PageView, | ||
Device: Device, | ||
DeviceType: DeviceType | ||
DeviceType: DeviceType, | ||
}; |
/// <reference types="node" /> | ||
import Experiment from '../configurations/experiment'; | ||
import FeatureFlag from '../configurations/featureFlag'; | ||
export interface SiteEnabledInterface { | ||
@@ -18,6 +16,13 @@ siteEnabled: boolean; | ||
} | ||
export interface AutomationExperimentInterface extends CampaignInterface { | ||
export interface ConfigurationAPIInterface { | ||
configuration: ConfigurationSettings; | ||
experiments: ExperimentInterface[]; | ||
featureFlags: FeatureFlagInterface[]; | ||
featureFlagConfigurations: FeatureFlagV2Interface[]; | ||
updateTime: number; | ||
} | ||
export interface ExperimentInterface extends CampaignInterface { | ||
status: "ACTIVE"; | ||
} | ||
export interface AutomationFeatureFlagInterface extends CampaignInterface { | ||
export interface FeatureFlagInterface extends CampaignInterface { | ||
featureStatus: string; | ||
@@ -31,2 +36,36 @@ identificationKey: string; | ||
} | ||
export interface FeatureFlagV2Interface { | ||
id: number; | ||
featureKey: string; | ||
variations: VariationInterface[]; | ||
defaultVariationKey: string; | ||
rules: RuleInterface[]; | ||
exposition: number; | ||
} | ||
export interface VariationInterface { | ||
id: number; | ||
key: string; | ||
variables: VariableInterface[]; | ||
} | ||
export interface VariableInterface { | ||
key: string; | ||
type: string; | ||
value: string; | ||
} | ||
export interface SegmentInterface { | ||
conditionsData: ConditionsInterface; | ||
} | ||
export interface RuleInterface { | ||
order: number; | ||
type: string; | ||
exposition: number; | ||
experimentId?: number; | ||
segment?: SegmentInterface; | ||
variationByExposition: VariationByExpositionInterface[]; | ||
} | ||
export interface VariationByExpositionInterface { | ||
variationId: number; | ||
variationKey: string; | ||
exposition: number; | ||
} | ||
export interface AutomationVariationsInterface { | ||
@@ -55,10 +94,11 @@ id: string; | ||
updateTime: number; | ||
experiments: ConfigurationExperimentsInterface; | ||
featureFlags: ConfigurationFeatureFlagsInterface; | ||
experiments: ConfigurationCampaignInterface; | ||
featureFlags: ConfigurationCampaignInterface; | ||
featureFlagsV2: ConfigurationFeatureFlagsV2Interface; | ||
} | ||
export interface ConfigurationExperimentsInterface { | ||
[id: string]: Experiment; | ||
export interface ConfigurationCampaignInterface { | ||
[id: string]: any; | ||
} | ||
export interface ConfigurationFeatureFlagsInterface { | ||
[id: string]: FeatureFlag; | ||
export interface ConfigurationFeatureFlagsV2Interface { | ||
[id: number]: any; | ||
} | ||
@@ -65,0 +105,0 @@ export interface ConfigurationSettings { |
@@ -1,2 +0,2 @@ | ||
import Configuration from './configurations/configuration'; | ||
import Configuration from "./configurations/configuration"; | ||
import Data from "./data"; | ||
@@ -12,4 +12,5 @@ import TargetingData from "./targeting/targetingData"; | ||
import CredentialsNotFound from "./exceptions/credentialsNotFound"; | ||
import { CallbackInterface, DataInterface, SDKConfiguration } from './interfaces/interfaces'; | ||
import { CallbackInterface, DataInterface, SDKConfiguration } from "./interfaces/interfaces"; | ||
declare class KameleoonClient { | ||
static readonly DEFAULT_TIMEOUT_MILLISECONDS: number; | ||
static readonly VISITOR_CODE_MAX_LENGTH = 255; | ||
@@ -30,2 +31,3 @@ configurations?: Configuration; | ||
environment: string | null; | ||
private userAgentData; | ||
private realTimeConfigurationService; | ||
@@ -41,5 +43,17 @@ private handlerUpdateConfiguration; | ||
triggerExperiment: (visitorCode: string, experimentId: number) => number; | ||
activateFeature: (visitorCode: string, featureIdOrName: number | string) => boolean; | ||
/** | ||
* @deprecated Use getFeatureVariationKey instead. | ||
*/ | ||
activateFeature: (visitorCode: string, featureIdOrName: string) => boolean; | ||
getFeatureVariationKey: (visitorCode: string, featureKey: string) => string; | ||
private _getFeatureVariationKey; | ||
getFeatureVariable: (visitorCode: string, featureKey: string, variableName: string) => string | number | boolean | object; | ||
private obtainHashDoubleFeatureFlagV2; | ||
private calculateHash; | ||
generateRandomString: () => string; | ||
obtainVisitorCode: (domain: string, defaultVisitorCode?: string | undefined) => string; | ||
private _findFeature; | ||
private _findFeatureV2; | ||
private featureFlagInfoForException; | ||
getVisitorCode: (domain: string, defaultVisitorCode?: string | undefined) => string; | ||
private sendTrackingRequest; | ||
obtainHashDouble: (containerId: number, visitorCode: string, xpConf: Experiment | FeatureFlag) => number; | ||
@@ -57,36 +71,46 @@ private getCommonSSXParameters; | ||
addData: (visitorCode: string, ...data: DataInterface[]) => void; | ||
checkTargeting: (visitorCode: string, campaignId: number, isFF: boolean) => boolean | null; | ||
private addUserAgent; | ||
private getUserAgent; | ||
private checkTargeting; | ||
private getConditionData; | ||
obtainVariationAssociatedData: (variationId: number) => Record<string | number | symbol, string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | (string | number | boolean | { | ||
[x: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any)[])[])[])[])[])[])[])[])[])[])[]; | ||
} | any)[])[])[])[])[])[])[])[])[])[])[]>; | ||
obtainFeatureVariable: (featureIdOrName: number | string, variable: string) => any; | ||
getVariationAssociatedData: (variationId: number) => any; | ||
/** | ||
* @deprecated Use getVariationAssociatedData instead. | ||
*/ | ||
obtainVariationAssociatedData: (variationId: number) => any; | ||
/** | ||
* @deprecated Use getFeatureVariable instead. | ||
*/ | ||
obtainFeatureVariable: (featureIdOrName: number | string, variable: string) => number | string | boolean | object; | ||
getFeatureAllVariables: (featureIdOrName: number | string) => Record<string, number | string | boolean | object>; | ||
/** | ||
* @deprecated Use getFeatureAllVariables instead. | ||
*/ | ||
obtainFeatureAllVariables: (featureIdOrName: number | string) => Record<string, number | string | boolean | object>; | ||
retrieveDataFromRemoteSource: (key: string) => Promise<any>; | ||
private _parseJsonValue; | ||
private _parseVariableValue; | ||
getExperimentList: () => number[]; | ||
/** | ||
* @deprecated Use getExperimentList instead. | ||
*/ | ||
obtainExperimentList: () => number[]; | ||
getExperimentListForVisitorCode: (visitorCode: string, onlyActive?: boolean) => any[]; | ||
/** | ||
* @deprecated Use getExperimentListForVisitorCode instead. | ||
*/ | ||
obtainExperimentListForVisitorCode: (visitorCode: string, onlyActive?: boolean) => any[]; | ||
getFeatureList: () => any[]; | ||
/** | ||
* @deprecated Use getFeatureList instead. | ||
*/ | ||
obtainFeatureList: () => any[]; | ||
getFeatureListForVisitorCode: (visitorCode: string, onlyActive?: boolean) => any[]; | ||
/** | ||
* @deprecated Use getFeatureListForVisitorCode instead. | ||
*/ | ||
obtainFeatureListForVisitorCode: (visitorCode: string, onlyActive?: boolean) => any[]; | ||
private _getListForVisitorCode; | ||
private saveConfiguration; | ||
private validateVisitorCode; | ||
private checkSiteEnabled; | ||
private checkFeatureKeyOrId; | ||
private getAndClearUnsentData; | ||
@@ -93,0 +117,0 @@ onUpdateConfiguration: (handler: () => void) => void; |
@@ -63,3 +63,3 @@ "use strict"; | ||
var configuration_1 = __importDefault(require("./configurations/configuration")); | ||
var data_1 = __importDefault(require("./data")); | ||
var data_1 = __importStar(require("./data")); | ||
exports.KameleoonData = data_1.default; | ||
@@ -81,2 +81,3 @@ var kameleoonUtils_1 = __importStar(require("./kameleoonUtils")); | ||
var targetingEngine_1 = require("./targeting/targetingEngine"); | ||
var types_1 = require("./configurations/types"); | ||
var KameleoonClient = /** @class */ (function () { | ||
@@ -92,2 +93,3 @@ function KameleoonClient(siteCode, configuration) { | ||
this.environment = null; | ||
this.userAgentData = {}; | ||
this.realTimeConfigurationService = null; | ||
@@ -110,3 +112,3 @@ this.handlerUpdateConfiguration = null; | ||
kameleoonTargetingData: {}, | ||
kameleoonConfiguration: {} | ||
kameleoonConfiguration: {}, | ||
}; | ||
@@ -126,3 +128,4 @@ } | ||
var needUpdate = false; | ||
if (!savedConfiguration || timeStamp != null) { // timeStamp != null means update by SSE event and requires force update | ||
if (!savedConfiguration || timeStamp != null) { | ||
// timeStamp != null means update by SSE event and requires force update | ||
needUpdate = true; | ||
@@ -132,10 +135,8 @@ } | ||
try { | ||
var parsedConfiguration = new configuration_1.default(_this.siteCode, { | ||
configuration: savedConfiguration.configuration, | ||
experiments: savedConfiguration.experiments, | ||
featureFlags: savedConfiguration.featureFlags, | ||
updateTime: savedConfiguration.updateTime | ||
}); | ||
if (parsedConfiguration.updateTime < new Date().getTime() - (_this.minutesBetweenConfigurationUpdate * 1000 * 60) || //refresh by polling interval | ||
parsedConfiguration.settings.realTimeUpdate) { //streaming initial refresh, need to update to recent version of configuration | ||
var parsedConfiguration = new configuration_1.default(savedConfiguration); | ||
if (parsedConfiguration.updateTime < | ||
new Date().getTime() - | ||
_this.minutesBetweenConfigurationUpdate * 1000 * 60 || //refresh by polling interval | ||
parsedConfiguration.settings.realTimeUpdate) { | ||
//streaming initial refresh, need to update to recent version of configuration | ||
needUpdate = true; | ||
@@ -153,8 +154,13 @@ } | ||
var siteCodeStringUrl = "mobile?siteCode=".concat(_this.siteCode); | ||
var environmentStringUrl = ((_a = _this.environment) === null || _a === void 0 ? void 0 : _a.length) ? "&environment=".concat(_this.environment) : ''; | ||
var environmentStringUrl = ((_a = _this.environment) === null || _a === void 0 ? void 0 : _a.length) | ||
? "&environment=".concat(_this.environment) | ||
: ""; | ||
var timeStampStringUrl = timeStamp ? "&ts=".concat(timeStamp) : ""; | ||
var configurationUrl = constants_1.CONFIGURATION_URL + siteCodeStringUrl + environmentStringUrl + timeStampStringUrl; | ||
var configurationUrl = constants_1.CONFIGURATION_URL + | ||
siteCodeStringUrl + | ||
environmentStringUrl + | ||
timeStampStringUrl; | ||
kameleoonUtils_1.default.doRequest(configurationUrl, kameleoonUtils_1.HttpMethod.GET, null, function (response) { | ||
try { | ||
_this.configurations = new configuration_1.default(_this.siteCode, JSON.parse(response)); | ||
_this.configurations = new configuration_1.default(JSON.parse(response)); | ||
_this.ready = true; | ||
@@ -186,3 +192,3 @@ _this.clearCallbacks(true); | ||
_this.clearCallbacks(false, errorCallback); | ||
}, timeout) | ||
}, timeout), | ||
}); | ||
@@ -217,3 +223,3 @@ } | ||
var body = _this.getAndClearUnsentData(visitorCode); | ||
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL + _this.getDataTrackingURL(visitorCode), kameleoonUtils_1.HttpMethod.POST, body, null); | ||
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL + _this.getDataTrackingURL(visitorCode), kameleoonUtils_1.HttpMethod.POST, body, null, true, _this.getUserAgent(visitorCode)); | ||
} | ||
@@ -229,7 +235,7 @@ else { | ||
_this.checkSiteEnabled(xpConf); | ||
if (_this.checkTargeting(visitorCode, experimentId, false)) { | ||
if (_this.checkTargeting(visitorCode, experimentId, xpConf)) { | ||
var variationId = 0; | ||
var noneVariation = true; | ||
var savedVariationId = _this.variationStorage.getVariationId(visitorCode, experimentId); | ||
if (savedVariationId) { | ||
if (savedVariationId !== null) { | ||
variationId = savedVariationId; | ||
@@ -239,3 +245,3 @@ noneVariation = false; | ||
else { | ||
if (xpConf) { | ||
if (xpConf !== null) { | ||
var hashDouble = _this.obtainHashDouble(experimentId, visitorCode, xpConf); | ||
@@ -254,3 +260,4 @@ var total = 0.0; | ||
var body = _this.getAndClearUnsentData(visitorCode); | ||
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL + _this.getExperimentRegisterURL(visitorCode, experimentId, variationId, noneVariation), kameleoonUtils_1.HttpMethod.POST, body); | ||
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL + | ||
_this.getExperimentRegisterURL(visitorCode, experimentId, variationId, noneVariation), kameleoonUtils_1.HttpMethod.POST, body, undefined, true, _this.getUserAgent(visitorCode)); | ||
} | ||
@@ -270,17 +277,12 @@ else { | ||
}; | ||
/** | ||
* @deprecated Use getFeatureVariationKey instead. | ||
*/ | ||
this.activateFeature = function (visitorCode, featureIdOrName) { | ||
var _a, _b; | ||
_this.checkFeatureKeyOrId(featureIdOrName); | ||
var _a; | ||
_this.validateVisitorCode(visitorCode); | ||
var featureFlag = null; | ||
var featureId = -1; | ||
for (var key in (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags) { | ||
var ff = (_b = _this.configurations) === null || _b === void 0 ? void 0 : _b.featureFlags[key]; | ||
if (key == featureIdOrName || (ff === null || ff === void 0 ? void 0 : ff.identificationKey) == featureIdOrName) { | ||
featureId = parseInt(key); | ||
featureFlag = ff; | ||
} | ||
} | ||
var featureFlag = _this._findFeature(featureIdOrName); | ||
var featureId = parseInt((_a = featureFlag === null || featureFlag === void 0 ? void 0 : featureFlag.id) !== null && _a !== void 0 ? _a : ""); | ||
_this.checkSiteEnabled(featureFlag); | ||
if (_this.checkTargeting(visitorCode, featureId, true)) { | ||
if (_this.checkTargeting(visitorCode, featureId, featureFlag)) { | ||
if (featureFlag && featureId) { | ||
@@ -303,3 +305,4 @@ var result = false; | ||
var body = _this.getAndClearUnsentData(visitorCode); | ||
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL + _this.getExperimentRegisterURL(visitorCode, featureId, variationId, noneVariation), kameleoonUtils_1.HttpMethod.POST, body); | ||
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL + | ||
_this.getExperimentRegisterURL(visitorCode, featureId, variationId, noneVariation), kameleoonUtils_1.HttpMethod.POST, body, undefined, true, _this.getUserAgent(visitorCode)); | ||
result = variationId != 0; | ||
@@ -317,2 +320,48 @@ } | ||
}; | ||
this.getFeatureVariationKey = function (visitorCode, featureKey) { | ||
var _a = _this._getFeatureVariationKey(visitorCode, featureKey), variationKey = _a[0], _ = _a[1]; | ||
return variationKey; | ||
}; | ||
this._getFeatureVariationKey = function (visitorCode, featureKey) { | ||
_this.validateVisitorCode(visitorCode); // validate that visitor code is acceptable else throw VisitorCodeNotValid exception | ||
var featureFlag = _this._findFeatureV2(featureKey); //find feature flag else throw FeatureConfigurationNotFoundexception | ||
if (featureFlag.rules.length > 0) { | ||
// no rules -> return defaultVariationKey | ||
var hashRule = _this.obtainHashDoubleFeatureFlagV2(visitorCode, featureFlag.id); //uses for rule exposition | ||
var hashVariation = _this.obtainHashDoubleFeatureFlagV2(visitorCode, featureFlag.id, "variation"); //uses for variation's expositions | ||
for (var _i = 0, _a = featureFlag.rules; _i < _a.length; _i++) { | ||
var rule = _a[_i]; | ||
if (_this.checkTargeting(visitorCode, featureFlag.id, rule)) { | ||
//check if visitor is targeted for rule, else next rule | ||
if (hashRule < rule.exposition) { | ||
//check main expostion for rule with hashRule | ||
var variationKey = rule.getVariationKey(hashVariation); // get variation key with new hashVariation | ||
if (variationKey != null) { | ||
//check if variation for experiment found, for targeted rule will be always true | ||
if (rule.type === types_1.RuleType.Experimentation) { | ||
//send tracking request if rule is type of EXPERIMENTATION | ||
_this.sendTrackingRequest(visitorCode, variationKey, rule); | ||
} | ||
return [variationKey, featureFlag]; | ||
} | ||
} | ||
else if (rule.type === types_1.RuleType.TargetedDelivery) { | ||
//if visitor is targeted for targeted rule then break cycle -> return default | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return [featureFlag.defaultVariationKey, featureFlag]; | ||
}; | ||
this.getFeatureVariable = function (visitorCode, featureKey, variableName) { | ||
var _a; | ||
var _b = _this._getFeatureVariationKey(visitorCode, featureKey), variationKey = _b[0], featureFlag = _b[1]; | ||
var variable = (_a = featureFlag | ||
.getVariationByKey(variationKey)) === null || _a === void 0 ? void 0 : _a.getVariableByKey(variableName); | ||
return _this._parseVariableValue(variable); | ||
}; | ||
this.obtainHashDoubleFeatureFlagV2 = function (visitorCode, containerId, suffix) { | ||
return _this.calculateHash(visitorCode + containerId + (suffix !== null && suffix !== void 0 ? suffix : "")); | ||
}; | ||
this.generateRandomString = function () { | ||
@@ -328,3 +377,6 @@ var alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; | ||
}; | ||
this.obtainVisitorCode = function (domain, defaultVisitorCode) { | ||
this.featureFlagInfoForException = function (featureIdOrName) { | ||
return " Feature Flag Name(Id): ".concat(featureIdOrName); | ||
}; | ||
this.getVisitorCode = function (domain, defaultVisitorCode) { | ||
var value; | ||
@@ -345,5 +397,19 @@ var name = "kameleoonVisitorCode"; | ||
value = defaultVisitorCode || _this.generateRandomString(); | ||
document.cookie = 'kameleoonVisitorCode=' + value + '; Max-Age=32832000; Path=/; Domain=' + domain; | ||
document.cookie = | ||
"kameleoonVisitorCode=" + | ||
value + | ||
"; Max-Age=32832000; Path=/; Domain=" + | ||
domain; | ||
return value; | ||
}; | ||
this.sendTrackingRequest = function (visitorCode, variationKey, rule) { | ||
var body = _this.getAndClearUnsentData(visitorCode); | ||
if (rule.experimentId) { | ||
var trackingURL = _this.getExperimentRegisterURL(visitorCode, rule.experimentId, rule.getVariationIdByKey(variationKey), false); | ||
kameleoonUtils_1.default.doRequest(trackingURL, kameleoonUtils_1.HttpMethod.POST, body, null, true, _this.getUserAgent(visitorCode)); | ||
} | ||
else { | ||
console.log("An attempt to send a request with null experimentId was blocked."); | ||
} | ||
}; | ||
this.obtainHashDouble = function (containerId, visitorCode, xpConf) { | ||
@@ -362,3 +428,8 @@ var joinedRespoolTime = ""; | ||
this.getCommonSSXParameters = function (visitorCode) { | ||
return "&nonce=" + (0, nonce_1.obtainNonce)() + "&siteCode=" + _this.siteCode + "&visitorCode=" + visitorCode; | ||
return ("&nonce=" + | ||
(0, nonce_1.obtainNonce)() + | ||
"&siteCode=" + | ||
_this.siteCode + | ||
"&visitorCode=" + | ||
visitorCode); | ||
}; | ||
@@ -375,3 +446,6 @@ this.getDataTrackingURL = function (visitorCode) { | ||
this.getExperimentRegisterURL = function (visitorCode, experimentId, variationId, noneVariation) { | ||
var baseURL = "experimentTracking?" + _this.getCommonSSXParameters(visitorCode) + "&experimentId=" + experimentId; | ||
var baseURL = "experimentTracking?" + | ||
_this.getCommonSSXParameters(visitorCode) + | ||
"&experimentId=" + | ||
experimentId; | ||
if (variationId == null) { | ||
@@ -381,3 +455,6 @@ return baseURL; | ||
else { | ||
return baseURL + "&variationId=" + variationId + (noneVariation ? "&noneVariation=true" : ""); | ||
return (baseURL + | ||
"&variationId=" + | ||
variationId + | ||
(noneVariation ? "&noneVariation=true" : "")); | ||
} | ||
@@ -424,39 +501,34 @@ }; | ||
data.forEach(function (d) { | ||
listData.push(d); | ||
if (targetingDataList.length < _this.targetingDataNumberEntriesAuthorized) { | ||
targetingDataList.push(new targetingData_1.default(new Date().getTime(), d)); | ||
if (d instanceof data_1.UserAgent) { | ||
_this.addUserAgent(visitorCode, d); | ||
} | ||
else { | ||
targetingDataList.splice(0, 1); | ||
targetingDataList.push(new targetingData_1.default(new Date().getTime(), d)); | ||
listData.push(d); | ||
if (targetingDataList.length < _this.targetingDataNumberEntriesAuthorized) { | ||
targetingDataList.push(new targetingData_1.default(new Date().getTime(), d)); | ||
} | ||
else { | ||
targetingDataList.splice(0, 1); | ||
targetingDataList.push(new targetingData_1.default(new Date().getTime(), d)); | ||
} | ||
} | ||
_this.saveConfiguration(); | ||
}); | ||
}; | ||
this.addUserAgent = function (visitorCode, userAgent) { | ||
_this.userAgentData[visitorCode] = userAgent; | ||
}; | ||
this.getUserAgent = function (visitorCode) { | ||
return _this.userAgentData[visitorCode]; | ||
}; | ||
// Targeting Engine | ||
// check targeting | ||
this.checkTargeting = function (visitorCode, campaignId, isFF) { | ||
var _a, _b; | ||
this.checkTargeting = function (visitorCode, campaignId, targetingObject) { | ||
var targeting = true; | ||
var xpConf = null; | ||
// performing targeting | ||
if (isFF) { | ||
xpConf = (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags[campaignId]; | ||
} | ||
else { | ||
xpConf = (_b = _this.configurations) === null || _b === void 0 ? void 0 : _b.experiments[campaignId]; | ||
} | ||
if (xpConf != null) { | ||
if (true == xpConf.forceTargeting) { | ||
// assigning targeting to container | ||
targeting = true; | ||
if (targetingObject != null) { | ||
var targetingTree = void 0; | ||
if (null != targetingObject.targetingSegment) { | ||
targetingTree = targetingObject.targetingSegment.targetingTree; | ||
} | ||
else { | ||
var targetingTree = void 0; | ||
if (null != xpConf.targetingSegment) { | ||
targetingTree = xpConf.targetingSegment.targetingTree; | ||
} | ||
// obtaining targeting checking result and assigning targeting to container | ||
targeting = targetingEngine_1.TargetingEngine.checkTargetingTree(targetingTree, function (type) { return _this.getConditionData(type, visitorCode, campaignId); }); | ||
} | ||
// obtaining targeting checking result and assigning targeting to container | ||
targeting = targetingEngine_1.TargetingEngine.checkTargetingTree(targetingTree, function (type) { return _this.getConditionData(type, visitorCode, campaignId); }); | ||
} | ||
@@ -468,8 +540,14 @@ return targeting; | ||
case constants_1.ConditionTypes.CUSTOM_DATUM: | ||
return { targetingData: _this.getTargetingData(visitorCode) }; | ||
return { | ||
targetingData: _this.getTargetingData(visitorCode), | ||
}; | ||
case constants_1.ConditionTypes.EXCLUSIVE_EXPERIMENT: | ||
return { currentExperimentId: campaignId, | ||
variationStorage: _this.variationStorage.getMapVariationId(visitorCode) }; | ||
return { | ||
currentExperimentId: campaignId, | ||
variationStorage: _this.variationStorage.getMapVariationId(visitorCode), | ||
}; | ||
case constants_1.ConditionTypes.TARGET_EXPERIMENT: | ||
return { variationStorage: _this.variationStorage.getMapVariationId(visitorCode) }; | ||
return { | ||
variationStorage: _this.variationStorage.getMapVariationId(visitorCode), | ||
}; | ||
default: | ||
@@ -479,3 +557,3 @@ return null; | ||
}; | ||
this.obtainVariationAssociatedData = function (variationId) { | ||
this.getVariationAssociatedData = function (variationId) { | ||
var _a, _b, _c; | ||
@@ -485,3 +563,3 @@ for (var vid in (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.experiments) { | ||
if (experiment === null || experiment === void 0 ? void 0 : experiment.variationConfigurations[variationId]) { | ||
return (_c = experiment === null || experiment === void 0 ? void 0 : experiment.variationConfigurations[variationId].customJson) !== null && _c !== void 0 ? _c : {}; | ||
return ((_c = experiment === null || experiment === void 0 ? void 0 : experiment.variationConfigurations[variationId].customJson) !== null && _c !== void 0 ? _c : {}); | ||
} | ||
@@ -491,11 +569,20 @@ } | ||
}; | ||
/** | ||
* @deprecated Use getVariationAssociatedData instead. | ||
*/ | ||
this.obtainVariationAssociatedData = function (variationId) { | ||
return _this.getVariationAssociatedData(variationId); | ||
}; | ||
/** | ||
* @deprecated Use getFeatureVariable instead. | ||
*/ | ||
this.obtainFeatureVariable = function (featureIdOrName, variable) { | ||
var _a, _b, _c, _d; | ||
_this.checkFeatureKeyOrId(featureIdOrName); | ||
for (var ffid in (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags) { | ||
var ff = (_b = _this.configurations) === null || _b === void 0 ? void 0 : _b.featureFlags[ffid]; | ||
if (ffid == featureIdOrName || (ff === null || ff === void 0 ? void 0 : ff.identificationKey) === featureIdOrName) { | ||
if (ffid == featureIdOrName || | ||
(ff === null || ff === void 0 ? void 0 : ff.identificationKey) === featureIdOrName) { | ||
for (var vid in ff === null || ff === void 0 ? void 0 : ff.variationConfigurations) { | ||
if (vid !== "0") { | ||
return _this._parseJsonValue((_d = (_c = ff === null || ff === void 0 ? void 0 : ff.variationConfigurations[vid]) === null || _c === void 0 ? void 0 : _c.customJson) === null || _d === void 0 ? void 0 : _d[variable]); | ||
return _this._parseVariableValue((_d = (_c = ff === null || ff === void 0 ? void 0 : ff.variationConfigurations[vid]) === null || _c === void 0 ? void 0 : _c.customJson) === null || _d === void 0 ? void 0 : _d[variable]); | ||
} | ||
@@ -507,2 +594,25 @@ } | ||
}; | ||
this.getFeatureAllVariables = function (featureIdOrName) { | ||
var _a; | ||
var ff = _this._findFeature(featureIdOrName); | ||
if (ff !== null) { | ||
var allVariables = {}; | ||
for (var vid in ff === null || ff === void 0 ? void 0 : ff.variationConfigurations) { | ||
if (vid != "0") { | ||
var dict = (_a = ff === null || ff === void 0 ? void 0 : ff.variationConfigurations[vid]) === null || _a === void 0 ? void 0 : _a.customJson; | ||
for (var key in dict) { | ||
allVariables[key] = _this._parseVariableValue(dict[key]); | ||
} | ||
} | ||
} | ||
return allVariables; | ||
} | ||
return {}; | ||
}; | ||
/** | ||
* @deprecated Use getFeatureAllVariables instead. | ||
*/ | ||
this.obtainFeatureAllVariables = function (featureIdOrName) { | ||
return _this.getFeatureAllVariables(featureIdOrName); | ||
}; | ||
this.retrieveDataFromRemoteSource = function (key) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -518,21 +628,63 @@ var _this = this; | ||
}); }; | ||
this._parseJsonValue = function (obj) { | ||
if (obj == null) { | ||
throw new featureConfigurationNotFound_1.default("KameleoonException.FeatureConfigurationNotFound"); | ||
this._parseVariableValue = function (obj) { | ||
switch (obj.type.toUpperCase()) { | ||
case "NUMBER": | ||
return parseInt(obj.value); | ||
case "JSON": | ||
return JSON.parse(obj.value); | ||
default: | ||
return obj.value; | ||
} | ||
else { | ||
switch (obj.type) { | ||
case 'Boolean': | ||
return obj.value == 'True'; | ||
case 'Number': | ||
return parseInt(obj.value); | ||
case 'JSON': | ||
return JSON.parse(obj.value); | ||
default: | ||
return obj.value; | ||
} | ||
} | ||
}; | ||
this.getExperimentList = function () { | ||
var _a, _b; | ||
return Object.keys((_b = (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.experiments) !== null && _b !== void 0 ? _b : {}).map(Number); | ||
}; | ||
/** | ||
* @deprecated Use getExperimentList instead. | ||
*/ | ||
this.obtainExperimentList = function () { | ||
return _this.getExperimentList(); | ||
}; | ||
this.getExperimentListForVisitorCode = function (visitorCode, onlyActive) { | ||
var _a; | ||
if (onlyActive === void 0) { onlyActive = true; } | ||
return _this._getListForVisitorCode((_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.experiments, visitorCode, onlyActive, false); | ||
}; | ||
/** | ||
* @deprecated Use getExperimentListForVisitorCode instead. | ||
*/ | ||
this.obtainExperimentListForVisitorCode = function (visitorCode, onlyActive) { | ||
if (onlyActive === void 0) { onlyActive = true; } | ||
return _this.getExperimentListForVisitorCode(visitorCode, onlyActive); | ||
}; | ||
this.getFeatureList = function () { | ||
var _a, _b; | ||
return Object.values((_b = (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlagsV2) !== null && _b !== void 0 ? _b : {}).map(function (element) { | ||
return element.featureKey; | ||
}); | ||
}; | ||
/** | ||
* @deprecated Use getFeatureList instead. | ||
*/ | ||
this.obtainFeatureList = function () { | ||
var _a, _b; | ||
return Object.values((_b = (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags) !== null && _b !== void 0 ? _b : {}).map(function (element) { | ||
return element.identificationKey; | ||
}); | ||
}; | ||
this.getFeatureListForVisitorCode = function (visitorCode, onlyActive) { | ||
var _a; | ||
if (onlyActive === void 0) { onlyActive = true; } | ||
return _this._getListForVisitorCode((_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags, visitorCode, onlyActive, true); | ||
}; | ||
/** | ||
* @deprecated Use getFeatureListForVisitorCode instead. | ||
*/ | ||
this.obtainFeatureListForVisitorCode = function (visitorCode, onlyActive) { | ||
if (onlyActive === void 0) { onlyActive = true; } | ||
return _this.getFeatureListForVisitorCode(visitorCode, onlyActive); | ||
}; | ||
this.saveConfiguration = function () { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
if (_this.configurations) { | ||
@@ -545,4 +697,5 @@ var data = { | ||
featureFlags: (_b = _this.configurations.configuration) === null || _b === void 0 ? void 0 : _b.featureFlags, | ||
configuration: _this.configurations.settings | ||
} | ||
featureFlagConfigurations: (_c = _this.configurations.configuration) === null || _c === void 0 ? void 0 : _c.featureFlagsV2, | ||
configuration: _this.configurations.settings, | ||
}, | ||
}; | ||
@@ -562,3 +715,5 @@ try { | ||
else if (visitorCode.length > KameleoonClient.VISITOR_CODE_MAX_LENGTH) { | ||
throw new visitorCodeNotValid_1.VisitorCodeNotValid("Visitor code max length is " + KameleoonClient.VISITOR_CODE_MAX_LENGTH + " characters"); | ||
throw new visitorCodeNotValid_1.VisitorCodeNotValid("Visitor code max length is " + | ||
KameleoonClient.VISITOR_CODE_MAX_LENGTH + | ||
" characters"); | ||
} | ||
@@ -575,3 +730,4 @@ }; | ||
if (configuration.actions_configuration_refresh_interval) { | ||
this.minutesBetweenConfigurationUpdate = configuration.actions_configuration_refresh_interval; | ||
this.minutesBetweenConfigurationUpdate = | ||
configuration.actions_configuration_refresh_interval; | ||
} | ||
@@ -582,16 +738,62 @@ if (configuration.environment) { | ||
} | ||
this.targetingDataNumberEntriesAuthorized = this.visitorDataMaximumSize * 1000000 / constants_1.TARGETING_DATA_MAXIMUM_SIZE_BYTES; | ||
this.targetingDataNumberEntriesAuthorized = | ||
(this.visitorDataMaximumSize * 1000000) / | ||
constants_1.TARGETING_DATA_MAXIMUM_SIZE_BYTES; | ||
this.updateCampaignConfiguration(); | ||
setInterval(this.emptyTargetingData, constants_1.DEFAULT_MILLISECONDS_BETWEEN_TARGETING_DATA_UPDATE); | ||
} | ||
KameleoonClient.prototype.calculateHash = function (value) { | ||
var buff = kameleoonUtils_1.default.computeStringSha256(value); | ||
return parseInt(buff, 16) / Math.pow(2, 256); | ||
}; | ||
KameleoonClient.prototype._findFeature = function (featureIdOrName) { | ||
var _a, _b; | ||
var ff = Object.values((_b = (_a = this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags) !== null && _b !== void 0 ? _b : {}).find(function (ff) { | ||
return (ff === null || ff === void 0 ? void 0 : ff.identificationKey) == featureIdOrName || (ff === null || ff === void 0 ? void 0 : ff.id) == featureIdOrName; | ||
}); | ||
if (ff) { | ||
return ff; | ||
} | ||
else { | ||
throw new featureConfigurationNotFound_1.default("KameleoonException.FeatureConfigurationNotFound." + | ||
this.featureFlagInfoForException(featureIdOrName)); | ||
} | ||
}; | ||
KameleoonClient.prototype._findFeatureV2 = function (featureKey) { | ||
var _a, _b; | ||
//fetch feature flag ID (number) by featureKey (string) | ||
var ff = Object.values((_b = (_a = this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlagsV2) !== null && _b !== void 0 ? _b : {}).find(function (ff) { return (ff === null || ff === void 0 ? void 0 : ff.featureKey) == featureKey; }); | ||
if (ff) { | ||
return ff; | ||
} | ||
else { | ||
throw new featureConfigurationNotFound_1.default("KameleoonException.FeatureConfigurationNotFound." + | ||
this.featureFlagInfoForException(featureKey)); | ||
} | ||
}; | ||
KameleoonClient.prototype._getListForVisitorCode = function (list, visitorCode, onlyActive, isFF) { | ||
this.validateVisitorCode(visitorCode); | ||
var campaignIds = []; | ||
for (var _i = 0, _a = Object.entries(list !== null && list !== void 0 ? list : {}); _i < _a.length; _i++) { | ||
var _b = _a[_i], key = _b[0], campaign = _b[1]; | ||
var campaignId = parseInt(key); | ||
if (this.checkTargeting(visitorCode, campaignId, campaign)) { | ||
if (onlyActive) { | ||
var hashDouble = this.obtainHashDouble(campaignId, visitorCode, campaign); | ||
var variationConfiguration = campaign.variationConfigurations[0]; | ||
if (hashDouble < variationConfiguration.deviation) { | ||
continue; | ||
} | ||
} | ||
campaignIds.push(isFF ? campaign.identificationKey : campaignId); | ||
} | ||
} | ||
return campaignIds; | ||
}; | ||
KameleoonClient.prototype.checkSiteEnabled = function (experimentOrFeatureFlag) { | ||
if (experimentOrFeatureFlag != null && !experimentOrFeatureFlag.siteEnabled) { | ||
if (experimentOrFeatureFlag != null && | ||
!experimentOrFeatureFlag.siteEnabled) { | ||
throw new siteCodeDisabled_1.SiteCodeDisabled(this.siteCode); | ||
} | ||
}; | ||
KameleoonClient.prototype.checkFeatureKeyOrId = function (featureIdOrName) { | ||
if (typeof featureIdOrName === "string") { | ||
console.log("Please use `featureIdOrName` with type of `string`. This is necessary to support multi-environment feature. Supporting of `number` type will be removed in next releases"); | ||
} | ||
}; | ||
KameleoonClient.prototype.getAndClearUnsentData = function (visitorCode) { | ||
@@ -608,3 +810,3 @@ var body = ""; | ||
if (subsciptionRequired && !this.realTimeConfigurationService) { | ||
this.realTimeConfigurationService = new realTimeConfigurationService_1.RealTimeConfigurationService(this.getEventsRequestURL(this.siteCode), function (event) { | ||
this.realTimeConfigurationService = new realTimeConfigurationService_1.RealTimeConfigurationService(this.siteCode, this.getEventsRequestURL(this.siteCode), function (event) { | ||
_this.updateCampaignConfiguration(event.ts); | ||
@@ -622,4 +824,7 @@ }); | ||
KameleoonClient.prototype.fireUpdateConfigurationHandler = function (fire) { | ||
fire && this.handlerUpdateConfiguration && this.handlerUpdateConfiguration(); | ||
fire && | ||
this.handlerUpdateConfiguration && | ||
this.handlerUpdateConfiguration(); | ||
}; | ||
KameleoonClient.DEFAULT_TIMEOUT_MILLISECONDS = 2000; | ||
KameleoonClient.VISITOR_CODE_MAX_LENGTH = 255; | ||
@@ -635,4 +840,4 @@ return KameleoonClient; | ||
NotActivated: notActivated_1.default, | ||
CredentialsNotFound: credentialsNotFound_1.default | ||
CredentialsNotFound: credentialsNotFound_1.default, | ||
}; | ||
exports.KameleoonException = KameleoonException; |
@@ -0,3 +1,4 @@ | ||
import { UserAgent } from "./data"; | ||
declare class KameleoonUtils { | ||
doRequest: (url: string, method: HttpMethod, data?: any, callback?: any, addKameleoonClientHeader?: boolean) => void; | ||
doRequest: (url: string, method: HttpMethod, data?: any, callback?: any, addKameleoonClientHeader?: boolean, userAgent?: UserAgent | undefined) => void; | ||
computeStringSha256: (string: string) => string; | ||
@@ -4,0 +5,0 @@ encodeUTF8: (string: string) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HttpMethod = void 0; | ||
var VERSION = "1.0.9"; | ||
var VERSION = "2.0.0"; | ||
var KameleoonUtils = /** @class */ (function () { | ||
function KameleoonUtils() { | ||
var _this = this; | ||
this.doRequest = function (url, method, data, callback, addKameleoonClientHeader) { | ||
this.doRequest = function (url, method, data, callback, addKameleoonClientHeader, userAgent) { | ||
if (addKameleoonClientHeader === void 0) { addKameleoonClientHeader = true; } | ||
@@ -17,3 +17,6 @@ var xhr = new XMLHttpRequest(); | ||
xhr.open(method, url, true); | ||
addKameleoonClientHeader && xhr.setRequestHeader("Kameleoon-Client", "sdk/js/" + VERSION); | ||
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded"); | ||
addKameleoonClientHeader && | ||
xhr.setRequestHeader("Kameleoon-Client", "sdk/js/" + VERSION); | ||
userAgent && xhr.setRequestHeader("User-Agent", userAgent.value); | ||
xhr.send(data ? data : null); | ||
@@ -63,3 +66,6 @@ }; | ||
a.unshift((y = | ||
((a.pop() + (S((b = a[4]), 6) ^ S(b, 11) ^ S(b, 25)) + (((b & a[5]) ^ (~b & a[6])) + K[j])) | 0) + | ||
((a.pop() + | ||
(S((b = a[4]), 6) ^ S(b, 11) ^ S(b, 25)) + | ||
(((b & a[5]) ^ (~b & a[6])) + K[j])) | | ||
0) + | ||
(W[j++] | 0)) + | ||
@@ -104,2 +110,2 @@ (S((l = a[0]), 2) ^ S(l, 13) ^ S(l, 22)) + | ||
})(HttpMethod = exports.HttpMethod || (exports.HttpMethod = {})); | ||
exports.default = new KameleoonUtils; | ||
exports.default = new KameleoonUtils(); |
export interface RealTimeEvent { | ||
siteCode: string; | ||
ts: number; | ||
@@ -10,4 +11,5 @@ } | ||
private eventSource; | ||
constructor(eventUrl: string, handler?: (event: RealTimeEvent) => void); | ||
private siteCode; | ||
constructor(siteCode: string, eventUrl: string, handler?: (event: RealTimeEvent) => void); | ||
disconnect: () => void; | ||
} |
@@ -5,3 +5,3 @@ "use strict"; | ||
var RealTimeConfigurationService = /** @class */ (function () { | ||
function RealTimeConfigurationService(eventUrl, handler) { | ||
function RealTimeConfigurationService(siteCode, eventUrl, handler) { | ||
var _this = this; | ||
@@ -11,3 +11,7 @@ this.disconnect = function () { | ||
}; | ||
this.siteCode = siteCode; | ||
this.eventSource = new EventSource(eventUrl); | ||
this.eventSource.onopen = function (message) { | ||
console.log("onopen called: ".concat(message)); | ||
}; | ||
this.eventSource.onerror = function (error) { | ||
@@ -19,8 +23,13 @@ console.log("SSE Client error called: ".concat(error)); | ||
var event = JSON.parse(messageEvent.data); | ||
handler && handler(event); | ||
if (_this.siteCode === event.siteCode) { | ||
handler && handler(event); | ||
} | ||
}); | ||
this.eventSource.onmessage = function (message) { | ||
console.log(message); | ||
}; | ||
} | ||
RealTimeConfigurationService.EVENT_NAME = 'configuration-update-event'; | ||
RealTimeConfigurationService.EVENT_NAME = "configuration-update-event"; | ||
return RealTimeConfigurationService; | ||
}()); | ||
exports.RealTimeConfigurationService = RealTimeConfigurationService; |
{ | ||
"name": "kameleoon-client-javascript", | ||
"version": "1.0.9", | ||
"version": "2.0.0", | ||
"description": "JavaScript SDK client", | ||
@@ -5,0 +5,0 @@ "main": "dist/kameleoonClient.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134884
82
2991