/*! * Convert JS SDK * Version 1.0.0 * Copyright(c) 2020 Convert Insights, Inc * License Apache-2.0 */ import { ContextInterface } from './interfaces/context'; import { EventManagerInterface } from '../../event'; import { ExperienceManagerInterface } from '../../experience'; import { FeatureManagerInterface } from './interfaces/feature-manager'; import { LogManagerInterface } from '../../logger'; import { DataManagerInterface } from '../../data'; import { Config, BucketedFeature, BucketedVariation, BucketingAttributes, ConversionAttributes, VisitorSegments, SegmentsAttributes, Entity, StoreData } from '../../types'; import { BucketingError, EntityType, RuleError } from '../../enums'; import { SegmentsManagerInterface } from '../../segments'; import { ApiManagerInterface } from '../../api'; /** * Provides visitor context * @category Main * @constructor * @implements {ContextInterface} */ export declare class Context implements ContextInterface { private _eventManager; private _experienceManager; private _featureManager; private _dataManager; private _segmentsManager; private _apiManager; private _loggerManager; private _config; private _visitorId; private _visitorProperties; private _environment; /** * @param {Config} config * @param {Object} dependencies * @param {ApiManagerInterface} dependencies.apiManager * @param {EventManagerInterface} dependencies.eventManager * @param {ExperienceManagerInterface} dependencies.experienceManager * @param {FeatureManagerInterface} dependencies.featureManager * @param {DataManagerInterface} dependencies.dataManager * @param {ApiManagerInterface} dependencies.apiManager * @param {LogManagerInterface} dependencies.loggerManager */ constructor(config: Config, visitorId: string, { eventManager, experienceManager, featureManager, segmentsManager, dataManager, apiManager, loggerManager }: { eventManager: EventManagerInterface; experienceManager: ExperienceManagerInterface; featureManager: FeatureManagerInterface; segmentsManager: SegmentsManagerInterface; dataManager: DataManagerInterface; apiManager: ApiManagerInterface; loggerManager?: LogManagerInterface; }, visitorProperties?: Record); /** * Get variation from specific experience * @param {string} experienceKey An experience's key that should be activated * @param {BucketingAttributes=} attributes An object that specifies attributes for the visitor * @param {Record=} attributes.locationProperties An object of key-value pairs that are used for location matching * @param {Record=} attributes.visitorProperties An object of key-value pairs that are used for audience targeting * @param {boolean=} attributes.updateVisitorProperties Decide whether to update visitor properties upon bucketing * @param {string=} attributes.environment Overwrite the environment * @return {BucketedVariation | RuleError | BucketingError} */ runExperience(experienceKey: string, attributes?: BucketingAttributes): BucketedVariation | RuleError | BucketingError; /** * Get variations across all experiences * @param {BucketingAttributes=} attributes An object that specifies attributes for the visitor * @param {string=} attributes.locationProperties An object of key-value pairs that are used for location matching * @param {Record=} attributes.visitorProperties An object of key-value pairs that are used for audience targeting * @param {boolean=} attributes.updateVisitorProperties Decide whether to update visitor properties upon bucketing * @param {string=} attributes.environment Overwrite the environment * @return {Array} */ runExperiences(attributes?: BucketingAttributes): Array; /** * Get feature and its status * @param {string} key A feature key * @param {BucketingAttributes=} attributes An object that specifies attributes for the visitor * @param {string=} attributes.locationProperties An object of key-value pairs that are used for location matching * @param {Record=} attributes.visitorProperties An object of key-value pairs that are used for audience targeting * @param {boolean=} attributes.updateVisitorProperties Decide whether to update visitor properties upon bucketing * @param {string=} attributes.environment Overwrite the environment * @param {boolean=} attributes.typeCasting Control automatic type conversion to the variable's defined type. Does not do any JSON validation. Defaults to `true` * @param {Array=} attributes.experienceKeys Use only specific experiences * @return {BucketedFeature | RuleError | Array} */ runFeature(key: string, attributes?: BucketingAttributes): BucketedFeature | RuleError | Array; /** * Get features and their statuses * @param {BucketingAttributes=} attributes An object that specifies attributes for the visitor * @param {string=} attributes.locationProperties An object of key-value pairs that are used for location matching * @param {Record=} attributes.visitorProperties An object of key-value pairs that are used for audience targeting * @param {boolean=} attributes.updateVisitorProperties Decide whether to update visitor properties upon bucketing * @param {string=} attributes.environment Overwrite the environment * @param {boolean=} attributes.typeCasting Control automatic type conversion to the variable's defined type. Does not do any JSON validation. Defaults to `true` * @return {Array} */ runFeatures(attributes?: BucketingAttributes): Array; /** * Trigger Conversion * @param {string} goalKey A goal key * @param {ConversionAttributes=} attributes An object that specifies attributes for the visitor * @param {Record=} attributes.ruleData An object of key-value pairs that are used for goal matching * @param {Array=} attributes.conversionData An array of key-value pairs that are used for transaction data * @param {Record} attributes.conversionSetting An object of key-value pairs that are used for tracking settings * @return {RuleError} */ trackConversion(goalKey: string, attributes?: ConversionAttributes): RuleError; /** * Set default segments for reports * @param {VisitorSegments} segments A segment key */ setDefaultSegments(segments: VisitorSegments): void; /** * To be deprecated */ setCustomSegments(segmentKeys: string[], attributes?: SegmentsAttributes): RuleError; /** * Match Custom segments * @param {Array} segmentKeys A list of segment keys * @param {SegmentsAttributes=} attributes An object that specifies attributes for the visitor * @param {Record=} attributes.ruleData An object of key-value pairs that are used for segments matching * @return {RuleError} */ runCustomSegments(segmentKeys: Array, attributes?: SegmentsAttributes): RuleError; /** * Update visitor properties in memory * @param {string} visitorId * @param {Record} visitorProperties */ updateVisitorProperties(visitorId: string, visitorProperties: Record): void; /** * get Config Entity * @param {string} key * @param {EntityType} entityType * @return {Entity} */ getConfigEntity(key: string, entityType: EntityType): Entity; /** * get Config Entity by string * @param {string} id * @param {EntityType} entityType * @return {Entity} */ getConfigEntityById(id: string, entityType: EntityType): Entity; /** * Get visitor data * @returns {StoreData} */ getVisitorData(): StoreData; /** * Send pending API/DataStore queues to server * @param {string=} reason * @return {Promise} */ releaseQueues(reason?: string): Promise; /** * Get visitor properties * @param {Record=} attributes An object of key-value pairs that are used for audience targeting * @return {Record} */ private getVisitorProperties; }