@kameleoon/javascript-sdk-core 4.3.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/CHANGELOG_INTERNAL.md +7 -0
- package/README.md +0 -2
- package/dist/clientConfiguration/clientConfiguration.d.ts +2 -2
- package/dist/clientConfiguration/clientConfiguration.js +1 -1
- package/dist/clientConfiguration/clientConfiguration.js.map +1 -1
- package/dist/clientConfiguration/constants.js +1 -1
- package/dist/clientConfiguration/constants.js.map +1 -1
- package/dist/clientConfiguration/types.d.ts +1 -2
- package/dist/clientConfiguration/types.js.map +1 -1
- package/dist/clientSettings/clientSettings.d.ts +11 -1
- package/dist/clientSettings/clientSettings.js +1 -1
- package/dist/clientSettings/clientSettings.js.map +1 -1
- package/dist/clientSettings/types.d.ts +5 -1
- package/dist/clientSettings/types.js.map +1 -1
- package/dist/eventSource/eventSource.js +1 -1
- package/dist/eventSource/eventSource.js.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +1 -1
- package/dist/kameleoonClient.js +1 -1
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonClientInterface.d.ts +1 -1
- package/dist/kameleoonClientInterface.js.map +1 -1
- package/dist/kameleoonData/dataManager.d.ts +2 -2
- package/dist/kameleoonData/dataManager.js +1 -1
- package/dist/kameleoonData/dataManager.js.map +1 -1
- package/dist/kameleoonData/dataProcessor.d.ts +2 -2
- package/dist/kameleoonData/dataProcessor.js +1 -1
- package/dist/kameleoonData/dataProcessor.js.map +1 -1
- package/dist/kameleoonData/index.d.ts +0 -1
- package/dist/kameleoonData/index.js +1 -1
- package/dist/kameleoonData/index.js.map +1 -1
- package/dist/kameleoonData/types.d.ts +1 -1
- package/dist/kameleoonData/types.js.map +1 -1
- package/dist/kameleoonError/constants.d.ts +3 -3
- package/dist/kameleoonError/constants.js +1 -1
- package/dist/kameleoonError/constants.js.map +1 -1
- package/dist/kameleoonError/kameleoonError.d.ts +2 -2
- package/dist/kameleoonError/kameleoonError.js +1 -1
- package/dist/kameleoonError/kameleoonError.js.map +1 -1
- package/dist/kameleoonUtils.d.ts +29 -5
- package/dist/kameleoonUtils.js +1 -1
- package/dist/kameleoonUtils.js.map +1 -1
- package/dist/requester/constants.d.ts +1 -8
- package/dist/requester/constants.js +1 -1
- package/dist/requester/constants.js.map +1 -1
- package/dist/requester/index.d.ts +2 -2
- package/dist/requester/index.js +1 -1
- package/dist/requester/index.js.map +1 -1
- package/dist/requester/requester.d.ts +6 -2
- package/dist/requester/requester.js +1 -1
- package/dist/requester/requester.js.map +1 -1
- package/dist/requester/types.d.ts +98 -19
- package/dist/requester/types.js +1 -1
- package/dist/requester/types.js.map +1 -1
- package/dist/requester/urlProvider.d.ts +8 -5
- package/dist/requester/urlProvider.js +1 -1
- package/dist/requester/urlProvider.js.map +1 -1
- package/dist/types.d.ts +17 -5
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/constants.d.ts +1 -0
- package/dist/utilities/constants.js +1 -1
- package/dist/utilities/constants.js.map +1 -1
- package/dist/utilities/utilities.js +1 -1
- package/dist/utilities/utilities.js.map +1 -1
- package/dist/visitorCodeManager/visitorCodeManager.js +1 -1
- package/dist/visitorCodeManager/visitorCodeManager.js.map +1 -1
- package/package.json +2 -2
- package/dist/kameleoonData/constants.d.ts +0 -4
- package/dist/kameleoonData/constants.js +0 -2
- package/dist/kameleoonData/constants.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kameleoonClient.js","names":["KameleoonClient","constructor","a","siteCode","configuration","internalConfiguration","_defineProperty","settings","clientSettings","ClientSettings","environment","externalStorage","externalEventSource","externalPackageInfo","externalVisitorCodeManager","externalRequestDispatcher","externalClientConfiguration","trackingCache","CacheManager","CACHE_CLEANUP_TIMEOUT","clientDataStorage","DataStorage","KameleoonStorageKey","ClientData","targetingDataStorage","TargetingData","variationDataStorage","VariationData","offlineTrackingStorage","OfflineTracking","consentDataStorage","ConsentData","dataManager","DataManager","storage","targetingCleanupInterval","targetingDataCleanupInterval","eventSource","KameleoonEventSource","requester","Requester","packageInfo","requestDispatcher","eventManager","EventManager","clientConfiguration","ClientConfiguration","variationConfiguration","VariationConfiguration","visitorCodeManager","initialize","useCache","result","throw","isOfflineModeOn","initialized","ok","addData","visitorCode","Utilities","validateVisitorCode","KameleoonError","KameleoonException","Initialization","b","arguments","length","data","Array","d","getRemoteVisitorData","shouldAddData","filters","DEFAULT_VISITOR_DATA_FILTERS","isUniqueIdentifier","previousVisitAmount","VisitAmount","getVisitorData","isMappingIdentifier","visitorData","storageVisitorData","visitsData","parseVisitorData","dataItem","isPersistentCustomData","trackConversion","goalId","revenue","Conversion","flush","linkedVisitor","getLinkedVisitor","index","identifierCustomDataIndex","CustomData","trackData","isConsentProvided","_isConsentProvided","unsentDataVisitors","sendOfflineTracking","visitorCodeKey","getFeatureFlags","featureFlags","resultFeatureFlags","forEach","id","featureKey","push","key","getVisitorFeatureFlags","activeVariations","_getActiveFeatureVariations","featureFlagId","getActiveFeatureFlags","resultFeatureList","Map","variation","variationKey","variationId","experimentId","variables","_getFeatureVariables","resultVariables","map","variable","parseFeatureVariable","set","getFeatureFlagVariationKey","_getFeatureVariation","getFeatureFlagVariable","variableKey","find","item","FeatureFlagVariableNotFound","type","value","getFeatureFlagVariables","parsedVariable","isFeatureFlagActive","OFF_VARIATION_KEY","err","FeatureFlagEnvironmentDisabled","getRemoteData","remoteData","getVisitorWarehouseAudience","customDataIndex","warehouseKey","RemoteData","WAREHOUSE_AUDIENCE_KEY","Object","keys","customData","onConfigurationUpdate","callback","addEventHandler","EventType","ConfigurationUpdate","onEvent","event","getEngineTrackingCode","getTrackingCode","isInitialized","setUserConsent","consent","setData","update","VisitorCode","maxAge","DEFAULT_MAX_AGE","path","PATH","consentRequired","ZERO_MAX_AGE","isConsentRequired","consentDataResult","read","featureFlag","get","FeatureFlagConfigurationNotFound","variations","FeatureFlagVariationNotFound","targetingData","getTargetingData","visitorIdentifier","getVisitorIdentifier","values","environmentEnabled","variationData","getVariation","fireEvent","Evaluation","Err","Environment","Production","withAssignment","updateCache","cacheManager","trackFeatureExperiment","featureFlagVariation","Ok","exports"],"sources":["../src/kameleoonClient.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { CacheManager } from './cacheManager';\nimport {\n ClientConfiguration,\n FeatureVariableType,\n JSONType,\n} from './clientConfiguration';\nimport { ClientSettings } from './clientSettings';\nimport {\n CACHE_CLEANUP_TIMEOUT,\n DEFAULT_VISITOR_DATA_FILTERS,\n OFF_VARIATION_KEY,\n} from './constants';\nimport {\n Conversion,\n CustomData,\n DataManager,\n KameleoonDataType,\n} from './kameleoonData';\nimport { WAREHOUSE_AUDIENCE_KEY } from './constants';\nimport { KameleoonError, KameleoonException } from './kameleoonError';\nimport { Requester } from './requester';\nimport {\n ClientDataType,\n KameleoonStorageKey,\n VariationDataType,\n DataStorage,\n ConsentDataType,\n IStorage,\n OfflineTracking,\n} from './storage';\nimport {\n TrackConversionParamsType,\n FeatureFlagType,\n GetFeatureFlagVariableParamsType,\n FeatureVariableResultType,\n SDKCoreParameters,\n TrackingCacheItemType,\n ExternalPackageInfoType,\n RemoteVisitorDataParamsType,\n GetVisitorWarehouseAudienceParamsType,\n Environment,\n SetUserConsentParametersType,\n FeatureFlagVariableType,\n KameleoonVariationType,\n GetFeatureVariablesParamsType,\n} from './types';\nimport { IVisitorCodeManager } from './visitorCodeManager';\nimport { Utilities } from './utilities';\nimport {\n FeatureFlagVariationType,\n VariationConfiguration,\n} from './variationConfiguration';\nimport { TargetingDataType } from './targeting';\nimport { EventCallbackType, EventManager, EventType } from './eventManager';\nimport { KameleoonEventSource } from './eventSource';\nimport { IKameleoonClient } from './kameleoonClientInterface';\nimport { DEFAULT_MAX_AGE, PATH, ZERO_MAX_AGE } from './visitorCodeManager';\n\n/**\n * @class\n * KameleoonClient - a class for creating kameleoon client instance\n * for communicating with Kameleoon JavaScript SDK Core, when new instance is created\n */\nexport class KameleoonClient implements IKameleoonClient {\n private variationConfiguration: VariationConfiguration;\n private clientConfiguration: ClientConfiguration;\n private dataManager: DataManager;\n private offlineTrackingStorage: IStorage<OfflineTracking>;\n private consentDataStorage: IStorage<ConsentDataType>;\n private trackingCache: CacheManager<TrackingCacheItemType>;\n private requester: Requester;\n private externalPackageInfo: ExternalPackageInfoType;\n private initialized: boolean = false;\n private visitorCodeManager: IVisitorCodeManager;\n private eventManager: EventManager;\n private environment?: Environment;\n private isOfflineModeOn?: boolean;\n\n /**\n * @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core\n */\n constructor({\n siteCode,\n configuration,\n internalConfiguration,\n }: SDKCoreParameters) {\n const { settings: clientSettings } = new ClientSettings(\n siteCode,\n configuration,\n );\n this.environment = clientSettings.environment;\n const {\n externalStorage,\n externalEventSource,\n externalPackageInfo,\n externalVisitorCodeManager,\n externalRequestDispatcher,\n externalClientConfiguration,\n } = internalConfiguration;\n const trackingCache = new CacheManager<TrackingCacheItemType>(\n CACHE_CLEANUP_TIMEOUT,\n );\n\n const clientDataStorage = new DataStorage<ClientDataType>(\n externalStorage,\n KameleoonStorageKey.ClientData,\n );\n const targetingDataStorage = new DataStorage<TargetingDataType>(\n externalStorage,\n KameleoonStorageKey.TargetingData,\n );\n const variationDataStorage = new DataStorage<VariationDataType>(\n externalStorage,\n KameleoonStorageKey.VariationData,\n );\n const offlineTrackingStorage = new DataStorage<OfflineTracking>(\n externalStorage,\n KameleoonStorageKey.OfflineTracking,\n );\n const consentDataStorage = new DataStorage<ConsentDataType>(\n externalStorage,\n KameleoonStorageKey.ConsentData,\n );\n\n const dataManager = new DataManager({\n storage: targetingDataStorage,\n targetingCleanupInterval: configuration?.targetingDataCleanupInterval,\n });\n\n const eventSource = new KameleoonEventSource(\n clientSettings.siteCode,\n externalEventSource,\n );\n\n const requester = new Requester({\n siteCode,\n environment: clientSettings.environment,\n packageInfo: externalPackageInfo,\n requestDispatcher: externalRequestDispatcher,\n });\n\n const eventManager = new EventManager();\n\n const clientConfiguration = new ClientConfiguration({\n settings: clientSettings,\n storage: clientDataStorage,\n dataManager,\n eventManager,\n requester,\n externalClientConfiguration,\n offlineTrackingStorage,\n eventSource,\n externalVisitorCodeManager,\n });\n\n const variationConfiguration = new VariationConfiguration(\n variationDataStorage,\n );\n\n this.variationConfiguration = variationConfiguration;\n this.requester = requester;\n this.trackingCache = trackingCache;\n this.dataManager = dataManager;\n this.clientConfiguration = clientConfiguration;\n this.externalPackageInfo = externalPackageInfo;\n this.offlineTrackingStorage = offlineTrackingStorage;\n this.consentDataStorage = consentDataStorage;\n this.visitorCodeManager = externalVisitorCodeManager;\n this.eventManager = eventManager;\n }\n\n public async initialize(useCache?: boolean): Promise<boolean> {\n const result = await this.clientConfiguration.initialize();\n result.throw();\n\n this.isOfflineModeOn = useCache;\n this.initialized = true;\n\n return result.ok;\n }\n\n public addData(visitorCode: string, ...data: KameleoonDataType[]): void {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n this.dataManager.addData(visitorCode, ...data).throw();\n }\n\n public async getRemoteVisitorData({\n visitorCode,\n shouldAddData = true,\n filters = DEFAULT_VISITOR_DATA_FILTERS,\n isUniqueIdentifier = false,\n }: RemoteVisitorDataParamsType): Promise<KameleoonDataType[]> {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const { previousVisitAmount } = filters;\n\n if (\n typeof previousVisitAmount === 'number' &&\n (previousVisitAmount < 1 || previousVisitAmount > 25)\n ) {\n throw new KameleoonError(KameleoonException.VisitAmount);\n }\n\n const result = await this.requester.getVisitorData({\n visitorCode,\n filters,\n isMappingIdentifier: isUniqueIdentifier,\n });\n const data = result.throw();\n\n const { visitorData, storageVisitorData, visitsData } =\n Utilities.parseVisitorData({\n data,\n filters,\n visitorCode,\n dataManager: this.dataManager,\n variationConfiguration: this.variationConfiguration,\n });\n\n for (const dataItem of storageVisitorData) {\n if (shouldAddData || this.dataManager.isPersistentCustomData(dataItem)) {\n this.addData(visitorCode, dataItem);\n }\n }\n\n // --- Note ---\n // Data on visits amount and time stamps is not returned to a user\n if (visitsData && shouldAddData) {\n this.addData(visitorCode, visitsData);\n }\n\n return visitorData;\n }\n\n public trackConversion({\n visitorCode,\n goalId,\n revenue,\n isUniqueIdentifier,\n }: TrackConversionParamsType): void {\n this.addData(visitorCode, new Conversion({ goalId, revenue }));\n this.flush(visitorCode, isUniqueIdentifier);\n }\n\n public flush(visitorCode?: string, isUniqueIdentifier?: boolean): void {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n if (typeof visitorCode === 'string') {\n Utilities.validateVisitorCode(visitorCode).throw();\n }\n\n if (visitorCode) {\n let isMappingIdentifier = false;\n\n // --- Note ---\n // This part is a workaround for Data API\n // If there's is no unique identifier for the visitor\n // We do reconciliation for visitor with himself\n if (isUniqueIdentifier) {\n const linkedVisitor = this.dataManager.getLinkedVisitor(visitorCode);\n const index = this.dataManager.identifierCustomDataIndex;\n\n if (!linkedVisitor && typeof index === 'number') {\n this.dataManager.addData(\n visitorCode,\n new CustomData(index, visitorCode),\n );\n } else {\n isMappingIdentifier = true;\n }\n }\n\n Utilities.trackData({\n visitorCode,\n isMappingIdentifier,\n dataManager: this.dataManager,\n requester: this.requester,\n isOfflineModeOn: this.isOfflineModeOn,\n isConsentProvided: this._isConsentProvided(visitorCode),\n offlineTrackingStorage: this.offlineTrackingStorage,\n });\n\n return;\n }\n\n // --- Note ---\n // `Utilities.trackData` executes `Utilities.sendOfflineTracking` asynchronously at first, but\n // we need to execute `Utilities.sendOfflineTracking` even if calling `Utilities.trackData` is skipped\n // due to lack of unsent data\n if (!this.dataManager.unsentDataVisitors.length) {\n Utilities.sendOfflineTracking({\n requester: this.requester,\n storage: this.offlineTrackingStorage,\n });\n return;\n }\n\n for (const visitorCodeKey of this.dataManager.unsentDataVisitors) {\n Utilities.trackData({\n visitorCode: visitorCodeKey,\n dataManager: this.dataManager,\n requester: this.requester,\n isOfflineModeOn: this.isOfflineModeOn,\n isConsentProvided: this._isConsentProvided(visitorCodeKey),\n offlineTrackingStorage: this.offlineTrackingStorage,\n });\n }\n }\n\n public getFeatureFlags(): FeatureFlagType[] {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n const featureFlags = this.clientConfiguration.featureFlags;\n const resultFeatureFlags: FeatureFlagType[] = [];\n\n featureFlags.forEach(({ id, featureKey }) => {\n resultFeatureFlags.push({\n id,\n key: featureKey,\n });\n });\n\n return resultFeatureFlags;\n }\n\n public getVisitorFeatureFlags(visitorCode: string): FeatureFlagType[] {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n const activeVariations = this._getActiveFeatureVariations(visitorCode);\n const resultFeatureFlags: FeatureFlagType[] = [];\n\n activeVariations.forEach(({ featureFlagId, featureKey }) => {\n resultFeatureFlags.push({\n id: featureFlagId,\n key: featureKey,\n });\n });\n\n return resultFeatureFlags;\n }\n\n public getActiveFeatureFlags(\n visitorCode: string,\n ): Map<string, KameleoonVariationType> {\n const activeVariations = this._getActiveFeatureVariations(visitorCode);\n const resultFeatureList: Map<string, KameleoonVariationType> = new Map();\n\n activeVariations.forEach((variation) => {\n const { variationKey, featureKey, variationId, experimentId } = variation;\n\n let variables: FeatureVariableType[] = [];\n\n if (variationId !== null && experimentId !== null) {\n variables = this._getFeatureVariables({\n visitorCode,\n featureKey,\n variationKey,\n });\n }\n\n const resultVariables = variables.map((variable) =>\n Utilities.parseFeatureVariable(variable).throw(),\n );\n\n resultFeatureList.set(variation.featureKey, {\n key: variationKey,\n id: variationId,\n experimentId,\n variables: resultVariables,\n });\n });\n\n return resultFeatureList;\n }\n\n public getFeatureFlagVariationKey(\n visitorCode: string,\n featureKey: string,\n ): string {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const { variationKey } = this._getFeatureVariation(\n visitorCode,\n featureKey,\n ).throw();\n\n return variationKey;\n }\n\n public getFeatureFlagVariable({\n visitorCode,\n featureKey,\n variableKey,\n }: GetFeatureFlagVariableParamsType): FeatureFlagVariableType {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const { variationKey } = this._getFeatureVariation(\n visitorCode,\n featureKey,\n ).throw();\n\n const variables = this._getFeatureVariables({\n visitorCode,\n featureKey,\n variationKey,\n });\n const variable = variables.find((item) => item.key === variableKey);\n\n if (!variable) {\n throw new KameleoonError(\n KameleoonException.FeatureFlagVariableNotFound,\n variableKey,\n visitorCode,\n );\n }\n\n const { type, value } = Utilities.parseFeatureVariable(variable).throw();\n\n return { type, value } as FeatureFlagVariableType;\n }\n\n public getFeatureFlagVariables(\n visitorCode: string,\n featureKey: string,\n ): FeatureVariableResultType[] {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const { variationKey } = this._getFeatureVariation(\n visitorCode,\n featureKey,\n ).throw();\n\n const variables = this._getFeatureVariables({\n visitorCode,\n featureKey,\n variationKey,\n });\n const resultVariables: FeatureVariableResultType[] = [];\n\n for (const variable of variables) {\n const parsedVariable = Utilities.parseFeatureVariable(variable).throw();\n resultVariables.push(parsedVariable);\n }\n\n return resultVariables;\n }\n\n public isFeatureFlagActive(visitorCode: string, featureKey: string): boolean {\n try {\n const variationKey = this.getFeatureFlagVariationKey(\n visitorCode,\n featureKey,\n );\n\n return variationKey !== OFF_VARIATION_KEY;\n } catch (err) {\n if (\n err instanceof KameleoonError &&\n err.type === KameleoonException.FeatureFlagEnvironmentDisabled\n ) {\n return false;\n }\n\n throw err;\n }\n }\n\n public async getRemoteData(key: string): Promise<JSONType> {\n const remoteData = await this.requester.getRemoteData(key);\n\n return remoteData.throw();\n }\n\n public async getVisitorWarehouseAudience({\n visitorCode,\n customDataIndex,\n warehouseKey,\n }: GetVisitorWarehouseAudienceParamsType): Promise<CustomData | null> {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const data = await this.getRemoteData(warehouseKey || visitorCode);\n\n if (!data) {\n throw new KameleoonError(KameleoonException.RemoteData);\n }\n\n if (\n !data[WAREHOUSE_AUDIENCE_KEY] ||\n Object.keys(data[WAREHOUSE_AUDIENCE_KEY]).length === 0\n ) {\n return null;\n }\n\n const customData = new CustomData(\n customDataIndex,\n ...Object.keys(data[WAREHOUSE_AUDIENCE_KEY]),\n );\n\n this.dataManager.addData(visitorCode, customData);\n\n return customData;\n }\n\n /**\n * @deprecated\n * use `onEvent(EventType.ConfigurationUpdate, callback)` instead\n * Will be removed in the next major release\n * */\n public onConfigurationUpdate(callback: () => void): void {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n this.eventManager.addEventHandler(EventType.ConfigurationUpdate, callback);\n }\n\n public onEvent<E extends EventType>(\n event: E,\n callback: EventCallbackType<E>,\n ): void {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n this.eventManager.addEventHandler(event, callback);\n }\n\n public getEngineTrackingCode(visitorCode: string): string {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n return Utilities.getTrackingCode(this.trackingCache, visitorCode);\n }\n\n public isInitialized(): boolean {\n return this.initialized;\n }\n\n protected setUserConsent({\n visitorCode,\n consent,\n setData,\n }: SetUserConsentParametersType): void {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n this.consentDataStorage.update({ [visitorCode]: consent });\n\n if (consent) {\n setData({\n visitorCode,\n key: KameleoonStorageKey.VisitorCode,\n maxAge: DEFAULT_MAX_AGE,\n path: PATH,\n });\n } else {\n if (this.visitorCodeManager.consentRequired) {\n setData({\n visitorCode: '',\n key: KameleoonStorageKey.VisitorCode,\n maxAge: ZERO_MAX_AGE,\n path: PATH,\n });\n }\n }\n }\n\n private _isConsentProvided(visitorCode: string): boolean {\n const { isConsentRequired } = this.clientConfiguration;\n const consentDataResult = this.consentDataStorage.read();\n\n return (\n !isConsentRequired ||\n (consentDataResult.ok && consentDataResult.data[visitorCode])\n );\n }\n\n private _getFeatureVariables({\n visitorCode,\n featureKey,\n variationKey,\n }: GetFeatureVariablesParamsType): FeatureVariableType[] {\n const featureFlags = this.clientConfiguration.featureFlags;\n const featureFlag = featureFlags.get(featureKey);\n\n if (!featureFlag) {\n throw new KameleoonError(\n KameleoonException.FeatureFlagConfigurationNotFound,\n featureKey,\n );\n }\n const variation = featureFlag.variations.find(\n (item) => item.key === variationKey,\n );\n\n if (!variation) {\n throw new KameleoonError(\n KameleoonException.FeatureFlagVariationNotFound,\n variationKey,\n visitorCode,\n );\n }\n\n return variation.variables;\n }\n\n private _getActiveFeatureVariations(\n visitorCode: string,\n ): FeatureFlagVariationType[] {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n const featureFlags = this.clientConfiguration.featureFlags;\n const activeVariations: FeatureFlagVariationType[] = [];\n\n const targetingData = this.dataManager.getTargetingData(visitorCode);\n const visitorIdentifier =\n this.dataManager.getVisitorIdentifier(visitorCode);\n\n for (const featureFlag of featureFlags.values()) {\n if (!featureFlag.environmentEnabled) {\n continue;\n }\n\n const variationData = this.variationConfiguration\n .getVariation({\n visitorCode,\n visitorIdentifier,\n targetingData,\n featureFlag,\n clientConfiguration: this.clientConfiguration,\n dataManager: this.dataManager,\n packageInfo: this.externalPackageInfo,\n })\n .throw();\n\n this.eventManager.fireEvent(EventType.Evaluation, {\n featureKey: featureFlag.featureKey,\n variation: {\n key: variationData.variationKey,\n experimentId: variationData.experimentId,\n id: variationData.variationId,\n },\n });\n\n if (variationData.variationKey !== OFF_VARIATION_KEY) {\n activeVariations.push(variationData);\n }\n }\n\n return activeVariations;\n }\n\n private _getFeatureVariation(\n visitorCode: string,\n featureKey: string,\n ): Result<FeatureFlagVariationType, KameleoonError> {\n if (!this.initialized) {\n return Err(new KameleoonError(KameleoonException.Initialization));\n }\n\n const featureFlags = this.clientConfiguration.featureFlags;\n const featureFlag = featureFlags.get(featureKey);\n\n if (!featureFlag) {\n return Err(\n new KameleoonError(\n KameleoonException.FeatureFlagConfigurationNotFound,\n featureKey,\n ),\n );\n }\n\n if (!featureFlag.environmentEnabled) {\n return Err(\n new KameleoonError(\n KameleoonException.FeatureFlagEnvironmentDisabled,\n featureFlag.featureKey,\n this.environment || Environment.Production,\n ),\n );\n }\n\n const targetingData = this.dataManager.getTargetingData(visitorCode);\n const visitorIdentifier =\n this.dataManager.getVisitorIdentifier(visitorCode);\n\n const variationData = this.variationConfiguration\n .getVariation({\n visitorCode,\n visitorIdentifier,\n featureFlag,\n targetingData,\n withAssignment: true,\n clientConfiguration: this.clientConfiguration,\n dataManager: this.dataManager,\n packageInfo: this.externalPackageInfo,\n })\n .throw();\n\n this.eventManager.fireEvent(EventType.Evaluation, {\n featureKey,\n variation: {\n key: variationData.variationKey,\n experimentId: variationData.experimentId,\n id: variationData.variationId,\n },\n });\n\n const { experimentId, variationId } = variationData;\n\n if (typeof variationId === 'number' && typeof experimentId === 'number') {\n Utilities.updateCache({\n cacheManager: this.trackingCache,\n visitorCode,\n experimentId,\n variationId,\n });\n }\n\n Utilities.trackFeatureExperiment({\n visitorCode,\n requester: this.requester,\n featureFlagVariation: variationData,\n dataManager: this.dataManager,\n isOfflineModeOn: this.isOfflineModeOn,\n isConsentProvided: this._isConsentProvided(visitorCode),\n offlineTrackingStorage: this.offlineTrackingStorage,\n variationConfiguration: this.variationConfiguration,\n });\n\n return Ok(variationData);\n }\n}\n"],"mappings":"+rCAgEO,KAAM,CAAAA,eAA4C,CAkBvDC,WAAWA,CAAAC,CAAA,CAIW,IAJV,CACVC,QAAQ,CAARA,CAAQ,CACRC,aAAa,CAAbA,CAAa,CACbC,qBAAqB,CAArBA,CACiB,CAAC,CAAAH,CAAA,CAAAI,eAAA,uCAAAA,eAAA,oCAAAA,eAAA,4BAAAA,eAAA,uCAAAA,eAAA,mCAAAA,eAAA,8BAAAA,eAAA,0BAAAA,eAAA,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sBAAsB,CACnDmB,sBAAsB,CAAE,IAAI,CAACA,sBAC/B,CAAC,CAAC,CAEK,GAAAwJ,SAAE,EAACZ,CAAa,CACzB,CACF,CAACa,OAAA,CAAAxM,eAAA,CAAAA,eAAA"}
|
|
1
|
+
{"version":3,"file":"kameleoonClient.js","names":["KameleoonClient","constructor","a","siteCode","configuration","internalConfiguration","_defineProperty","settings","clientSettings","ClientSettings","environment","externalStorage","externalEventSource","externalPackageInfo","externalVisitorCodeManager","externalRequester","externalClientConfiguration","trackingCache","CacheManager","CACHE_CLEANUP_TIMEOUT","clientDataStorage","DataStorage","KameleoonStorageKey","ClientData","targetingDataStorage","TargetingData","variationDataStorage","VariationData","offlineTrackingStorage","OfflineTracking","consentDataStorage","ConsentData","dataManager","DataManager","storage","cleanupInterval","requester","Requester","domain","networkDomain","packageInfo","requestTimeout","trackRetryDelay","eventSource","KameleoonEventSource","eventManager","EventManager","clientConfiguration","ClientConfiguration","updateInterval","variationConfiguration","VariationConfiguration","visitorCodeManager","initialize","useCache","result","throw","isOfflineModeOn","initialized","ok","addData","visitorCode","Utilities","validateVisitorCode","KameleoonError","KameleoonException","Initialization","b","arguments","length","data","Array","d","getRemoteVisitorData","shouldAddData","filters","DEFAULT_VISITOR_DATA_FILTERS","isUniqueIdentifier","previousVisitAmount","VisitAmount","getVisitorData","isMappingIdentifier","visitorData","storageVisitorData","visitsData","parseVisitorData","dataItem","isPersistentCustomData","trackConversion","goalId","revenue","Conversion","flush","linkedVisitor","getLinkedVisitor","index","identifierCustomDataIndex","CustomData","trackData","isConsentProvided","_isConsentProvided","unsentDataVisitors","sendOfflineTracking","visitorCodeKey","getFeatureFlags","featureFlags","resultFeatureFlags","forEach","id","featureKey","push","key","getVisitorFeatureFlags","activeVariations","_getActiveFeatureVariations","featureFlagId","getActiveFeatureFlags","resultFeatureList","Map","variation","variationKey","variationId","experimentId","variables","_getFeatureVariables","resultVariables","map","variable","parseFeatureVariable","set","getFeatureFlagVariationKey","_getFeatureVariation","getFeatureFlagVariable","variableKey","find","item","FeatureFlagVariableNotFound","type","value","getFeatureFlagVariables","parsedVariable","isFeatureFlagActive","OFF_VARIATION_KEY","err","FeatureFlagEnvironmentDisabled","getRemoteData","remoteData","getVisitorWarehouseAudience","customDataIndex","warehouseKey","RemoteData","concat","WAREHOUSE_AUDIENCE_KEY","Object","keys","customData","onConfigurationUpdate","callback","addEventHandler","EventType","ConfigurationUpdate","onEvent","event","getEngineTrackingCode","getTrackingCode","isInitialized","setUserConsent","consent","setData","update","VisitorCode","maxAge","DEFAULT_MAX_AGE","path","PATH","consentRequired","ZERO_MAX_AGE","isConsentRequired","consentDataResult","read","featureFlag","get","FeatureFlagConfigurationNotFound","variations","FeatureFlagVariationNotFound","targetingData","getTargetingData","visitorIdentifier","getVisitorIdentifier","values","environmentEnabled","variationData","getVariation","fireEvent","Evaluation","Err","withAssignment","updateCache","cacheManager","trackFeatureExperiment","featureFlagVariation","Ok","exports"],"sources":["../src/kameleoonClient.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { CacheManager } from './cacheManager';\nimport {\n ClientConfiguration,\n FeatureVariableType,\n JSONType,\n} from './clientConfiguration';\nimport { ClientSettings } from './clientSettings';\nimport {\n CACHE_CLEANUP_TIMEOUT,\n DEFAULT_VISITOR_DATA_FILTERS,\n OFF_VARIATION_KEY,\n} from './constants';\nimport {\n Conversion,\n CustomData,\n DataManager,\n KameleoonDataType,\n} from './kameleoonData';\nimport { WAREHOUSE_AUDIENCE_KEY } from './constants';\nimport { KameleoonError, KameleoonException } from './kameleoonError';\nimport { Requester } from './requester';\nimport {\n ClientDataType,\n KameleoonStorageKey,\n VariationDataType,\n DataStorage,\n ConsentDataType,\n IStorage,\n OfflineTracking,\n} from './storage';\nimport {\n TrackConversionParamsType,\n FeatureFlagType,\n GetFeatureFlagVariableParamsType,\n FeatureVariableResultType,\n SDKCoreParameters,\n TrackingCacheItemType,\n ExternalPackageInfoType,\n RemoteVisitorDataParamsType,\n GetVisitorWarehouseAudienceParamsType,\n Environment,\n SetUserConsentParametersType,\n FeatureFlagVariableType,\n KameleoonVariationType,\n GetFeatureVariablesParamsType,\n} from './types';\nimport { IVisitorCodeManager } from './visitorCodeManager';\nimport { Utilities } from './utilities';\nimport {\n FeatureFlagVariationType,\n VariationConfiguration,\n} from './variationConfiguration';\nimport { TargetingDataType } from './targeting';\nimport { EventCallbackType, EventManager, EventType } from './eventManager';\nimport { KameleoonEventSource } from './eventSource';\nimport { IKameleoonClient } from './kameleoonClientInterface';\nimport { DEFAULT_MAX_AGE, PATH, ZERO_MAX_AGE } from './visitorCodeManager';\n\n/**\n * @class\n * KameleoonClient - a class for creating kameleoon client instance\n * for communicating with Kameleoon JavaScript SDK Core, when new instance is created\n */\nexport class KameleoonClient implements IKameleoonClient {\n private variationConfiguration: VariationConfiguration;\n private clientConfiguration: ClientConfiguration;\n private dataManager: DataManager;\n private offlineTrackingStorage: IStorage<OfflineTracking>;\n private consentDataStorage: IStorage<ConsentDataType>;\n private trackingCache: CacheManager<TrackingCacheItemType>;\n private requester: Requester;\n private externalPackageInfo: ExternalPackageInfoType;\n private initialized: boolean = false;\n private visitorCodeManager: IVisitorCodeManager;\n private eventManager: EventManager;\n private environment: Environment;\n private isOfflineModeOn?: boolean;\n\n /**\n * @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core\n */\n constructor({\n siteCode,\n configuration,\n internalConfiguration,\n }: SDKCoreParameters) {\n const { settings: clientSettings } = new ClientSettings(\n siteCode,\n configuration,\n );\n this.environment = clientSettings.environment;\n const {\n externalStorage,\n externalEventSource,\n externalPackageInfo,\n externalVisitorCodeManager,\n externalRequester,\n externalClientConfiguration,\n } = internalConfiguration;\n const trackingCache = new CacheManager<TrackingCacheItemType>(\n CACHE_CLEANUP_TIMEOUT,\n );\n\n const clientDataStorage = new DataStorage<ClientDataType>(\n externalStorage,\n KameleoonStorageKey.ClientData,\n );\n const targetingDataStorage = new DataStorage<TargetingDataType>(\n externalStorage,\n KameleoonStorageKey.TargetingData,\n );\n const variationDataStorage = new DataStorage<VariationDataType>(\n externalStorage,\n KameleoonStorageKey.VariationData,\n );\n const offlineTrackingStorage = new DataStorage<OfflineTracking>(\n externalStorage,\n KameleoonStorageKey.OfflineTracking,\n );\n const consentDataStorage = new DataStorage<ConsentDataType>(\n externalStorage,\n KameleoonStorageKey.ConsentData,\n );\n\n const dataManager = new DataManager({\n storage: targetingDataStorage,\n cleanupInterval: clientSettings.cleanupInterval,\n });\n\n const requester = new Requester({\n siteCode,\n domain: clientSettings.networkDomain,\n environment: clientSettings.environment,\n packageInfo: externalPackageInfo,\n externalRequester: externalRequester,\n requestTimeout: clientSettings.requestTimeout,\n trackRetryDelay: clientSettings.trackRetryDelay,\n });\n\n const eventSource = new KameleoonEventSource(\n clientSettings.siteCode,\n externalEventSource,\n );\n\n const eventManager = new EventManager();\n\n const clientConfiguration = new ClientConfiguration({\n storage: clientDataStorage,\n updateInterval: clientSettings.updateInterval,\n dataManager,\n eventManager,\n requester,\n externalClientConfiguration,\n offlineTrackingStorage,\n eventSource,\n externalVisitorCodeManager,\n });\n\n const variationConfiguration = new VariationConfiguration(\n variationDataStorage,\n );\n\n this.variationConfiguration = variationConfiguration;\n this.requester = requester;\n this.trackingCache = trackingCache;\n this.dataManager = dataManager;\n this.clientConfiguration = clientConfiguration;\n this.externalPackageInfo = externalPackageInfo;\n this.offlineTrackingStorage = offlineTrackingStorage;\n this.consentDataStorage = consentDataStorage;\n this.visitorCodeManager = externalVisitorCodeManager;\n this.eventManager = eventManager;\n }\n\n public async initialize(useCache?: boolean): Promise<boolean> {\n const result = await this.clientConfiguration.initialize();\n result.throw();\n\n this.isOfflineModeOn = useCache;\n this.initialized = true;\n\n return result.ok;\n }\n\n public addData(visitorCode: string, ...data: KameleoonDataType[]): void {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n this.dataManager.addData(visitorCode, ...data).throw();\n }\n\n public async getRemoteVisitorData({\n visitorCode,\n shouldAddData = true,\n filters = DEFAULT_VISITOR_DATA_FILTERS,\n isUniqueIdentifier = false,\n }: RemoteVisitorDataParamsType): Promise<KameleoonDataType[]> {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const { previousVisitAmount } = filters;\n\n if (\n typeof previousVisitAmount === 'number' &&\n (previousVisitAmount < 1 || previousVisitAmount > 25)\n ) {\n throw new KameleoonError(KameleoonException.VisitAmount);\n }\n\n const result = await this.requester.getVisitorData({\n visitorCode,\n filters,\n isMappingIdentifier: isUniqueIdentifier,\n });\n const data = result.throw();\n\n const { visitorData, storageVisitorData, visitsData } =\n Utilities.parseVisitorData({\n data,\n filters,\n visitorCode,\n dataManager: this.dataManager,\n variationConfiguration: this.variationConfiguration,\n });\n\n for (const dataItem of storageVisitorData) {\n if (shouldAddData || this.dataManager.isPersistentCustomData(dataItem)) {\n this.addData(visitorCode, dataItem);\n }\n }\n\n // --- Note ---\n // Data on visits amount and time stamps is not returned to a user\n if (visitsData && shouldAddData) {\n this.addData(visitorCode, visitsData);\n }\n\n return visitorData;\n }\n\n public trackConversion({\n visitorCode,\n goalId,\n revenue,\n isUniqueIdentifier,\n }: TrackConversionParamsType): void {\n this.addData(visitorCode, new Conversion({ goalId, revenue }));\n this.flush(visitorCode, isUniqueIdentifier);\n }\n\n public flush(visitorCode?: string, isUniqueIdentifier?: boolean): void {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n if (typeof visitorCode === 'string') {\n Utilities.validateVisitorCode(visitorCode).throw();\n }\n\n if (visitorCode) {\n let isMappingIdentifier = false;\n\n // --- Note ---\n // This part is a workaround for Data API\n // If there's is no unique identifier for the visitor\n // We do reconciliation for visitor with himself\n if (isUniqueIdentifier) {\n const linkedVisitor = this.dataManager.getLinkedVisitor(visitorCode);\n const index = this.dataManager.identifierCustomDataIndex;\n\n if (!linkedVisitor && typeof index === 'number') {\n this.dataManager.addData(\n visitorCode,\n new CustomData(index, visitorCode),\n );\n } else {\n isMappingIdentifier = true;\n }\n }\n\n Utilities.trackData({\n visitorCode,\n isMappingIdentifier,\n dataManager: this.dataManager,\n requester: this.requester,\n isOfflineModeOn: this.isOfflineModeOn,\n isConsentProvided: this._isConsentProvided(visitorCode),\n offlineTrackingStorage: this.offlineTrackingStorage,\n });\n\n return;\n }\n\n // --- Note ---\n // `Utilities.trackData` executes `Utilities.sendOfflineTracking` asynchronously at first, but\n // we need to execute `Utilities.sendOfflineTracking` even if calling `Utilities.trackData` is skipped\n // due to lack of unsent data\n if (!this.dataManager.unsentDataVisitors.length) {\n Utilities.sendOfflineTracking({\n requester: this.requester,\n storage: this.offlineTrackingStorage,\n });\n return;\n }\n\n for (const visitorCodeKey of this.dataManager.unsentDataVisitors) {\n Utilities.trackData({\n visitorCode: visitorCodeKey,\n dataManager: this.dataManager,\n requester: this.requester,\n isOfflineModeOn: this.isOfflineModeOn,\n isConsentProvided: this._isConsentProvided(visitorCodeKey),\n offlineTrackingStorage: this.offlineTrackingStorage,\n });\n }\n }\n\n public getFeatureFlags(): FeatureFlagType[] {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n const featureFlags = this.clientConfiguration.featureFlags;\n const resultFeatureFlags: FeatureFlagType[] = [];\n\n featureFlags.forEach(({ id, featureKey }) => {\n resultFeatureFlags.push({\n id,\n key: featureKey,\n });\n });\n\n return resultFeatureFlags;\n }\n\n public getVisitorFeatureFlags(visitorCode: string): FeatureFlagType[] {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n const activeVariations = this._getActiveFeatureVariations(visitorCode);\n const resultFeatureFlags: FeatureFlagType[] = [];\n\n activeVariations.forEach(({ featureFlagId, featureKey }) => {\n resultFeatureFlags.push({\n id: featureFlagId,\n key: featureKey,\n });\n });\n\n return resultFeatureFlags;\n }\n\n public getActiveFeatureFlags(\n visitorCode: string,\n ): Map<string, KameleoonVariationType> {\n const activeVariations = this._getActiveFeatureVariations(visitorCode);\n const resultFeatureList: Map<string, KameleoonVariationType> = new Map();\n\n activeVariations.forEach((variation) => {\n const { variationKey, featureKey, variationId, experimentId } = variation;\n\n let variables: FeatureVariableType[] = [];\n\n if (variationId !== null && experimentId !== null) {\n variables = this._getFeatureVariables({\n visitorCode,\n featureKey,\n variationKey,\n });\n }\n\n const resultVariables = variables.map((variable) =>\n Utilities.parseFeatureVariable(variable).throw(),\n );\n\n resultFeatureList.set(variation.featureKey, {\n key: variationKey,\n id: variationId,\n experimentId,\n variables: resultVariables,\n });\n });\n\n return resultFeatureList;\n }\n\n public getFeatureFlagVariationKey(\n visitorCode: string,\n featureKey: string,\n ): string {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const { variationKey } = this._getFeatureVariation(\n visitorCode,\n featureKey,\n ).throw();\n\n return variationKey;\n }\n\n public getFeatureFlagVariable({\n visitorCode,\n featureKey,\n variableKey,\n }: GetFeatureFlagVariableParamsType): FeatureFlagVariableType {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const { variationKey } = this._getFeatureVariation(\n visitorCode,\n featureKey,\n ).throw();\n\n const variables = this._getFeatureVariables({\n visitorCode,\n featureKey,\n variationKey,\n });\n const variable = variables.find((item) => item.key === variableKey);\n\n if (!variable) {\n throw new KameleoonError(\n KameleoonException.FeatureFlagVariableNotFound,\n variableKey,\n visitorCode,\n );\n }\n\n const { type, value } = Utilities.parseFeatureVariable(variable).throw();\n\n return { type, value } as FeatureFlagVariableType;\n }\n\n public getFeatureFlagVariables(\n visitorCode: string,\n featureKey: string,\n ): FeatureVariableResultType[] {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const { variationKey } = this._getFeatureVariation(\n visitorCode,\n featureKey,\n ).throw();\n\n const variables = this._getFeatureVariables({\n visitorCode,\n featureKey,\n variationKey,\n });\n const resultVariables: FeatureVariableResultType[] = [];\n\n for (const variable of variables) {\n const parsedVariable = Utilities.parseFeatureVariable(variable).throw();\n resultVariables.push(parsedVariable);\n }\n\n return resultVariables;\n }\n\n public isFeatureFlagActive(visitorCode: string, featureKey: string): boolean {\n try {\n const variationKey = this.getFeatureFlagVariationKey(\n visitorCode,\n featureKey,\n );\n\n return variationKey !== OFF_VARIATION_KEY;\n } catch (err) {\n if (\n err instanceof KameleoonError &&\n err.type === KameleoonException.FeatureFlagEnvironmentDisabled\n ) {\n return false;\n }\n\n throw err;\n }\n }\n\n public async getRemoteData(key: string): Promise<JSONType> {\n const remoteData = await this.requester.getRemoteData(key);\n\n return remoteData.throw();\n }\n\n public async getVisitorWarehouseAudience({\n visitorCode,\n customDataIndex,\n warehouseKey,\n }: GetVisitorWarehouseAudienceParamsType): Promise<CustomData | null> {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n const data = await this.getRemoteData(warehouseKey || visitorCode);\n\n if (!data) {\n throw new KameleoonError(\n KameleoonException.RemoteData,\n `No data found for ${warehouseKey || visitorCode} key`,\n );\n }\n\n if (\n !data[WAREHOUSE_AUDIENCE_KEY] ||\n Object.keys(data[WAREHOUSE_AUDIENCE_KEY]).length === 0\n ) {\n return null;\n }\n\n const customData = new CustomData(\n customDataIndex,\n ...Object.keys(data[WAREHOUSE_AUDIENCE_KEY]),\n );\n\n this.dataManager.addData(visitorCode, customData);\n\n return customData;\n }\n\n /**\n * @deprecated\n * use `onEvent(EventType.ConfigurationUpdate, callback)` instead\n * Will be removed in the next major release\n * */\n public onConfigurationUpdate(callback: () => void): void {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n this.eventManager.addEventHandler(EventType.ConfigurationUpdate, callback);\n }\n\n public onEvent<E extends EventType>(\n event: E,\n callback: EventCallbackType<E>,\n ): void {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n this.eventManager.addEventHandler(event, callback);\n }\n\n public getEngineTrackingCode(visitorCode: string): string {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n return Utilities.getTrackingCode(this.trackingCache, visitorCode);\n }\n\n public isInitialized(): boolean {\n return this.initialized;\n }\n\n protected setUserConsent({\n visitorCode,\n consent,\n setData,\n }: SetUserConsentParametersType): void {\n Utilities.validateVisitorCode(visitorCode).throw();\n\n this.consentDataStorage.update({ [visitorCode]: consent });\n\n if (consent) {\n setData({\n visitorCode,\n key: KameleoonStorageKey.VisitorCode,\n maxAge: DEFAULT_MAX_AGE,\n path: PATH,\n });\n } else {\n if (this.visitorCodeManager.consentRequired) {\n setData({\n visitorCode: '',\n key: KameleoonStorageKey.VisitorCode,\n maxAge: ZERO_MAX_AGE,\n path: PATH,\n });\n }\n }\n }\n\n private _isConsentProvided(visitorCode: string): boolean {\n const { isConsentRequired } = this.clientConfiguration;\n const consentDataResult = this.consentDataStorage.read();\n\n return (\n !isConsentRequired ||\n (consentDataResult.ok && consentDataResult.data[visitorCode])\n );\n }\n\n private _getFeatureVariables({\n visitorCode,\n featureKey,\n variationKey,\n }: GetFeatureVariablesParamsType): FeatureVariableType[] {\n const featureFlags = this.clientConfiguration.featureFlags;\n const featureFlag = featureFlags.get(featureKey);\n\n if (!featureFlag) {\n throw new KameleoonError(\n KameleoonException.FeatureFlagConfigurationNotFound,\n featureKey,\n );\n }\n const variation = featureFlag.variations.find(\n (item) => item.key === variationKey,\n );\n\n if (!variation) {\n throw new KameleoonError(\n KameleoonException.FeatureFlagVariationNotFound,\n variationKey,\n visitorCode,\n );\n }\n\n return variation.variables;\n }\n\n private _getActiveFeatureVariations(\n visitorCode: string,\n ): FeatureFlagVariationType[] {\n if (!this.initialized) {\n throw new KameleoonError(KameleoonException.Initialization);\n }\n\n const featureFlags = this.clientConfiguration.featureFlags;\n const activeVariations: FeatureFlagVariationType[] = [];\n\n const targetingData = this.dataManager.getTargetingData(visitorCode);\n const visitorIdentifier =\n this.dataManager.getVisitorIdentifier(visitorCode);\n\n for (const featureFlag of featureFlags.values()) {\n if (!featureFlag.environmentEnabled) {\n continue;\n }\n\n const variationData = this.variationConfiguration\n .getVariation({\n visitorCode,\n visitorIdentifier,\n targetingData,\n featureFlag,\n clientConfiguration: this.clientConfiguration,\n dataManager: this.dataManager,\n packageInfo: this.externalPackageInfo,\n })\n .throw();\n\n this.eventManager.fireEvent(EventType.Evaluation, {\n featureKey: featureFlag.featureKey,\n variation: {\n key: variationData.variationKey,\n experimentId: variationData.experimentId,\n id: variationData.variationId,\n },\n });\n\n if (variationData.variationKey !== OFF_VARIATION_KEY) {\n activeVariations.push(variationData);\n }\n }\n\n return activeVariations;\n }\n\n private _getFeatureVariation(\n visitorCode: string,\n featureKey: string,\n ): Result<FeatureFlagVariationType, KameleoonError> {\n if (!this.initialized) {\n return Err(new KameleoonError(KameleoonException.Initialization));\n }\n\n const featureFlags = this.clientConfiguration.featureFlags;\n const featureFlag = featureFlags.get(featureKey);\n\n if (!featureFlag) {\n return Err(\n new KameleoonError(\n KameleoonException.FeatureFlagConfigurationNotFound,\n featureKey,\n ),\n );\n }\n\n if (!featureFlag.environmentEnabled) {\n return Err(\n new KameleoonError(\n KameleoonException.FeatureFlagEnvironmentDisabled,\n featureFlag.featureKey,\n this.environment,\n ),\n );\n }\n\n const targetingData = this.dataManager.getTargetingData(visitorCode);\n const visitorIdentifier =\n this.dataManager.getVisitorIdentifier(visitorCode);\n\n const variationData = this.variationConfiguration\n .getVariation({\n visitorCode,\n visitorIdentifier,\n featureFlag,\n targetingData,\n withAssignment: true,\n clientConfiguration: this.clientConfiguration,\n dataManager: this.dataManager,\n packageInfo: this.externalPackageInfo,\n })\n .throw();\n\n this.eventManager.fireEvent(EventType.Evaluation, {\n featureKey,\n variation: {\n key: variationData.variationKey,\n experimentId: variationData.experimentId,\n id: variationData.variationId,\n },\n });\n\n const { experimentId, variationId } = variationData;\n\n if (typeof variationId === 'number' && typeof experimentId === 'number') {\n Utilities.updateCache({\n cacheManager: this.trackingCache,\n visitorCode,\n experimentId,\n variationId,\n });\n }\n\n Utilities.trackFeatureExperiment({\n visitorCode,\n requester: this.requester,\n featureFlagVariation: variationData,\n dataManager: this.dataManager,\n isOfflineModeOn: this.isOfflineModeOn,\n isConsentProvided: this._isConsentProvided(visitorCode),\n offlineTrackingStorage: this.offlineTrackingStorage,\n variationConfiguration: this.variationConfiguration,\n });\n\n return Ok(variationData);\n }\n}\n"],"mappings":"qqCAgEO,KAAM,CAAAA,eAA4C,CAkBvDC,WAAWA,CAAAC,CAAA,CAIW,IAJV,CACVC,QAAQ,CAARA,CAAQ,CACRC,aAAa,CAAbA,CAAa,CACbC,qBAAqB,CAArBA,CACiB,CAAC,CAAAH,CAAA,CAAAI,eAAA,uCAAAA,eAAA,oCAAAA,eAAA,4BAAAA,eAAA,uCAAAA,eAAA,mCAAAA,eAAA,8BAAAA,eAAA,0BAAAA,eAAA,oCAAAA,eAAA,wBAAAA,eAAA,mCAAAA,eAAA,6BAAAA,eAAA,4BAAAA,eAAA,gCAClB,KAAM,CAAEC,QAAQ,CAAEC,CAAe,CAAC,CAAG,GAAI,CAAAC,8BAAc,CACrDN,CAAQ,CACRC,CACF,CAAC,CACD,IAAI,CAACM,WAAW,CAAGF,CAAc,CAACE,WAAW,MACvC,CACJC,eAAe,CAAfA,CAAe,CACfC,mBAAmB,CAAnBA,CAAmB,CACnBC,mBAAmB,CAAnBA,CAAmB,CACnBC,0BAA0B,CAA1BA,CAA0B,CAC1BC,iBAAiB,CAAjBA,CAAiB,CACjBC,2BAA2B,CAA3BA,CACF,CAAC,CAAGX,CAAqB,CACnBY,CAAa,CAAG,GAAI,CAAAC,0BAAY,CACpCC,gCACF,CAAC,CAEKC,CAAiB,CAAG,GAAI,CAAAC,oBAAW,CACvCV,CAAe,CACfW,4BAAmB,CAACC,UACtB,CAAC,CACKC,CAAoB,CAAG,GAAI,CAAAH,oBAAW,CAC1CV,CAAe,CACfW,4BAAmB,CAACG,aACtB,CAAC,CACKC,CAAoB,CAAG,GAAI,CAAAL,oBAAW,CAC1CV,CAAe,CACfW,4BAAmB,CAACK,aACtB,CAAC,C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,YAAY,CAAZA,CAAY,CAAED,WAAW,CAAXA,CAAY,CAAC,CAAGsE,CAAa,CAsBnD,MApB2B,QAAQ,EAA/B,MAAO,CAAAtE,CAAwB,EAA4B,QAAQ,EAAhC,MAAO,CAAAC,CAAyB,EACrE5D,oBAAS,CAACuI,WAAW,CAAC,CACpBC,YAAY,CAAE,IAAI,CAACrL,aAAa,CAChC4C,WAAW,CAAXA,CAAW,CACX6D,YAAY,CAAZA,CAAY,CACZD,WAAW,CAAXA,CACF,CAAC,CAAC,CAGJ3D,oBAAS,CAACyI,sBAAsB,CAAC,CAC/B1I,WAAW,CAAXA,CAAW,CACXzB,SAAS,CAAE,IAAI,CAACA,SAAS,CACzBoK,oBAAoB,CAAET,CAAa,CACnC/J,WAAW,CAAE,IAAI,CAACA,WAAW,CAC7ByB,eAAe,CAAE,IAAI,CAACA,eAAe,CACrC0C,iBAAiB,CAAE,IAAI,CAACC,kBAAkB,CAACvC,CAAW,CAAC,CACvDjC,sBAAsB,CAAE,IAAI,CAACA,sBAAsB,CACnDsB,sBAAsB,CAAE,IAAI,CAACA,sBAC/B,CAAC,CAAC,CAEK,GAAAuJ,SAAE,EAACV,CAAa,CACzB,CACF,CAACW,OAAA,CAAA1M,eAAA,CAAAA,eAAA"}
|
|
@@ -256,5 +256,5 @@ export interface IKameleoonClient {
|
|
|
256
256
|
*
|
|
257
257
|
* - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
|
|
258
258
|
*/
|
|
259
|
-
onEvent: (event:
|
|
259
|
+
onEvent: <E extends EventType>(event: E, callback: EventCallbackType<E>) => void;
|
|
260
260
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kameleoonClientInterface.js","names":[],"sources":["../src/kameleoonClientInterface.ts"],"sourcesContent":["import { JSONType } from './clientConfiguration';\nimport { EventCallbackType, EventType } from './eventManager';\nimport { CustomData, KameleoonDataType } from './kameleoonData';\nimport {\n FeatureFlagType,\n FeatureFlagVariableType,\n FeatureVariableResultType,\n GetFeatureFlagVariableParamsType,\n GetVisitorWarehouseAudienceParamsType,\n KameleoonVariationType,\n RemoteVisitorDataParamsType,\n TrackConversionParamsType,\n} from './types';\n\n/**\n * @interface an interface of KameleoonClient instance\n */\nexport interface IKameleoonClient {\n /**\n * @method initialize - an asynchronous method for KameleoonClient initialization by fetching Kameleoon SDK related data from server or by retrieving data from local source if data is up-to-date or update interval has not been reached\n *\n * Triggered Events: `EventType.ConfigurationUpdate` (On each successful configuration update while using Real Time Update)\n *\n * @param {boolean | undefined} useCache - optional parameter for activating SDK offline mode, if `true` is passed failed polls will not return error and will use cached data if such data is available, default value is `false`. Note: if offline mode is on, SDK will still try to retrieve the latest data.\n * @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n * - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api\n * - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed\n */\n initialize(useCache?: boolean): Promise<boolean>;\n initialize(): Promise<boolean>;\n /**\n * @method addData - method for adding targeting data to the storage so that other methods could decide whether the current visitor is targeted or not. Note: userAgent data will not be stored in storage like other data, and it will be sent with every tracking request for bot filtration.\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {KameleoonDataType[]} kameleoonData - number of instances of any type of `KameleoonData`, can be added solely in array or as a sequential arguments\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;\n /**\n * @method getRemoteVisitorData - an asynchronous method for retrieving KameleoonData from Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.\n * @param {RemoteVisitorDataParamsType} remoteVisitorDataParameters - `visitorCode`, `shouldAddData`, `filters` and `isUniqueIdentifier` parameters\n * @returns {KameleoonDataType[]} promise resolved to an array of `KameleoonData` instances, only includes custom data\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n * - `KameleoonException.VisitAmount` - Visit amount must be a number between 1 and 25\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n getRemoteVisitorData: ({\n visitorCode,\n shouldAddData,\n filters,\n isUniqueIdentifier,\n }: RemoteVisitorDataParamsType) => Promise<KameleoonDataType[]>;\n /**\n * @method trackConversion - creates and adds `Conversion` data to the visitor with specified parameters and executes `flush`. Note: it's a helper method for the quick and convenient conversion tracking, however creating and adding `Conversion` manually allows more flexible `Conversion` with `negative` parameter\n * @param {TrackConversionParamsType} conversionParameters - `visitorCode`, `goalId` and `revenue` parameters for data tracking\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n */\n trackConversion: ({\n visitorCode,\n goalId,\n revenue,\n isUniqueIdentifier,\n }: TrackConversionParamsType) => void;\n /**\n * @method flush - takes visitor associated kameleoon data and sends the data tracking request with collected data,\n * sent data is removed from `KameleoonClient` instance but not from the storage for correct targeting checks. If no visitor is passed,\n * then data for all visitors is sent and removed from `KameleoonClient` instance. Moreover, regardless of visitor code input\n * the method first attempts to send all previously failed tracking requests which were stored locally during the offline mode.\n * @param {string | undefined} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {boolean | undefined} isUniqueIdentifier - an optional parameter for specifying if the visitorCode is a unique identifier, default value is `false`\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n flush: (visitorCode?: string, isUniqueIdentifier?: boolean) => void;\n /**\n * @method getFeatureFlags - returns a list of feature flags stored in the client configuration\n *\n * Note: This method **doesn't send** tracking data\n *\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n getFeatureFlags: () => FeatureFlagType[];\n /**\n * @method getVisitorFeatureFlags - returns a list of feature flags that the visitor with `visitorCode` that is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated).\n *\n * Note: This method **doesn't send** tracking data\n * Triggered Events: `EventType.Evaluation` (For each feature flag evaluated)\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`\n * - `KameleoonException.StorageRead` - Couldn't read storage data\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n getVisitorFeatureFlags: (visitorCode: string) => FeatureFlagType[];\n /**\n * @method getActiveFeatureFlags - method collecting all active feature flags information including it's variation and variables for the visitor\n *\n * Note: This method **doesn't send** tracking data\n * Triggered Events: `EventType.Evaluation` (For each feature flag evaluated)\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {Map<string, KameleoonVariationType>} a map of feature flags with `featureKey` as a key and `KameleoonVariationType` as a value\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`\n * - `KameleoonException.StorageRead` - Couldn't read storage data\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getActiveFeatureFlags: (\n visitorCode: string,\n ) => Map<string, KameleoonVariationType>;\n /**\n * @method isFeatureFlagActive - returns a boolean indicating whether the visitor with `visitorCode` has `featureKey` active for him, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request\n *\n * Note: This method **sends** tracking data\n * Triggered Events: `EventType.Evaluation`\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {string} featureKey - a unique key for feature flag\n * @returns {boolean} a boolean indicator of whether the feature flag with `featureKey` is active for visitor with `visitorCode`\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.DataInconsistency` - Allocated variation was found but there is no feature flag with according `featureKey`.\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n isFeatureFlagActive: (visitorCode: string, featureKey: string) => boolean;\n /**\n * @method getFeatureFlagVariationKey - returns variation key for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request\n *\n * Note: This method **sends** tracking data\n * Triggered Events: `EventType.Evaluation`\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {string} featureKey - a unique key for feature flag\n * @returns {string} a string containing variable key for the allocated feature flag variation for the provided visitor\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n getFeatureFlagVariationKey: (\n visitorCode: string,\n featureKey: string,\n ) => string;\n /**\n * @method getFeatureFlagVariable - returns a variable for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request\n *\n * Note: This method **sends** tracking data\n * Triggered Events: `EventType.Evaluation`\n *\n * @param {GetFeatureFlagVariableParamsType} parameters - an object with parameters of a type `GetFeatureFlagVariableParamsType`, see the type for details.\n * @returns {FeatureFlagVariableType} a variable object containing `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagVariableNotFound` - No feature variable was found for provided `visitorCode` and `variableKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getFeatureFlagVariable: ({\n visitorCode,\n featureKey,\n variableKey,\n }: GetFeatureFlagVariableParamsType) => FeatureFlagVariableType;\n /**\n * @method getFeatureFlagVariables - returns a list of variables for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request\n *\n * Note: This method **sends** tracking data\n * Triggered Events: `EventType.Evaluation`\n *\n * @param {string} visitorCode - a unique visitor identifier, shouldn't exceed 255 characters\n * @param {string} featureKey - a unique key for feature flag\n * @returns {FeatureVariableResultType[]} a list of variable objects containing `key`, `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagVariationNotFound` - No feature variation was found for provided `visitorCode` and `variationKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getFeatureFlagVariables: (\n visitorCode: string,\n featureKey: string,\n ) => FeatureVariableResultType[];\n /**\n * @method getRemoteData - returns a data which is stored for specified siteCode on a remote Kameleoon server.\n * @param {string} key - unique key that the data you try to get is associated with.\n * @returns {JSONType} - promise with retrieving data for specific key.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getRemoteData: (key: string) => Promise<JSONType>;\n /**\n * @method getVisitorWarehouseAudience - an async method that returns a `CustomData` instance, containing data associated with a visitor's warehouse audiences\n * which is stored for specified visitorCode on a remote Kameleoon server.\n * Retrieved data will be added to storage under the specified `customDataIndex`\n * @param {GetVisitorWarehouseAudienceParamsType} parameters - an object with parameters of a type `GetVisitorWarehouseAudienceParamsType`, see the type for details.\n * @returns {Promise<CustomData | null>} `Promise` containing an instance of `CustomData` containing data associated with a visitor's warehouse audiences or `null` if the data was retrieved successfully but nothing was found under the specified `warehouseKey`\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` - The visitor code is empty\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getVisitorWarehouseAudience: ({\n visitorCode,\n customDataIndex,\n warehouseKey,\n }: GetVisitorWarehouseAudienceParamsType) => Promise<CustomData | null>;\n /**\n * @method getEngineTrackingCode - returns Kameleoon tracking code for the current visitor. Tracking code is built of the experiments that were triggered and feature flag variations that were assigned during the last 5 seconds\n * See [Kameleoon Automation API](https://developers.kameleoon.com/apis/activation-api-js/api-reference#trigger-1) for the details\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {string} Kameleoon tracking code\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n */\n getEngineTrackingCode: (visitorCode: string) => string;\n /**\n * @method onConfigurationUpdate - fires a callback on client configuration update. Note: this method only works for server sent events of real time update.\n * @param {() => void} callback - callback function with no parameters that will be called upon configuration update\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n onConfigurationUpdate: (callback: () => void) => void;\n /**\n * @method onEvent - fires a callback on a specified Kameleoon `EventType`. Each event can only have one according callback.\n *\n * Note: SDK methods are marked with the `EventType` they trigger if any.\n *\n * @param {EventCallbackType<EventType>} callback - callback function with parameters that will be called upon event\n *\n * Parameter type depends on the `EventType` passed:\n * - `EventType.Evaluation` - `EvaluationEventDataType`\n * - `EventType.ConfigurationUpdate` - `ConfigurationUpdateEventDataType`\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n onEvent: (event: EventType, callback: EventCallbackType<EventType>) => void;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"kameleoonClientInterface.js","names":[],"sources":["../src/kameleoonClientInterface.ts"],"sourcesContent":["import { JSONType } from './clientConfiguration';\nimport { EventCallbackType, EventType } from './eventManager';\nimport { CustomData, KameleoonDataType } from './kameleoonData';\nimport {\n FeatureFlagType,\n FeatureFlagVariableType,\n FeatureVariableResultType,\n GetFeatureFlagVariableParamsType,\n GetVisitorWarehouseAudienceParamsType,\n KameleoonVariationType,\n RemoteVisitorDataParamsType,\n TrackConversionParamsType,\n} from './types';\n\n/**\n * @interface an interface of KameleoonClient instance\n */\nexport interface IKameleoonClient {\n /**\n * @method initialize - an asynchronous method for KameleoonClient initialization by fetching Kameleoon SDK related data from server or by retrieving data from local source if data is up-to-date or update interval has not been reached\n *\n * Triggered Events: `EventType.ConfigurationUpdate` (On each successful configuration update while using Real Time Update)\n *\n * @param {boolean | undefined} useCache - optional parameter for activating SDK offline mode, if `true` is passed failed polls will not return error and will use cached data if such data is available, default value is `false`. Note: if offline mode is on, SDK will still try to retrieve the latest data.\n * @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n * - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api\n * - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed\n */\n initialize(useCache?: boolean): Promise<boolean>;\n initialize(): Promise<boolean>;\n /**\n * @method addData - method for adding targeting data to the storage so that other methods could decide whether the current visitor is targeted or not. Note: userAgent data will not be stored in storage like other data, and it will be sent with every tracking request for bot filtration.\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {KameleoonDataType[]} kameleoonData - number of instances of any type of `KameleoonData`, can be added solely in array or as a sequential arguments\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;\n /**\n * @method getRemoteVisitorData - an asynchronous method for retrieving KameleoonData from Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.\n * @param {RemoteVisitorDataParamsType} remoteVisitorDataParameters - `visitorCode`, `shouldAddData`, `filters` and `isUniqueIdentifier` parameters\n * @returns {KameleoonDataType[]} promise resolved to an array of `KameleoonData` instances, only includes custom data\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n * - `KameleoonException.VisitAmount` - Visit amount must be a number between 1 and 25\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n getRemoteVisitorData: ({\n visitorCode,\n shouldAddData,\n filters,\n isUniqueIdentifier,\n }: RemoteVisitorDataParamsType) => Promise<KameleoonDataType[]>;\n /**\n * @method trackConversion - creates and adds `Conversion` data to the visitor with specified parameters and executes `flush`. Note: it's a helper method for the quick and convenient conversion tracking, however creating and adding `Conversion` manually allows more flexible `Conversion` with `negative` parameter\n * @param {TrackConversionParamsType} conversionParameters - `visitorCode`, `goalId` and `revenue` parameters for data tracking\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.StorageWrite` Couldn't update storage data\n */\n trackConversion: ({\n visitorCode,\n goalId,\n revenue,\n isUniqueIdentifier,\n }: TrackConversionParamsType) => void;\n /**\n * @method flush - takes visitor associated kameleoon data and sends the data tracking request with collected data,\n * sent data is removed from `KameleoonClient` instance but not from the storage for correct targeting checks. If no visitor is passed,\n * then data for all visitors is sent and removed from `KameleoonClient` instance. Moreover, regardless of visitor code input\n * the method first attempts to send all previously failed tracking requests which were stored locally during the offline mode.\n * @param {string | undefined} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {boolean | undefined} isUniqueIdentifier - an optional parameter for specifying if the visitorCode is a unique identifier, default value is `false`\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n flush: (visitorCode?: string, isUniqueIdentifier?: boolean) => void;\n /**\n * @method getFeatureFlags - returns a list of feature flags stored in the client configuration\n *\n * Note: This method **doesn't send** tracking data\n *\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n getFeatureFlags: () => FeatureFlagType[];\n /**\n * @method getVisitorFeatureFlags - returns a list of feature flags that the visitor with `visitorCode` that is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated).\n *\n * Note: This method **doesn't send** tracking data\n * Triggered Events: `EventType.Evaluation` (For each feature flag evaluated)\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`\n * - `KameleoonException.StorageRead` - Couldn't read storage data\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n getVisitorFeatureFlags: (visitorCode: string) => FeatureFlagType[];\n /**\n * @method getActiveFeatureFlags - method collecting all active feature flags information including it's variation and variables for the visitor\n *\n * Note: This method **doesn't send** tracking data\n * Triggered Events: `EventType.Evaluation` (For each feature flag evaluated)\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {Map<string, KameleoonVariationType>} a map of feature flags with `featureKey` as a key and `KameleoonVariationType` as a value\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`\n * - `KameleoonException.StorageRead` - Couldn't read storage data\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getActiveFeatureFlags: (\n visitorCode: string,\n ) => Map<string, KameleoonVariationType>;\n /**\n * @method isFeatureFlagActive - returns a boolean indicating whether the visitor with `visitorCode` has `featureKey` active for him, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request\n *\n * Note: This method **sends** tracking data\n * Triggered Events: `EventType.Evaluation`\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {string} featureKey - a unique key for feature flag\n * @returns {boolean} a boolean indicator of whether the feature flag with `featureKey` is active for visitor with `visitorCode`\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.DataInconsistency` - Allocated variation was found but there is no feature flag with according `featureKey`.\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n isFeatureFlagActive: (visitorCode: string, featureKey: string) => boolean;\n /**\n * @method getFeatureFlagVariationKey - returns variation key for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request\n *\n * Note: This method **sends** tracking data\n * Triggered Events: `EventType.Evaluation`\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {string} featureKey - a unique key for feature flag\n * @returns {string} a string containing variable key for the allocated feature flag variation for the provided visitor\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n */\n getFeatureFlagVariationKey: (\n visitorCode: string,\n featureKey: string,\n ) => string;\n /**\n * @method getFeatureFlagVariable - returns a variable for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request\n *\n * Note: This method **sends** tracking data\n * Triggered Events: `EventType.Evaluation`\n *\n * @param {GetFeatureFlagVariableParamsType} parameters - an object with parameters of a type `GetFeatureFlagVariableParamsType`, see the type for details.\n * @returns {FeatureFlagVariableType} a variable object containing `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagVariableNotFound` - No feature variable was found for provided `visitorCode` and `variableKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getFeatureFlagVariable: ({\n visitorCode,\n featureKey,\n variableKey,\n }: GetFeatureFlagVariableParamsType) => FeatureFlagVariableType;\n /**\n * @method getFeatureFlagVariables - returns a list of variables for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request\n *\n * Note: This method **sends** tracking data\n * Triggered Events: `EventType.Evaluation`\n *\n * @param {string} visitorCode - a unique visitor identifier, shouldn't exceed 255 characters\n * @param {string} featureKey - a unique key for feature flag\n * @returns {FeatureVariableResultType[]} a list of variable objects containing `key`, `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`\n * - `KameleoonException.FeatureFlagVariationNotFound` - No feature variation was found for provided `visitorCode` and `variationKey`\n * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment\n * - `KameleoonException.JSONParse` - Couldn't parse JSON value\n * - `KameleoonException.NumberParse` - Couldn't parse Number value\n */\n getFeatureFlagVariables: (\n visitorCode: string,\n featureKey: string,\n ) => FeatureVariableResultType[];\n /**\n * @method getRemoteData - returns a data which is stored for specified siteCode on a remote Kameleoon server.\n * @param {string} key - unique key that the data you try to get is associated with.\n * @returns {JSONType} - promise with retrieving data for specific key.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getRemoteData: (key: string) => Promise<JSONType>;\n /**\n * @method getVisitorWarehouseAudience - an async method that returns a `CustomData` instance, containing data associated with a visitor's warehouse audiences\n * which is stored for specified visitorCode on a remote Kameleoon server.\n * Retrieved data will be added to storage under the specified `customDataIndex`\n * @param {GetVisitorWarehouseAudienceParamsType} parameters - an object with parameters of a type `GetVisitorWarehouseAudienceParamsType`, see the type for details.\n * @returns {Promise<CustomData | null>} `Promise` containing an instance of `CustomData` containing data associated with a visitor's warehouse audiences or `null` if the data was retrieved successfully but nothing was found under the specified `warehouseKey`\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` - The visitor code is empty\n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server\n */\n getVisitorWarehouseAudience: ({\n visitorCode,\n customDataIndex,\n warehouseKey,\n }: GetVisitorWarehouseAudienceParamsType) => Promise<CustomData | null>;\n /**\n * @method getEngineTrackingCode - returns Kameleoon tracking code for the current visitor. Tracking code is built of the experiments that were triggered and feature flag variations that were assigned during the last 5 seconds\n * See [Kameleoon Automation API](https://developers.kameleoon.com/apis/activation-api-js/api-reference#trigger-1) for the details\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @returns {string} Kameleoon tracking code\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded\n * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty\n */\n getEngineTrackingCode: (visitorCode: string) => string;\n /**\n * @method onConfigurationUpdate - fires a callback on client configuration update. Note: this method only works for server sent events of real time update.\n * @param {() => void} callback - callback function with no parameters that will be called upon configuration update\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n onConfigurationUpdate: (callback: () => void) => void;\n /**\n * @method onEvent - fires a callback on a specified Kameleoon `EventType`. Each event can only have one according callback.\n *\n * Note: SDK methods are marked with the `EventType` they trigger if any.\n *\n * @param {EventCallbackType<EventType>} callback - callback function with parameters that will be called upon event\n *\n * Parameter type depends on the `EventType` passed:\n * - `EventType.Evaluation` - `EvaluationEventDataType`\n * - `EventType.ConfigurationUpdate` - `ConfigurationUpdateEventDataType`\n * @returns {void}\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call\n */\n onEvent: <E extends EventType>(\n event: E,\n callback: EventCallbackType<E>,\n ) => void;\n}\n"],"mappings":""}
|
|
@@ -22,11 +22,11 @@ export declare class DataManager implements IDataManager {
|
|
|
22
22
|
private localCustomDataIndexes;
|
|
23
23
|
private persistentCustomDataIndexes;
|
|
24
24
|
private mappingIdentifierCustomDataIndex;
|
|
25
|
-
private
|
|
25
|
+
private cleanupIntervalId;
|
|
26
26
|
private dataProcessor;
|
|
27
27
|
private unsentData;
|
|
28
28
|
private sentPageViewTimestamps;
|
|
29
|
-
constructor({ storage,
|
|
29
|
+
constructor({ storage, cleanupInterval }: DataManagerParametersType);
|
|
30
30
|
addData(visitorCode: string, ...kameleoonData: KameleoonDataType[]): Result<void, KameleoonError>;
|
|
31
31
|
getTree(segment: SegmentType): Tree;
|
|
32
32
|
clearTrees(): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _tsRes=require("ts-res"),_targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_utilities=require("../utilities"),_clientConfiguration=require("../clientConfiguration"),_types=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _tsRes=require("ts-res"),_targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_utilities=require("../utilities"),_clientConfiguration=require("../clientConfiguration"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{storage:b,cleanupInterval:c}=a;if(_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"mappingIdentifierCustomDataIndex",null),_defineProperty(this,"cleanupIntervalId",null),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"unsentData",void 0),_defineProperty(this,"sentPageViewTimestamps",new Map),this.dataProcessor=new _dataProcessor.DataProcessor(b),this.unsentData={},c){const a=()=>{this.dataProcessor.cleanupTargetingData(c),this.sentPageViewTimestamps.clear()};try{this.cleanupIntervalId=setInterval(a,c)}catch(a){throw this.cleanupIntervalId&&clearInterval(this.cleanupIntervalId),a}}}addData(a){this.unsentData[a]||(this.unsentData[a]=new Map);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];for(const b of c)switch(this.dataProcessor.updateData(a,b),b.data.type){case _types.KameleoonData.CustomData:{const c=b,d=c.data;this.mappingIdentifierCustomDataIndex===d.index&&(c._isMappingIdentifier=!0,a!==d.value[0]&&this.dataProcessor.createReference(a,d.value[0])),this.localCustomDataIndexes.has(d.index)||b.isSent||this.unsentData[a].set(d.index,c);break}case _types.KameleoonData.PageView:{const c=b.data,d=this.dataProcessor.getTargetingData(a).or({});if(d){const e=d[_types.KameleoonData.PageView],f=e[c.urlAddress];if(!b.isSent)for(const c of f.timestamps)this.sentPageViewTimestamps.has(c)||(this.unsentData[a].set(c,b),this.sentPageViewTimestamps.set(c,!0));else for(const a of f.timestamps)this.sentPageViewTimestamps.has(a)||this.sentPageViewTimestamps.set(a,!0)}break}case _types.KameleoonData.Conversion:{const c=this.unsentData[a];if(!b.isSent)if(c.has(_types.KameleoonData.Conversion)){const a=c.get(_types.KameleoonData.Conversion);a.push(b),c.set(_types.KameleoonData.Conversion,a)}else c.set(_types.KameleoonData.Conversion,[b]);break}default:{const{data:c}=b;b.isSent||this.unsentData[a].set(c.type,b)}}return(0,_tsRes.Ok)()}getTree(a){if(this.targetingTrees.has(a.id))return this.targetingTrees.get(a.id);const b=new _targeting.Tree(a);return this.targetingTrees.set(a.id,b),b}clearTrees(){this.targetingTrees.clear()}getUnsentData(a){return this.unsentData[a]}clearUnsentData(a){var b;const c=null===(b=this.unsentData[a])||void 0===b?void 0:b.values();if(c&&this.persistentCustomDataIndexes.size){const b=new Map;for(const a of c)!Array.isArray(a)&&this.isPersistentCustomData(a)&&b.set(a.data.index,a);if(b.size)return void(this.unsentData[a]=b)}delete this.unsentData[a]}clearUnsentDataByKey(a,b){const c=this.unsentData[a];if(c){if(b===_types.KameleoonData.CustomData&&this.persistentCustomDataIndexes.size)for(const[a,d]of c.entries())this.isPersistentCustomData(d)||a===b&&c.delete(a);else if(b===_types.KameleoonData.PageView)for(const a of c.keys())"number"==typeof a&&c.delete(a);else c.delete(b);c.size||delete this.unsentData[a]}}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}getLinkedVisitor(a){return this.dataProcessor.getLinkedVisitor(a,this.mappingIdentifierCustomDataIndex)}getVisitorIdentifier(a){const b=this.getTargetingData(a);if(!b)return a;const c=b[_types.KameleoonData.CustomData];if(!c||null===this.mappingIdentifierCustomDataIndex)return a;const d=c[this.mappingIdentifierCustomDataIndex];return d?d.value[0]:a}getTargetingData(a){const b=this.dataProcessor.getTargetingData(a).or(null);return b?b:void 0}get trees(){return this.targetingTrees}get unsentDataVisitors(){return Object.keys(this.unsentData)}get identifierCustomDataIndex(){return this.mappingIdentifierCustomDataIndex}get storedDataTypes(){return this.dataProcessor.storedDataTypeList}get storedCustomDataIndexes(){return this.dataProcessor.storedCustomDataIndexList}set customDataIndexes(a){const[b,c]=[[],[]];a.forEach(a=>{a.localOnly&&b.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&c.push(a.index),a.isMappingIdentifier&&(this.mappingIdentifierCustomDataIndex=a.index)}),b.length&&(this.localCustomDataIndexes=new Set(b)),c.length&&(this.persistentCustomDataIndexes=new Set(c))}}exports.DataManager=DataManager;
|
|
2
2
|
//# sourceMappingURL=dataManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataManager.js","names":["DataManager","constructor","a","storage","targetingCleanupInterval","_defineProperty","Map","Set","dataProcessor","DataProcessor","unsentData","cleanupInterval","cleanupCallback","cleanupOutdatedTargetingData","sentPageViewTimestamps","clear","targetingDataIntervalId","setInterval","Milliseconds","Minute","err","clearInterval","addData","visitorCode","b","arguments","length","kameleoonData","Array","d","dataItem","updateData","data","type","KameleoonData","CustomData","customData","mappingIdentifierCustomDataIndex","index","_isMappingIdentifier","value","createReference","localCustomDataIndexes","has","isSent","set","PageView","storedData","getTargetingData","or","storedVisitorData","pageView","urlAddress","timestamp","timestamps","Conversion","existingConversions","get","push","Ok","getTree","segment","targetingTrees","id","targetingTree","Tree","clearTrees","getUnsentData","clearUnsentData","dataItems","values","persistentCustomDataIndexes","size","persistentCustomData","isArray","isPersistentCustomData","clearUnsentDataByKey","key","visitorData","dataKey","entries","delete","keys","Utilities","isCustomData","getLinkedVisitor","getVisitorIdentifier","targetingData","customDataValue","trees","unsentDataVisitors","Object","identifierCustomDataIndex","storedDataTypes","storedDataTypeList","storedCustomDataIndexes","storedCustomDataIndexList","customDataIndexes","customDataLocalOnlyIndexes","forEach","localOnly","scope","CustomDataScope","Visitor","isMappingIdentifier","exports"],"sources":["../../src/kameleoonData/dataManager.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { SegmentType, Tree } from 'src/targeting';\nimport { DataProcessor } from './dataProcessor';\nimport { Utilities } from 'src/utilities';\nimport {\n CustomDataConfigurationType,\n CustomDataScope,\n} from 'src/clientConfiguration';\nimport { Milliseconds } from 'src/types';\nimport { CustomData } from './customData';\nimport {\n DataManagerParametersType,\n ExistingPageViewDataType,\n KameleoonData,\n KameleoonDataType,\n KameleoonVisitorDataType,\n PageViewDataType,\n UnsentTargetingDataType,\n UnsentVisitorTargetingDataType,\n} from './types';\n\ninterface IDataManager {\n addData(visitorCode: string, ...kameleoonData: KameleoonDataType[]): void;\n getUnsentData: (\n visitorCode: string,\n ) => UnsentTargetingDataType[string] | undefined;\n getTree(segment: SegmentType): Tree;\n clearTrees(): void;\n clearUnsentData: (visitorCode: string) => void;\n isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;\n getLinkedVisitor: (visitorCode: string) => string | null;\n getTargetingData: (\n visitorCode: string,\n ) => KameleoonVisitorDataType | undefined;\n readonly trees: Map<string, Tree>;\n readonly unsentDataVisitors: string[];\n readonly identifierCustomDataIndex: number | null;\n}\n\nexport class DataManager implements IDataManager {\n private targetingTrees: Map<string, Tree> = new Map();\n private localCustomDataIndexes: Set<number> = new Set();\n private persistentCustomDataIndexes: Set<number> = new Set();\n private mappingIdentifierCustomDataIndex: number | null = null;\n private targetingDataIntervalId: NodeJS.Timer | null = null;\n private dataProcessor: DataProcessor;\n private unsentData: UnsentTargetingDataType;\n private sentPageViewTimestamps: Map<number, boolean> = new Map();\n\n constructor({\n storage,\n targetingCleanupInterval,\n }: DataManagerParametersType) {\n this.dataProcessor = new DataProcessor(storage);\n this.unsentData = {};\n\n if (targetingCleanupInterval) {\n const cleanupInterval =\n targetingCleanupInterval < 0 ? 1 : targetingCleanupInterval;\n\n const cleanupCallback = () => {\n this.dataProcessor.cleanupOutdatedTargetingData(\n targetingCleanupInterval,\n );\n this.sentPageViewTimestamps.clear();\n };\n\n // --- Note ---\n // We can not make delayed code execution recoverable, as it might lead\n // to targeting data storage size overflow\n try {\n this.targetingDataIntervalId = setInterval(\n cleanupCallback,\n cleanupInterval * Milliseconds.Minute,\n );\n } catch (err) {\n if (this.targetingDataIntervalId) {\n clearInterval(this.targetingDataIntervalId);\n }\n\n throw err;\n }\n }\n }\n\n public addData(\n visitorCode: string,\n ...kameleoonData: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n // --- Note ---\n // We assume `this.unsentTargetingData[visitorCode]` is always presents further\n if (!this.unsentData[visitorCode]) {\n this.unsentData[visitorCode] = new Map();\n }\n\n for (const dataItem of kameleoonData) {\n // TODO: this can be optimized to be updated altogether\n // instead of updating each data item separately\n this.dataProcessor.updateData(visitorCode, dataItem);\n\n switch (dataItem.data.type) {\n case KameleoonData.CustomData: {\n const customData = dataItem as CustomData;\n const data = customData.data;\n\n // --- Bug ---\n // - There's a known issue here: `mappingIdentifier` won't be updated\n // in the storage because the data is written before `unsentData` update\n // and we get `mappingIdentifier` only by checking CC here\n // - It doesn't affect the functionality, as stored data is\n // only used for condition evaluation and `Visitor` scoped CD is never removed from `unsentData`\n // still it should be fixed with some `.updateData` refactor\n if (this.mappingIdentifierCustomDataIndex === data.index) {\n customData._isMappingIdentifier = true;\n\n if (visitorCode !== data.value[0]) {\n // --- Note ---\n // Associate linked visitor codes\n this.dataProcessor.createReference(visitorCode, data.value[0]);\n }\n }\n\n if (\n !this.localCustomDataIndexes.has(data.index) &&\n !dataItem.isSent\n ) {\n this.unsentData[visitorCode]!.set(data.index, customData);\n }\n\n break;\n }\n case KameleoonData.PageView: {\n const data = dataItem.data as PageViewDataType;\n\n // --- Note ---\n // `PageViews` can only be processed during storage update as they\n // can't create and merge referrers/titles/timestamps on their own\n // So we have to extract them from storage to update `unsentData` correctly\n const storedData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or({});\n\n if (storedData) {\n const storedVisitorData = storedData[KameleoonData.PageView];\n const pageView = (storedVisitorData as ExistingPageViewDataType)[\n data.urlAddress\n ];\n\n // --- Note ---\n // A case for newly created page view\n if (!dataItem.isSent) {\n for (const timestamp of pageView.timestamps) {\n // --- Note ---\n // As we don't keep `sent` status for each timestamp, we have to\n // check if it was already sent to avoid duplicates\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.unsentData[visitorCode]!.set(timestamp, dataItem);\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n // --- Note ---\n // A case for `getRemoteVisitorData` pre-loaded pages that shouldn't be sent again\n } else {\n for (const timestamp of pageView.timestamps) {\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n }\n }\n\n break;\n }\n case KameleoonData.Conversion: {\n const unsentData = this.unsentData[visitorCode]!;\n\n if (!dataItem.isSent) {\n if (unsentData.has(KameleoonData.Conversion)) {\n const existingConversions = unsentData.get(\n KameleoonData.Conversion,\n ) as KameleoonDataType[];\n\n existingConversions.push(dataItem);\n\n unsentData.set(KameleoonData.Conversion, existingConversions);\n } else {\n unsentData.set(KameleoonData.Conversion, [dataItem]);\n }\n }\n\n break;\n }\n default: {\n const { data } = dataItem;\n\n if (!dataItem.isSent) {\n this.unsentData[visitorCode]!.set(data.type, dataItem);\n }\n }\n }\n }\n\n return Ok();\n }\n\n public getTree(segment: SegmentType): Tree {\n if (this.targetingTrees.has(segment.id)) {\n return this.targetingTrees.get(segment.id)!;\n }\n\n const targetingTree = new Tree(segment);\n this.targetingTrees.set(segment.id, targetingTree);\n\n return targetingTree;\n }\n\n public clearTrees(): void {\n this.targetingTrees.clear();\n }\n\n public getUnsentData(\n visitorCode: string,\n ): UnsentTargetingDataType[string] | undefined {\n return this.unsentData[visitorCode];\n }\n\n public clearUnsentData(visitorCode: string): void {\n const dataItems = this.unsentData[visitorCode]?.values();\n\n if (dataItems && this.persistentCustomDataIndexes.size) {\n const persistentCustomData: UnsentVisitorTargetingDataType = new Map();\n\n for (const dataItem of dataItems) {\n if (!Array.isArray(dataItem) && this.isPersistentCustomData(dataItem)) {\n persistentCustomData.set(dataItem.data.index, dataItem);\n }\n }\n\n if (persistentCustomData.size) {\n this.unsentData[visitorCode] = persistentCustomData;\n return;\n }\n }\n\n delete this.unsentData[visitorCode];\n }\n\n public clearUnsentDataByKey(visitorCode: string, key: KameleoonData): void {\n const visitorData = this.unsentData[visitorCode];\n\n if (!visitorData) {\n return;\n }\n\n if (\n key === KameleoonData.CustomData &&\n this.persistentCustomDataIndexes.size\n ) {\n for (const [dataKey, dataItem] of visitorData.entries()) {\n if (this.isPersistentCustomData(dataItem as KameleoonDataType)) {\n continue;\n }\n\n if (dataKey === key) {\n visitorData.delete(dataKey);\n }\n }\n } else if (key === KameleoonData.PageView) {\n for (const dataKey of visitorData.keys()) {\n if (typeof dataKey === 'number') {\n visitorData.delete(dataKey);\n }\n }\n } else {\n visitorData.delete(key);\n }\n\n if (!visitorData.size) {\n delete this.unsentData[visitorCode];\n }\n }\n\n public isPersistentCustomData(\n dataItem: KameleoonDataType,\n ): dataItem is CustomData {\n if (!this.persistentCustomDataIndexes.size) {\n return false;\n }\n\n if (Utilities.isCustomData(dataItem)) {\n return this.persistentCustomDataIndexes.has(dataItem.data.index);\n }\n\n return false;\n }\n\n public getLinkedVisitor(visitorCode: string): string | null {\n return this.dataProcessor.getLinkedVisitor(\n visitorCode,\n this.mappingIdentifierCustomDataIndex,\n );\n }\n\n public getVisitorIdentifier(visitorCode: string): string {\n const targetingData = this.getTargetingData(visitorCode);\n\n if (!targetingData) {\n return visitorCode;\n }\n\n const customData = targetingData[KameleoonData.CustomData];\n\n if (!customData || this.mappingIdentifierCustomDataIndex === null) {\n return visitorCode;\n }\n\n const customDataValue = customData[this.mappingIdentifierCustomDataIndex];\n\n if (customDataValue) {\n return customDataValue.value[0];\n }\n\n return visitorCode;\n }\n\n public getTargetingData(\n visitorCode: string,\n ): KameleoonVisitorDataType | undefined {\n const targetingData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or(null);\n\n if (!targetingData) {\n return undefined;\n }\n\n return targetingData;\n }\n\n get trees(): Map<string, Tree> {\n return this.targetingTrees;\n }\n\n get unsentDataVisitors(): string[] {\n return Object.keys(this.unsentData);\n }\n\n get identifierCustomDataIndex(): number | null {\n return this.mappingIdentifierCustomDataIndex;\n }\n\n get storedDataTypes(): Set<KameleoonData> {\n return this.dataProcessor.storedDataTypeList;\n }\n\n get storedCustomDataIndexes(): Set<number> {\n return this.dataProcessor.storedCustomDataIndexList;\n }\n\n set customDataIndexes(customData: CustomDataConfigurationType[]) {\n const [customDataLocalOnlyIndexes, persistentCustomDataIndexes]: Array<\n number[]\n > = [[], []];\n\n customData.forEach((customData) => {\n if (customData.localOnly) {\n customDataLocalOnlyIndexes.push(customData.index);\n }\n\n if (customData.scope === CustomDataScope.Visitor) {\n persistentCustomDataIndexes.push(customData.index);\n }\n\n if (customData.isMappingIdentifier) {\n this.mappingIdentifierCustomDataIndex = customData.index;\n }\n });\n\n if (customDataLocalOnlyIndexes.length) {\n this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);\n }\n\n if (persistentCustomDataIndexes.length) {\n this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);\n }\n }\n}\n"],"mappings":"41BAwCO,KAAM,CAAAA,WAAoC,CAU/CC,WAAWA,CAAAC,CAAA,CAGmB,IAHlB,CACVC,OAAO,CAAPA,CAAO,CACPC,wBAAwB,CAAxBA,CACyB,CAAC,CAAAF,CAAA,CAI1B,GAAAG,eAAA,uBAhB0C,GAAI,CAAAC,GAAK,EAAAD,eAAA,+BACP,GAAI,CAAAE,GAAK,EAAAF,eAAA,oCACJ,GAAI,CAAAE,GAAK,EAAAF,eAAA,yCACF,IAA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U,CAACoE,mBAAmB,GAChC,IAAI,CAACnE,gCAAgC,CAAGD,CAAU,CAACE,KAAK,CAE5D,CAAC,CAAC,CAEE4D,CAA0B,CAACxE,MAAM,GACnC,IAAI,CAACgB,sBAAsB,CAAG,GAAI,CAAAnC,GAAG,CAAC2F,CAA0B,CAAC,EAG/D3B,CAA2B,CAAC7C,MAAM,GACpC,IAAI,CAAC6C,2BAA2B,CAAG,GAAI,CAAAhE,GAAG,CAACgE,CAA2B,CAAC,CAE3E,CACF,CAACkC,OAAA,CAAAzG,WAAA,CAAAA,WAAA"}
|
|
1
|
+
{"version":3,"file":"dataManager.js","names":["DataManager","constructor","a","storage","cleanupInterval","_defineProperty","Map","Set","dataProcessor","DataProcessor","unsentData","cleanupCallback","cleanupTargetingData","sentPageViewTimestamps","clear","cleanupIntervalId","setInterval","err","clearInterval","addData","visitorCode","b","arguments","length","kameleoonData","Array","d","dataItem","updateData","data","type","KameleoonData","CustomData","customData","mappingIdentifierCustomDataIndex","index","_isMappingIdentifier","value","createReference","localCustomDataIndexes","has","isSent","set","PageView","storedData","getTargetingData","or","storedVisitorData","pageView","urlAddress","timestamp","timestamps","Conversion","existingConversions","get","push","Ok","getTree","segment","targetingTrees","id","targetingTree","Tree","clearTrees","getUnsentData","clearUnsentData","dataItems","values","persistentCustomDataIndexes","size","persistentCustomData","isArray","isPersistentCustomData","clearUnsentDataByKey","key","visitorData","dataKey","entries","delete","keys","Utilities","isCustomData","getLinkedVisitor","getVisitorIdentifier","targetingData","customDataValue","trees","unsentDataVisitors","Object","identifierCustomDataIndex","storedDataTypes","storedDataTypeList","storedCustomDataIndexes","storedCustomDataIndexList","customDataIndexes","customDataLocalOnlyIndexes","forEach","localOnly","scope","CustomDataScope","Visitor","isMappingIdentifier","exports"],"sources":["../../src/kameleoonData/dataManager.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { SegmentType, Tree } from 'src/targeting';\nimport { DataProcessor } from './dataProcessor';\nimport { Utilities } from 'src/utilities';\nimport {\n CustomDataConfigurationType,\n CustomDataScope,\n} from 'src/clientConfiguration';\nimport { CustomData } from './customData';\nimport {\n DataManagerParametersType,\n ExistingPageViewDataType,\n KameleoonData,\n KameleoonDataType,\n KameleoonVisitorDataType,\n PageViewDataType,\n UnsentTargetingDataType,\n UnsentVisitorTargetingDataType,\n} from './types';\n\ninterface IDataManager {\n addData(visitorCode: string, ...kameleoonData: KameleoonDataType[]): void;\n getUnsentData: (\n visitorCode: string,\n ) => UnsentTargetingDataType[string] | undefined;\n getTree(segment: SegmentType): Tree;\n clearTrees(): void;\n clearUnsentData: (visitorCode: string) => void;\n isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;\n getLinkedVisitor: (visitorCode: string) => string | null;\n getTargetingData: (\n visitorCode: string,\n ) => KameleoonVisitorDataType | undefined;\n readonly trees: Map<string, Tree>;\n readonly unsentDataVisitors: string[];\n readonly identifierCustomDataIndex: number | null;\n}\n\nexport class DataManager implements IDataManager {\n private targetingTrees: Map<string, Tree> = new Map();\n private localCustomDataIndexes: Set<number> = new Set();\n private persistentCustomDataIndexes: Set<number> = new Set();\n private mappingIdentifierCustomDataIndex: number | null = null;\n private cleanupIntervalId: NodeJS.Timer | null = null;\n private dataProcessor: DataProcessor;\n private unsentData: UnsentTargetingDataType;\n private sentPageViewTimestamps: Map<number, boolean> = new Map();\n\n constructor({ storage, cleanupInterval }: DataManagerParametersType) {\n this.dataProcessor = new DataProcessor(storage);\n this.unsentData = {};\n\n if (cleanupInterval) {\n const cleanupCallback = () => {\n this.dataProcessor.cleanupTargetingData(cleanupInterval);\n this.sentPageViewTimestamps.clear();\n };\n\n // --- Note ---\n // We can not make delayed code execution recoverable, as it might lead\n // to targeting data storage size overflow\n try {\n this.cleanupIntervalId = setInterval(cleanupCallback, cleanupInterval);\n } catch (err) {\n if (this.cleanupIntervalId) {\n clearInterval(this.cleanupIntervalId);\n }\n\n throw err;\n }\n }\n }\n\n public addData(\n visitorCode: string,\n ...kameleoonData: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n // --- Note ---\n // We assume `this.unsentTargetingData[visitorCode]` is always presents further\n if (!this.unsentData[visitorCode]) {\n this.unsentData[visitorCode] = new Map();\n }\n\n for (const dataItem of kameleoonData) {\n // TODO: this can be optimized to be updated altogether\n // instead of updating each data item separately\n this.dataProcessor.updateData(visitorCode, dataItem);\n\n switch (dataItem.data.type) {\n case KameleoonData.CustomData: {\n const customData = dataItem as CustomData;\n const data = customData.data;\n\n // --- Bug ---\n // - There's a known issue here: `mappingIdentifier` won't be updated\n // in the storage because the data is written before `unsentData` update\n // and we get `mappingIdentifier` only by checking CC here\n // - It doesn't affect the functionality, as stored data is\n // only used for condition evaluation and `Visitor` scoped CD is never removed from `unsentData`\n // still it should be fixed with some `.updateData` refactor\n if (this.mappingIdentifierCustomDataIndex === data.index) {\n customData._isMappingIdentifier = true;\n\n if (visitorCode !== data.value[0]) {\n // --- Note ---\n // Associate linked visitor codes\n this.dataProcessor.createReference(visitorCode, data.value[0]);\n }\n }\n\n if (\n !this.localCustomDataIndexes.has(data.index) &&\n !dataItem.isSent\n ) {\n this.unsentData[visitorCode]!.set(data.index, customData);\n }\n\n break;\n }\n case KameleoonData.PageView: {\n const data = dataItem.data as PageViewDataType;\n\n // --- Note ---\n // `PageViews` can only be processed during storage update as they\n // can't create and merge referrers/titles/timestamps on their own\n // So we have to extract them from storage to update `unsentData` correctly\n const storedData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or({});\n\n if (storedData) {\n const storedVisitorData = storedData[KameleoonData.PageView];\n const pageView = (storedVisitorData as ExistingPageViewDataType)[\n data.urlAddress\n ];\n\n // --- Note ---\n // A case for newly created page view\n if (!dataItem.isSent) {\n for (const timestamp of pageView.timestamps) {\n // --- Note ---\n // As we don't keep `sent` status for each timestamp, we have to\n // check if it was already sent to avoid duplicates\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.unsentData[visitorCode]!.set(timestamp, dataItem);\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n // --- Note ---\n // A case for `getRemoteVisitorData` pre-loaded pages that shouldn't be sent again\n } else {\n for (const timestamp of pageView.timestamps) {\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n }\n }\n\n break;\n }\n case KameleoonData.Conversion: {\n const unsentData = this.unsentData[visitorCode]!;\n\n if (!dataItem.isSent) {\n if (unsentData.has(KameleoonData.Conversion)) {\n const existingConversions = unsentData.get(\n KameleoonData.Conversion,\n ) as KameleoonDataType[];\n\n existingConversions.push(dataItem);\n\n unsentData.set(KameleoonData.Conversion, existingConversions);\n } else {\n unsentData.set(KameleoonData.Conversion, [dataItem]);\n }\n }\n\n break;\n }\n default: {\n const { data } = dataItem;\n\n if (!dataItem.isSent) {\n this.unsentData[visitorCode]!.set(data.type, dataItem);\n }\n }\n }\n }\n\n return Ok();\n }\n\n public getTree(segment: SegmentType): Tree {\n if (this.targetingTrees.has(segment.id)) {\n return this.targetingTrees.get(segment.id)!;\n }\n\n const targetingTree = new Tree(segment);\n this.targetingTrees.set(segment.id, targetingTree);\n\n return targetingTree;\n }\n\n public clearTrees(): void {\n this.targetingTrees.clear();\n }\n\n public getUnsentData(\n visitorCode: string,\n ): UnsentTargetingDataType[string] | undefined {\n return this.unsentData[visitorCode];\n }\n\n public clearUnsentData(visitorCode: string): void {\n const dataItems = this.unsentData[visitorCode]?.values();\n\n if (dataItems && this.persistentCustomDataIndexes.size) {\n const persistentCustomData: UnsentVisitorTargetingDataType = new Map();\n\n for (const dataItem of dataItems) {\n if (!Array.isArray(dataItem) && this.isPersistentCustomData(dataItem)) {\n persistentCustomData.set(dataItem.data.index, dataItem);\n }\n }\n\n if (persistentCustomData.size) {\n this.unsentData[visitorCode] = persistentCustomData;\n return;\n }\n }\n\n delete this.unsentData[visitorCode];\n }\n\n public clearUnsentDataByKey(visitorCode: string, key: KameleoonData): void {\n const visitorData = this.unsentData[visitorCode];\n\n if (!visitorData) {\n return;\n }\n\n if (\n key === KameleoonData.CustomData &&\n this.persistentCustomDataIndexes.size\n ) {\n for (const [dataKey, dataItem] of visitorData.entries()) {\n if (this.isPersistentCustomData(dataItem as KameleoonDataType)) {\n continue;\n }\n\n if (dataKey === key) {\n visitorData.delete(dataKey);\n }\n }\n } else if (key === KameleoonData.PageView) {\n for (const dataKey of visitorData.keys()) {\n if (typeof dataKey === 'number') {\n visitorData.delete(dataKey);\n }\n }\n } else {\n visitorData.delete(key);\n }\n\n if (!visitorData.size) {\n delete this.unsentData[visitorCode];\n }\n }\n\n public isPersistentCustomData(\n dataItem: KameleoonDataType,\n ): dataItem is CustomData {\n if (!this.persistentCustomDataIndexes.size) {\n return false;\n }\n\n if (Utilities.isCustomData(dataItem)) {\n return this.persistentCustomDataIndexes.has(dataItem.data.index);\n }\n\n return false;\n }\n\n public getLinkedVisitor(visitorCode: string): string | null {\n return this.dataProcessor.getLinkedVisitor(\n visitorCode,\n this.mappingIdentifierCustomDataIndex,\n );\n }\n\n public getVisitorIdentifier(visitorCode: string): string {\n const targetingData = this.getTargetingData(visitorCode);\n\n if (!targetingData) {\n return visitorCode;\n }\n\n const customData = targetingData[KameleoonData.CustomData];\n\n if (!customData || this.mappingIdentifierCustomDataIndex === null) {\n return visitorCode;\n }\n\n const customDataValue = customData[this.mappingIdentifierCustomDataIndex];\n\n if (customDataValue) {\n return customDataValue.value[0];\n }\n\n return visitorCode;\n }\n\n public getTargetingData(\n visitorCode: string,\n ): KameleoonVisitorDataType | undefined {\n const targetingData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or(null);\n\n if (!targetingData) {\n return undefined;\n }\n\n return targetingData;\n }\n\n get trees(): Map<string, Tree> {\n return this.targetingTrees;\n }\n\n get unsentDataVisitors(): string[] {\n return Object.keys(this.unsentData);\n }\n\n get identifierCustomDataIndex(): number | null {\n return this.mappingIdentifierCustomDataIndex;\n }\n\n get storedDataTypes(): Set<KameleoonData> {\n return this.dataProcessor.storedDataTypeList;\n }\n\n get storedCustomDataIndexes(): Set<number> {\n return this.dataProcessor.storedCustomDataIndexList;\n }\n\n set customDataIndexes(customData: CustomDataConfigurationType[]) {\n const [customDataLocalOnlyIndexes, persistentCustomDataIndexes]: Array<\n number[]\n > = [[], []];\n\n customData.forEach((customData) => {\n if (customData.localOnly) {\n customDataLocalOnlyIndexes.push(customData.index);\n }\n\n if (customData.scope === CustomDataScope.Visitor) {\n persistentCustomDataIndexes.push(customData.index);\n }\n\n if (customData.isMappingIdentifier) {\n this.mappingIdentifierCustomDataIndex = customData.index;\n }\n });\n\n if (customDataLocalOnlyIndexes.length) {\n this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);\n }\n\n if (persistentCustomDataIndexes.length) {\n this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);\n }\n }\n}\n"],"mappings":"g0BAuCO,KAAM,CAAAA,WAAoC,CAU/CC,WAAWA,CAAAC,CAAA,CAA0D,IAAzD,CAAEC,OAAO,CAAPA,CAAO,CAAEC,eAAe,CAAfA,CAA2C,CAAC,CAAAF,CAAA,CAIjE,GAAAG,eAAA,uBAb0C,GAAI,CAAAC,GAAK,EAAAD,eAAA,+BACP,GAAI,CAAAE,GAAK,EAAAF,eAAA,oCACJ,GAAI,CAAAE,GAAK,EAAAF,eAAA,yCACF,IAAI,EAAAA,eAAA,0BACb,IAAI,EAAAA,eAAA,8BAAAA,eAAA,2BAAAA,eAAA,+BAGE,GAAI,CAAAC,GAAK,EAG9D,IAAI,CAACE,aAAa,CAAG,GAAI,CAAAC,4BAAa,CAACN,CAAO,CAAC,CAC/C,IAAI,CAACO,UAAU,CAAG,CAAC,CAAC,CAEhBN,CAAe,CAAE,CACnB,KAAM,CAAAO,CAAe,CAAGA,CAAA,GAAM,CAC5B,IAAI,CAACH,aAAa,CAACI,oBAAoB,CAACR,CAAe,CAAC,CACxD,IAAI,CAACS,sBAAsB,CAACC,KAAK,CAAC,CACpC,CAAC,CAKD,GAAI,CAC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A,CAAA,CAAa,CACjC,MAAO,CAAAC,MAAM,CAACT,IAAI,CAAC,IAAI,CAACrE,UAAU,CACpC,CAEA,GAAI,CAAA+E,yBAAyBA,CAAA,CAAkB,CAC7C,MAAO,KAAI,CAACvD,gCACd,CAEA,GAAI,CAAAwD,eAAeA,CAAA,CAAuB,CACxC,MAAO,KAAI,CAAClF,aAAa,CAACmF,kBAC5B,CAEA,GAAI,CAAAC,uBAAuBA,CAAA,CAAgB,CACzC,MAAO,KAAI,CAACpF,aAAa,CAACqF,yBAC5B,CAEA,GAAI,CAAAC,iBAAiBA,CAAC7D,CAAyC,CAAE,CAC/D,KAAM,CAAC8D,CAA0B,CAAE3B,CAA2B,CAE7D,CAAG,CAAC,EAAE,CAAE,EAAE,CAAC,CAEZnC,CAAU,CAAC+D,OAAO,CAAE/D,CAAU,EAAK,CAC7BA,CAAU,CAACgE,SAAS,EACtBF,CAA0B,CAACxC,IAAI,CAACtB,CAAU,CAACE,KAAK,CAAC,CAG/CF,CAAU,CAACiE,KAAK,GAAKC,oCAAe,CAACC,OAAO,EAC9ChC,CAA2B,CAACb,IAAI,CAACtB,CAAU,CAACE,KAAK,CAAC,CAGhDF,CAAU,CAACoE,mBAAmB,GAChC,IAAI,CAACnE,gCAAgC,CAAGD,CAAU,CAACE,KAAK,CAE5D,CAAC,CAAC,CAEE4D,CAA0B,CAACxE,MAAM,GACnC,IAAI,CAACgB,sBAAsB,CAAG,GAAI,CAAAhC,GAAG,CAACwF,CAA0B,CAAC,EAG/D3B,CAA2B,CAAC7C,MAAM,GACpC,IAAI,CAAC6C,2BAA2B,CAAG,GAAI,CAAA7D,GAAG,CAAC6D,CAA2B,CAAC,CAE3E,CACF,CAACkC,OAAA,CAAAtG,WAAA,CAAAA,WAAA"}
|
|
@@ -6,7 +6,7 @@ import { KameleoonData, KameleoonDataType, KameleoonVisitorDataType } from './ty
|
|
|
6
6
|
interface IDataProcessor {
|
|
7
7
|
updateData(visitorCode: string, dataItem: KameleoonDataType): Result<void, KameleoonError>;
|
|
8
8
|
createReference(visitorCode: string, linkedVisitor: VisitorReference): void;
|
|
9
|
-
|
|
9
|
+
cleanupTargetingData(targetingCleanupInterval?: number): void;
|
|
10
10
|
getTargetingData(visitorCode: string): Result<KameleoonVisitorDataType | null, KameleoonError>;
|
|
11
11
|
getLinkedVisitor(visitorCode: string, index: number): string | null;
|
|
12
12
|
}
|
|
@@ -18,7 +18,7 @@ export declare class DataProcessor implements IDataProcessor {
|
|
|
18
18
|
updateData(visitorCode: string, dataItem: KameleoonDataType): Result<void, KameleoonError>;
|
|
19
19
|
createReference(visitorCode: string, linkedVisitor: VisitorReference): void;
|
|
20
20
|
getLinkedVisitor(visitorCode: string, index: number | null): string | null;
|
|
21
|
-
|
|
21
|
+
cleanupTargetingData(cleanupInterval: number): void;
|
|
22
22
|
getTargetingData(visitorCode: string): Result<KameleoonVisitorDataType | null, KameleoonError>;
|
|
23
23
|
private dereferenceTargetingData;
|
|
24
24
|
get storedDataTypeList(): Set<KameleoonData>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const _excluded=["customData","pageView","conversion"];Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataProcessor=void 0;var _tsRes=require("ts-res"),_utilities=require("../utilities"),_types=require("../utilities/types"),_types2=require("
|
|
1
|
+
"use strict";const _excluded=["customData","pageView","conversion"];Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataProcessor=void 0;var _tsRes=require("ts-res"),_utilities=require("../utilities"),_types=require("../utilities/types"),_types2=require("./types");function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataProcessor{constructor(a){_defineProperty(this,"storage",void 0),_defineProperty(this,"storedDataTypes",new Set([])),_defineProperty(this,"storedCustomDataIndexes",new Set([])),this.storage=a}updateData(a,b){const c=this.storage.read().or({}),d=this.dereferenceTargetingData(c,a),e=(null===d||void 0===d?void 0:d.visitorReference)||a;switch(b.data.type){case _types2.KameleoonData.CustomData:{const a=b.data,f=d&&_types2.KameleoonData.CustomData in d.data,g={visitorCode:e,data:c,key:_types2.KameleoonData.CustomData,nestedKey:a.index.toString(),value:a};f?this.updateNestedField(g):this.createNestedField(g),this.storedCustomDataIndexes.add(a.index);break}case _types2.KameleoonData.PageView:{var f;const a=b.data;a.timestamps.length||(a.timestamps=[Date.now()]);const g=d&&_types2.KameleoonData.PageView in d.data&&(null===(f=d.data[a.type])||void 0===f?void 0:f[a.urlAddress]),h={visitorCode:e,data:c,key:_types2.KameleoonData.PageView,nestedKey:a.urlAddress,value:a};g?(a.timestamps.forEach(a=>{_utilities.Utilities.insertInOrderedListMutably({list:g.timestamps,element:a,order:_types.Order.Ascending})}),[g.referrers,g.title]=[a.referrers,a.title],this.updateNestedField(_objectSpread(_objectSpread({},h),{},{value:g}))):this.createNestedField(h);break}case _types2.KameleoonData.Conversion:{const a=b.data,f=d&&_types2.KameleoonData.Conversion in d.data,g={visitorCode:e,data:c,key:_types2.KameleoonData.Conversion,value:a};f?this.updateArrayField(g):this.createArrayField(g);break}case _types2.KameleoonData.VisitsData:{const a=b.data,f=d&&_types2.KameleoonData.VisitsData in d.data,g={visitorCode:e,data:c,key:_types2.KameleoonData.VisitsData,value:a};if(f){const b=d.data[a.type];b.visits.forEach(b=>{_utilities.Utilities.insertInOrderedListMutably({list:a.visits,element:b,order:_types.Order.Ascending})}),this.updateField(_objectSpread(_objectSpread({},g),{},{value:_objectSpread(_objectSpread({},a),{},{visits:a.visits})}))}else this.createField(g);break}default:{const{data:a}=b,f=d&&a.type in d.data,g={visitorCode:e,data:c,key:a.type,value:a};f?this.updateField(g):this.createField(g),this.storedDataTypes.add(a.type)}}return this.storage.write(c)}createReference(a,b){const c=this.storage.read();c.ok&&(c.data[b]=a,this.storage.write(c.data))}getLinkedVisitor(a,b){const c=this.storage.read();if(!c.ok)return null;if("string"==typeof c.data[a])return c.data[a];if(null===b)return null;const d=c.data[a];if(!d)return null;const e=d[_types2.KameleoonData.CustomData];return e&&e[b]?e[b].value[0]:null}cleanupTargetingData(a){const b=this.storage.read();if(!b.ok)return;const c=b.data,d=Date.now();if(Object.keys(c).length){for(const[b,e]of Object.entries(c)){if("string"==typeof e){delete c[b];continue}const f=e,{customData:g,pageView:h,conversion:i}=f,j=_objectWithoutProperties(f,_excluded);if(g)for(const[b,e]of Object.entries(g))if(e){const g=e.lastActivityTime+a<d,h=f[_types2.KameleoonData.CustomData];g&&h&&(this.storedCustomDataIndexes.delete(+b),delete h[+b]),h&&!Object.keys(h).length&&(this.storedCustomDataIndexes.clear(),delete c[_types2.KameleoonData.CustomData])}if(h)for(const[b,c]of Object.entries(h)){const e=c.lastActivityTime+a<d,g=f[_types2.KameleoonData.PageView];e&&g&&delete g[b],g&&!Object.keys(g).length&&delete f[_types2.KameleoonData.PageView]}if(i)for(const b of i){const c=b.lastActivityTime+a<d,e=f[_types2.KameleoonData.Conversion];c&&e&&e.splice(e.indexOf(b),1),e&&!e.length&&delete f[_types2.KameleoonData.Conversion]}for(const[b,c]of Object.entries(j)){const e=c.lastActivityTime+a<d;e&&(delete f[b],this.storedDataTypes.delete(b))}Object.keys(c[b]).length||(this.storedDataTypes.clear(),this.storedCustomDataIndexes.clear(),delete c[b])}this.storage.write(c)}}getTargetingData(a){const b=this.storage.read();if(!b.ok)return(0,_tsRes.Err)(b.error);const c=this.dereferenceTargetingData(b.data,a);return c?(0,_tsRes.Ok)(c.data):(0,_tsRes.Ok)(null)}dereferenceTargetingData(a,b){if(!a[b])return null;if("string"==typeof a[b]){const c=a[b];return{data:a[c],visitorReference:c}}return{data:a[b],visitorReference:b}}get storedDataTypeList(){return this.storedDataTypes}get storedCustomDataIndexList(){return this.storedCustomDataIndexes}updateField(a){let{visitorCode:b,key:c,value:d,data:e}=a;e[b][c]=_objectSpread(_objectSpread({},d),{},{lastActivityTime:Date.now()})}createField(a){let{visitorCode:b,key:c,value:d,data:e}=a;e[b]=_objectSpread(_objectSpread({},e[b]),{},{[c]:_objectSpread(_objectSpread({},d),{},{lastActivityTime:Date.now()})})}updateArrayField(a){let{visitorCode:b,key:c,value:d,data:e}=a;e[b][c].push(_objectSpread(_objectSpread({},d),{},{lastActivityTime:Date.now()}))}createArrayField(a){let{visitorCode:b,key:c,value:d,data:e}=a;e[b]=_objectSpread(_objectSpread({},e[b]),{},{[c]:[_objectSpread(_objectSpread({},d),{},{lastActivityTime:Date.now()})]})}updateNestedField(a){let{visitorCode:b,key:c,nestedKey:d,value:e,data:f}=a;f[b][c][d]=_objectSpread(_objectSpread({},e),{},{lastActivityTime:Date.now()})}createNestedField(a){var b;let{visitorCode:c,key:d,nestedKey:e,value:f,data:g}=a;g[c]=null!==(b=g[c])&&void 0!==b&&b[d]?_objectSpread(_objectSpread({},g[c]),{},{[d]:_objectSpread(_objectSpread({},g[c][d]),{},{[e]:_objectSpread(_objectSpread({},f),{},{lastActivityTime:Date.now()})})}):_objectSpread(_objectSpread({},g[c]),{},{[d]:{[e]:_objectSpread(_objectSpread({},f),{},{lastActivityTime:Date.now()})}})}}exports.DataProcessor=DataProcessor;
|
|
2
2
|
//# sourceMappingURL=dataProcessor.js.map
|