import { ApiManagerInterface } from '../../api'; import { BucketingManagerInterface } from '../../bucketing'; import { DataStoreManagerInterface } from './interfaces/data-store-manager'; import { DataManagerInterface } from './interfaces/data-manager'; import { EventManagerInterface } from '../../event'; import { LogManagerInterface } from '../../logger'; import { RuleManagerInterface } from '../../rules'; import { Entity, Config, ConfigResponseData, ConfigExperience, IdentityField, BucketedVariation, StoreData, GoalData, VisitorSegments, BucketingAttributes, LocationAttributes } from '../../types'; import { BucketingError, RuleError, ConversionSettingKey } from '../../enums'; /** * Provides logic for data. Stores bucket with help of dataStore if it's provided * @category Modules * @constructor * @implements {DataManagerInterface} */ export declare class DataManager implements DataManagerInterface { private _data; private _accountId; private _projectId; private _config; private _bucketingManager; private _loggerManager; private _eventManager; private _dataStoreManager; private _apiManager; private _ruleManager; private _dataEntities; private _localStoreLimit; private _bucketedVisitors; private _asyncStorage; private _environment; private _mapper; /** * @param {Config} config * @param {Object} dependencies * @param {ApiManagerInterface} dependencies.apiManager * @param {BucketingManagerInterface} dependencies.bucketingManager * @param {RuleManagerInterface} dependencies.ruleManager * @param {LogManagerInterface} dependencies.loggerManager */ constructor(config: Config, { bucketingManager, ruleManager, eventManager, apiManager, loggerManager }: { bucketingManager: BucketingManagerInterface; ruleManager: RuleManagerInterface; eventManager: EventManagerInterface; apiManager: ApiManagerInterface; loggerManager?: LogManagerInterface; }, { asyncStorage }?: { asyncStorage?: boolean; }); set data(data: ConfigResponseData); /** * data getter */ get data(): ConfigResponseData; /** * dataStoreManager setter * @param {any=} dataStore */ set dataStoreManager(dataStore: any); /** * dataStoreManager getter */ get dataStoreManager(): DataStoreManagerInterface; /** * Set dataStoreManager at run-time */ setDataStore(dataStore: any): void; /** * Validate locationProperties against locations rules and visitorProperties against audiences rules * @param {string} visitorId * @param {string} identity Value of the field which name is provided in identityField * @param {IdentityField=} identityField Defaults to 'key' * @param {BucketingAttributes} attributes * @param {Record} attributes.locationProperties * @param {Record} attributes.visitorProperties * @param {boolean=} attributes.enableStorage Defaults to `true`. Gates the * location-match persistence write in `selectLocations()`; matching itself * is always performed regardless of this flag. * @param {string=} attributes.environment * @param {boolean=} attributes.suppressEvents Defaults to `false`. Threaded * to `selectLocations()` to suppress the LOCATION_ACTIVATED/ * LOCATION_DEACTIVATED event fires only (qs-02 preview); matching is * unaffected. * @return {ConfigExperience | RuleError} */ matchRulesByField(visitorId: string, identity: string, identityField: IdentityField, attributes: BucketingAttributes): ConfigExperience | RuleError; /** * Retrieve variation for visitor * @param {string} visitorId * @param {string} identity Value of the field which name is provided in identityField * @param {IdentityField=} identityField Defaults to 'key' * @param {BucketingAttributes} attributes * @param {Record} attributes.locationProperties * @param {Record} attributes.visitorProperties * @param {boolean=} attributes.updateVisitorProperties * @param {string=} attributes.forceVariationId * @param {boolean=} attributes.enableTracking Defaults to `true` * @param {boolean=} attributes.enableStorage Defaults to `true` * @param {boolean=} attributes.asyncStorage Defaults to `true` * @param {string=} attributes.environment * @param {boolean=} attributes.suppressEvents Defaults to `false`. Threaded * to `matchRulesByField()` -> `selectLocations()` to suppress the * LOCATION_ACTIVATED/LOCATION_DEACTIVATED event fires only (qs-02 preview). * @return {BucketedVariation | RuleError | BucketingError} * @private */ private _getBucketingByField; /** * Build buckets where key is variation id and value is traffic distribution * (existing packed layout, experience version <= 11, missing, or non-numeric; * byte-for-byte unchanged). Version 11 is the version stamped on every experience * currently served in production (backend `CURRENT_EXPERIENCE_VERSION`), so this * is the active path for all currently-running experiments. * @param {ExperienceVariationConfig[]} variations * @return {Record} * @private */ private _buildPackedBuckets; /** * Build variation allocations for the anchored layout (qs-01 / DATA-1, contract v12). * Activates only once the served experience version is > 11 (i.e. >= 12, once the * backend bumps `CURRENT_EXPERIENCE_VERSION` past its current value of 11). * Inactive arms (stopped, or explicit zero traffic_allocation) keep their weight for * anchor stability but are marked inactive so {@link BucketingManagerInterface.getBucketRanges} * gives them zero width. See qs-01-anchored-bucketing-layout.md "The contract (normative)". * @param {ExperienceVariationConfig[]} variations * @return {VariationAllocation[]} * @private */ private _buildVariationAllocations; /** * Retrieve bucketing for Visitor * @param {string} visitorId * @param {Record | null} visitorProperties * @param {boolean} updateVisitorProperties * @param {ConfigExperience} experience * @param {string=} forceVariationId * @param {boolean=} enableTracking Defaults to `true` * @param {boolean=} enableStorage Defaults to `true` * @return {BucketedVariation | BucketingError} * @private */ private _retrieveBucketing; /** * @param {string} experienceId * @param {string} variationId * @return {ExperienceVariationConfig} * @private */ private retrieveVariation; reset(): void; /** * @param {string} visitorId * @param {StoreData} newData * @private */ putData(visitorId: string, newData?: StoreData): void; /** * @param {string} visitorId * @return {StoreData} variation id * @private */ getData(visitorId: string): StoreData; /** * @param {string} visitorId * @return {string} storeKey * @private */ getStoreKey(visitorId: string): string; /** * * @param {string} visitorId * @param {Array>} items * @param {Record} attributes.locationProperties * @param {IdentityField=} attributes.identityField * @param {boolean=} attributes.forceEvent * @param {boolean=} attributes.enableStorage Defaults to `true`. Gates only * the persistence write below; location matching always runs regardless. * @param {boolean=} attributes.suppressEvents Defaults to `false`. Gates * only the LOCATION_ACTIVATED/LOCATION_DEACTIVATED event fires below; * location matching always runs regardless. Independent of * `enableTracking`/`enableStorage` -- a normal silent run * (`enableTracking: false`) must still fire these events. Used by preview * contexts (qs-02) for zero-trace event suppression (AC5). * @returns {Array | RuleError>} */ selectLocations(visitorId: string, items: Array>, attributes: LocationAttributes): Array | RuleError>; /** * Retrieve variation for visitor * @param {string} visitorId * @param {string} key * @param {BucketingAttributes} attributes * @param {Record} attributes.locationProperties * @param {Record} attributes.visitorProperties * @param {boolean=} attributes.updateVisitorProperties * @param {boolean=} attributes.enableTracking * @param {string=} attributes.environment * @return {BucketedVariation | RuleError} */ getBucketing(visitorId: string, key: string, attributes: BucketingAttributes): BucketedVariation | RuleError | BucketingError; /** * Retrieve variation for Visitor * @param {string} visitorId * @param {string} id * @param {BucketingAttributes} attributes * @param {Record} attributes.locationProperties * @param {Record} attributes.visitorProperties * @param {boolean=} attributes.updateVisitorProperties * @param {boolean=} attributes.enableTracking * @param {string=} attributes.environment * @return {BucketedVariation | RuleError} */ getBucketingById(visitorId: string, id: string, attributes: BucketingAttributes): BucketedVariation | RuleError | BucketingError; /** * qs-02 / SDK-4: resolve a preview decision directly from the passed-in experience, * bypassing audiences/segments/locations, the environment check, experience status, * variation status/traffic filters, stored decisions, and the bucketing hash entirely. * PURE -- reads only `experience.variations`; never touches shared config (a preview * experience fetched via `?exp=` may not be registered there), never calls `putData`, * and never calls `_apiManager.enqueue`. * @param {ConfigExperience} experience * @param {string} variationId * @return {BucketedVariation | null} */ getPreviewDecision(experience: ConfigExperience, variationId: string): BucketedVariation | null; /** * Process conversion event * @param {string} visitorId * @param {string} goalId * @param {Record=} goalRule An object of key-value pairs that are used for goal matching * @param {Array} goalData An array of object of key-value pairs * @param {VisitorSegments} segments * @param {Record} conversionSetting An object of key-value pairs that are used for tracking settings */ convert(visitorId: string, goalId: string, goalRule?: Record, goalData?: Array, segments?: VisitorSegments, conversionSetting?: Record): RuleError | boolean; /** * qs-03 / SDK-3: walk an audience's rule tree (same OR -> AND -> OR_WHEN traversal * shape as `RuleManager.isRuleMatched`) looking for a `bucketed_into_experience_key` * mutual-exclusion rule element. Documented assumption: at most one such rule per * exclusion audience -- returns the first one found, or `null` if the audience * carries no mutual-exclusion rule (the generic rule-matching path applies instead). * @param {RuleObjectAudience} rules * @return {BucketingExclusionRuleItem | null} * @private */ private _isBucketingExclusionRule; /** * qs-03 / SDK-3: presence-only resolution of a `bucketed_into_experience_key` * mutual-exclusion rule. Read-only -- resolves the rule's target experience by KEY * via `getEntity` and checks ONLY whether the visitor's stored bucketing map * (`getData().bucketing`) already carries an entry keyed by the target's id; it * NEVER calls `retrieveVariation`/the BucketingManager, so evaluating this rule can * never bucket the target experience as a side effect (AC5). If the target key does * not resolve in the served config, warns naming the unresolved key and treats the * visitor as not bucketed into it (`bucketedRaw = false`) rather than failing the * whole audience evaluation. Negation is applied LAST, after the raw presence check. * @param {BucketingExclusionRuleItem} rule * @param {string} visitorId * @return {boolean} * @private */ private _resolveBucketingExclusion; /** * Get audiences that meet the visitorProperties * @param {Array>} items * @param {Record} visitorProperties * @param {string} entityType * @param {IdentityField=} field Defaults to 'id' * @param {string=} visitorId Required only when an item's rules resolve to a * `bucketed_into_experience_key` mutual-exclusion rule (qs-03 / SDK-3); unused by * the generic rule-matching path. * @return {Array | RuleError>} */ filterMatchedRecordsWithRule(items: Array>, visitorProperties: Record, entityType: string, field?: IdentityField, visitorId?: string): Array | RuleError>; /** * Get audiences that meet the custom segments * @param {Array>} items * @param {string} visitorId * @return {Array>} */ filterMatchedCustomSegments(items: Array>, visitorId: string): Array>; /** * Extract report segments from other attribues in Visitor properties * @param {Record=} visitorProperties An object of key-value pairs that are used for audience targeting * @return {Record} */ filterReportSegments(visitorProperties: Record): Record; /** * Get list of data entities * @param {string} entityType * @return {Array} */ getEntitiesList(entityType: string): Array; /** * Get list of data entities grouped by field * @param {string} entityType * @param {IdentityField=} field * @return {Record} */ getEntitiesListObject(entityType: string, field?: IdentityField): Record; /** * * @param {string} identity Value of the field which name is provided in identityField * @param {string} entityType * @param {IdentityField=} identityField Defaults to 'key' * @return {Entity} * @private */ private _getEntityByField; /** * Find the entity in list by id * @param {string} key * @param {string} entityType * @return {Entity} */ getEntity(key: string, entityType: string): Entity; /** * Find the entity in list by keys * @param {Array} keys * @param {string} entityType * @return {Array} */ getEntities(keys: Array, entityType: string): Array; /** * Find the entity in list by id * @param {string} id * @param {string} entityType * @return {Entity} */ getEntityById(id: string, entityType: string): Entity; /** * Find the entity in list by ids * @param {Array} ids * @param {string} entityType * @return {Array} */ getEntitiesByIds(ids: Array, entityType: string): Array; /** * Find the items in list by keys * @param {Array} keys * @param {string} path * @return {Array>} */ getItemsByKeys(keys: Array, path: string): Array>; /** * Find the items in list by ids * @param {Array} ids * @param {String} path * @return {Array>} */ getItemsByIds(ids: Array, path: string): Array>; /** * Find nested item * @param {string} entityType * @param {string|number} entityIdentity * @param {string} subEntityType * @param {string|number} subEntityIdentity * @param {IdentityField} identityField * @param {IdentityField} subIdentityField * @return {Record} */ getSubItem(entityType: string, entityIdentity: string, subEntityType: string, subEntityIdentity: string, identityField: IdentityField, subIdentityField: IdentityField): Record; /** * Validates data object * @param data * @return {boolean} */ isValidConfigData(data: ConfigResponseData): boolean; }