/** * 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 { CampaignModel } from '../campaign/CampaignModel'; import { FeatureModel } from '../campaign/FeatureModel'; import { HoldoutModel } from '../campaign/HoldoutModel'; export class SettingsModel { private sK?: string; private sdkKey: string; private f?: Array = []; private features: Array = []; private c?: Array = []; private campaigns: Array = []; private campaignGroups?: Record = {}; private cG?: Record = {}; private groups?: Record = {}; private g?: Record = {}; private a?: string; private accountId: string; private v?: number; private version: number; private collectionPrefix?: string; private pollInterval?: number; private usageStatsAccountId?: number; private isWebConnectivityEnabled?: boolean; private holdouts?: Array = []; private devMode?: boolean; constructor(settings: SettingsModel) { this.sdkKey = settings.sK || settings.sdkKey; this.accountId = settings.a || settings.accountId; this.version = settings.v || settings.version; this.collectionPrefix = settings.collectionPrefix; this.usageStatsAccountId = settings.usageStatsAccountId; // devMode is an optional parameter, so we need to check if it is defined if (settings.devMode) { this.devMode = settings.devMode; } if ( (settings.f && settings.f.constructor !== {}.constructor) || (settings.features && settings.features.constructor !== {}.constructor) ) { const featureList: Array = settings.f || settings.features; featureList.forEach((feature) => { this.features.push(new FeatureModel().modelFromDictionary(feature)); }); } if ( (settings.c && settings.c.constructor !== {}.constructor) || (settings.campaigns && settings.campaigns.constructor !== {}.constructor) ) { const campaignList: Array = settings.c || settings.campaigns; campaignList.forEach((campaign) => { this.campaigns.push(new CampaignModel().modelFromDictionary(campaign)); }); } if (settings.cG || settings.campaignGroups) { this.campaignGroups = settings.cG || settings.campaignGroups; } if (settings.g || settings.groups) { this.groups = settings.g || settings.groups; } if (settings.pollInterval) { this.pollInterval = settings.pollInterval; } if (settings.isWebConnectivityEnabled) { this.isWebConnectivityEnabled = settings.isWebConnectivityEnabled; } if (Array.isArray((settings as any).holdouts)) { const holdoutsArray: Array = (settings as any).holdouts as Array; holdoutsArray.forEach((holdout) => { this.holdouts.push(new HoldoutModel().modelFromDictionary(holdout)); }); } return this; } getFeatures(): Array { return this.features; } getCampaigns(): Array { return this.campaigns; } getSdkkey(): string { return this.sdkKey; } getAccountId(): string { return this.accountId; } getVersion(): number { return this.version; } getCollectionPrefix(): string { return this.collectionPrefix; } getCampaignGroups(): Record { return this.campaignGroups; } getGroups(): Record { return this.groups; } setPollInterval(value: number): void { this.pollInterval = value; } getPollInterval(): number { return this.pollInterval; } getUsageStatsAccountId(): number { return this.usageStatsAccountId; } getIsWebConnectivityEnabled(): boolean { return this.isWebConnectivityEnabled; } getHoldouts(): Array { return Array.isArray(this.holdouts) ? this.holdouts : []; } getDevMode(): boolean { return this.devMode === true; } }