/** * Copyright 2026, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type { Client, OptimizelyUserContext } from '@optimizely/optimizely-sdk'; import type { UserInfo } from '../provider'; export interface UserContextManagerConfig { client: Client; onUserContextChange: (ctx: OptimizelyUserContext | null) => void; onError: (error: Error) => void; } /** * Manages user context creation, VUID resolution, and ODP segment fetching. * * Handles async operations with staleness checks so that rapid user changes * only result in the latest request's callback being fired. Previous in-flight * operations are abandoned via a requestId counter. * * Internally tracks previous user, segments, and skipSegments values to * short-circuit when nothing has changed. */ export declare class UserContextManager { private readonly client; private readonly onUserContextChange; private readonly onError; private readonly meta; private requestId; private disposed; private initialized; private skipSegments; private prevUser?; private prevSegments?; constructor(config: UserContextManagerConfig); /** * Resolves whether user context needs to be (re)created based on * value-equality of user, qualifiedSegments, and skipSegments. * Short-circuits if nothing has changed since the previous call. * * @param user - Optional user info (id and attributes) * @param qualifiedSegments - Optional pre-fetched segments. When provided, * @param skipSegments - Whether to skip ODP segment fetching (default: false) */ resolveUserContext(user?: UserInfo | null, qualifiedSegments?: string[], skipSegments?: boolean): void; /** * Disposes the manager, preventing any future callbacks from firing. */ dispose(): void; private createUserContext; private isStale; }