/** * 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 { IWingifyBuilder } from '../WingifyBuilder'; import { ILogManager } from '../packages/logger'; import { NetworkClientInterface } from '../packages/network-layer/client/NetworkClientInterface'; import { SegmentEvaluator } from '../packages/segmentation-evaluator'; import { Connector } from '../packages/storage/Connector'; import { IGatewayService } from './GatewayServiceModel'; import { BatchConfig } from '../services/BatchEventsQueue'; import { ClientStorageOptions } from '../packages/storage/connectors/BrowserStorageConnector'; import { IHttpsAgentConfig, IRetryConfig } from '../packages/network-layer/client/NetworkClient'; import { IEdgeConfig } from './edge/EdgeConfigModel'; import { IBrowserConfig } from './browser/BrowserConfigModel'; interface IIntegrationOptions { callback?: (properties: Record) => void; } interface INetworkOptions { client?: NetworkClientInterface; } export interface ISdkMetaConfig { _vwo_sdkName?: string; _vwo_sdkVersion?: string; _wingify_sdkName?: string; _wingify_sdkVersion?: string; } export interface IWingifyOptions { accountId: string; sdkKey: string; isDevelopmentMode?: boolean; storage?: Connector | Record; gatewayService?: IGatewayService; pollInterval?: number; logger?: ILogManager; segmentation?: SegmentEvaluator; integrations?: IIntegrationOptions; network?: INetworkOptions; platform?: string; shouldWaitForTrackingCalls?: boolean; settings?: Record; batchEventData?: BatchConfig; wingifyBuilder?: IWingifyBuilder; vwoBuilder?: IWingifyBuilder; isUsageStatsDisabled?: boolean; _wingify_meta?: Record; _vwo_meta?: Record; clientStorage?: ClientStorageOptions; retryConfig?: IRetryConfig; httpsAgentConfig?: IHttpsAgentConfig; proxyUrl?: string; isAliasingEnabled?: boolean; edgeConfig?: IEdgeConfig; browserConfig?: IBrowserConfig; sdkMeta?: ISdkMetaConfig; isBatchingDisabled?: boolean; } export class WingifyOptionsModel implements IWingifyOptions { accountId: string; sdkKey: string; isDevelopmentMode?: boolean; storage?: Connector | Record; gatewayService?: IGatewayService; pollInterval?: number; logger?: ILogManager; segmentation?: SegmentEvaluator; integrations?: IIntegrationOptions; network?: INetworkOptions; shouldWaitForTrackingCalls?: boolean; settings?: Record; isAliasingEnabled?: boolean; wingifyBuilder?: IWingifyBuilder; vwoBuilder?: IWingifyBuilder; isUsageStatsDisabled?: boolean; _vwo_meta?: Record; _wingify_meta?: Record; clientStorage?: ClientStorageOptions; retryConfig?: IRetryConfig; httpsAgentConfig?: IHttpsAgentConfig; proxyUrl?: string; edgeConfig?: IEdgeConfig; browserConfig?: IBrowserConfig; sdkMeta?: ISdkMetaConfig; isBatchingDisabled?: boolean; modelFromDictionary(options: WingifyOptionsModel): this { this.accountId = options.accountId; this.sdkKey = options.sdkKey; this.wingifyBuilder = options.wingifyBuilder || options.vwoBuilder; if (options?.shouldWaitForTrackingCalls) { this.shouldWaitForTrackingCalls = options.shouldWaitForTrackingCalls; } if (options?.isDevelopmentMode) { this.isDevelopmentMode = options.isDevelopmentMode; } if (options?.storage) { this.storage = options.storage; } if (options?.gatewayService) { this.gatewayService = options.gatewayService; } if (options?.pollInterval) { this.pollInterval = options.pollInterval; } if (options?.logger) { this.logger = options.logger; } if (options?.segmentation) { this.segmentation = options.segmentation; } if (options?.integrations) { this.integrations = options.integrations; } if (options?.network) { this.network = options.network; } if (options?.settings) { this.settings = options.settings; } if (options?.isUsageStatsDisabled) { this.isUsageStatsDisabled = options.isUsageStatsDisabled; } if (options?._wingify_meta || options?._vwo_meta) { this._wingify_meta = options._wingify_meta || options._vwo_meta; } if (options?.clientStorage) { this.clientStorage = options.clientStorage; } if (options?.retryConfig) { this.retryConfig = options.retryConfig; } if (options?.proxyUrl) { this.proxyUrl = options.proxyUrl; } if (options?.isAliasingEnabled) { this.isAliasingEnabled = options.isAliasingEnabled; } if (options?.edgeConfig) { this.edgeConfig = options.edgeConfig; } if (options?.browserConfig) { this.browserConfig = options.browserConfig; } if (options?.sdkMeta) { this.sdkMeta = options.sdkMeta; } if (options?.httpsAgentConfig) { this.httpsAgentConfig = options.httpsAgentConfig; } // default to false if not provided this.isBatchingDisabled = options?.isBatchingDisabled ?? false; return this; } /** * Gets the flag indicating whether batching is disabled. * @returns The flag indicating whether batching is disabled. */ getIsBatchingDisabled(): boolean { return this.isBatchingDisabled; } /** * Gets the HTTPS agent configuration. * @returns The HTTPS agent configuration. */ getHttpsAgentConfig(): IHttpsAgentConfig { return this.httpsAgentConfig; } getAccountId(): string { return this.accountId; } getSdkKey(): string { return this.sdkKey; } getIsDevelopmentMode(): boolean { return this.isDevelopmentMode; } getStorageService(): Connector | Record { return this.storage; } getGatewayService(): IGatewayService { return this.gatewayService; } getPollInterval(): number { return this.pollInterval; } getLogger(): ILogManager { return this.logger; } getSegmentation(): SegmentEvaluator { return this.segmentation; } getNetwork(): INetworkOptions { return this.network; } getWingifyBuilder(): IWingifyBuilder { return this.wingifyBuilder; } getSettings(): Record { return this.settings; } getIsUsageStatsDisabled(): boolean { return this.isUsageStatsDisabled; } getWingifyMeta(): Record { return this._wingify_meta; } getClientStorage(): ClientStorageOptions { return this.clientStorage; } getRetryConfig(): IRetryConfig { return this.retryConfig; } getProxyUrl(): string { return this.proxyUrl; } getIsAliasingEnabled(): boolean { return this.isAliasingEnabled; } getEdgeConfig(): IEdgeConfig { return this.edgeConfig; } getBrowserConfig(): IBrowserConfig { return this.browserConfig; } /** * Gets the SDK meta. * @returns The SDK meta. */ getSdkMeta(): ISdkMetaConfig | undefined { return this.sdkMeta; } /** * Gets the SDK name. * @returns The SDK name. */ getSdkName(): string | undefined { return this.sdkMeta?._wingify_sdkName || this.sdkMeta?._vwo_sdkName; } /** * Gets the SDK version. * @returns The SDK version. */ getVersion(): string | undefined { return this.sdkMeta?._wingify_sdkVersion || this.sdkMeta?._vwo_sdkVersion; } }