/** * Copyright 2024-2026 Wingify Software Pvt. Ltd. * * 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 * * http://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 { Storage } from './packages/storage'; import { Flag } from './api/GetFlag'; import { SettingsModel } from './models/settings/SettingsModel'; import { dynamic } from './types/Common'; import { IWingifyOptions } from './models/WingifyOptionsModel'; import { ServiceContainer } from './services/ServiceContainer'; export interface IWingifyClient { readonly options?: IWingifyOptions; settings: SettingsModel; originalSettings: Record; isSettingsValid: boolean; settingsFetchTime: number | undefined; isAliasingEnabled: boolean; getFlag(featureKey: string, context: Record): Promise; trackEvent( eventName: string, context: Record, eventProperties?: Record, ): Promise>; setAttribute( attributeKey: string, attributeValue: boolean | string | number, context: Record, ): Promise; setAttribute(attributes: Record, context: Record): Promise; updateSettings(settings?: Record, isViaWebhook?: boolean): Promise; flushEvents(): Promise>; shutdown(): Promise; setAlias(context: Record | string, aliasId: string): Promise; } export declare class WingifyClient implements IWingifyClient { settings: SettingsModel; originalSettings: Record; storage: Storage; wingifyClientInstance: WingifyClient; isSettingsValid: boolean; settingsFetchTime: number | undefined; isAliasingEnabled: boolean; serviceContainer: ServiceContainer; options?: IWingifyOptions; private isShutdown; /** * Constructor for the WingifyClient class. * @param settings - The settings to initialize the client with. * @param options - The options to initialize the client with. * @param logManager - The log manager to use for logging. * @param settingsService - The settings service to use for fetching settings. * @param networkManager - The network manager to use for making network requests. * @param storage - The storage to use for storing data. * @param batchEventsQueue - The batch events queue to use for batching events. */ constructor(settings: Record, options: IWingifyOptions, serviceContainer: ServiceContainer); /** * Sends the SDK init event and usage stats event * @param usageStatsUtil - The usage stats util to use for sending the usage stats event */ private sendSdkInitAndUsageStatsEvents; /** * Retrieves the value of a feature flag for a given feature key and context. * This method validates the feature key and context, ensures the settings are valid, and then uses the FlagApi to get the flag value. * * @param {string} featureKey - The key of the feature to retrieve. * @param {ContextModel} context - The context in which the feature flag is being retrieved, must include a valid user ID. * @returns {Promise} - A promise that resolves to the feature flag value. */ getFlag(featureKey: string, context: Record): Promise; /** * Tracks an event with specified properties and context. * This method validates the types of the inputs and ensures the settings and user context are valid before proceeding. * * @param {string} eventName - The name of the event to track. * @param {ContextModel} context - The context in which the event is being tracked, must include a valid user ID. * @param {Record} eventProperties - The properties associated with the event. * @returns {Promise>} - A promise that resolves to the result of the tracking operation. */ trackEvent( eventName: string, context: Record, eventProperties?: Record, ): Promise>; /** * Sets an attribute or multiple attributes for a user in the provided context. * This method validates the types of the inputs before proceeding with the API call. * There are two cases handled: * 1. When attributes are passed as a map (key-value pairs). * 2. When a single attribute (key-value) is passed. * * @param {string | Record} attributeOrAttributes - Either a single attribute key (string) and value (boolean | string | number), * or a map of attributes with keys and values (boolean | string | number). * @param {boolean | string | number | Record} [attributeValueOrContext] - The value for the attribute in case of a single attribute, or the context when multiple attributes are passed. * @param {Record} [context] - The context which must include a valid user ID. This is required if multiple attributes are passed. */ setAttribute( attributeOrAttributes: string | Record, attributeValueOrContext?: boolean | string | number | Record, context?: Record, ): Promise; /** * Updates the settings by fetching the latest settings from the Wingify server. * @param settings - The settings to update. * @param isViaWebhook - Whether to fetch the settings from the webhook endpoint. * @returns Promise */ updateSettings(settings?: Record, isViaWebhook?: boolean): Promise; /** * Flushes the events manually from the batch events queue */ flushEvents(): Promise>; /** * Sets alias for a given user ID * @param contextOrUserId - The context containing user ID or the user ID directly * @param aliasId - The alias identifier to set * @returns Promise - Returns true if successful, false otherwise */ setAlias(contextOrUserId: Record | string, aliasId: string): Promise; /** * Generates a UUID from the context.id * @param context - The context to generate the UUID from * @param apiName - The name of the API calling this method * @returns The UUID generated from the context.id */ private getUUIDFromContext; /** * Shuts down the client: flushes pending batch events (and clears the batch timer) via flushEvents(), * then clears the batch queue so no further events are enqueued. Idempotent. */ shutdown(): Promise; }