@kameleoon/javascript-sdk-core 2.2.1 → 2.4.0
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/dist/campaignConfiguration/campaignConfiguration.d.ts +2 -2
- package/dist/campaignConfiguration/campaignConfiguration.js +21 -5
- package/dist/campaignConfiguration/campaignConfiguration.js.map +1 -1
- package/dist/campaignConfiguration/types.d.ts +4 -0
- package/dist/campaignConfiguration/types.js.map +1 -1
- package/dist/clientSettings/clientSettings.js +1 -1
- package/dist/clientSettings/clientSettings.js.map +1 -1
- package/dist/eventSource/externalEventSource.js +1 -1
- package/dist/eventSource/externalEventSource.js.map +1 -1
- package/dist/kameleoonClient.d.ts +19 -5
- package/dist/kameleoonClient.js +29 -20
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonError/constants.d.ts +1 -0
- package/dist/kameleoonError/constants.js +2 -1
- package/dist/kameleoonError/constants.js.map +1 -1
- package/dist/kameleoonError/kameleoonError.d.ts +1 -1
- package/dist/kameleoonError/kameleoonError.js +1 -0
- package/dist/kameleoonError/kameleoonError.js.map +1 -1
- package/dist/kameleoonError/types.d.ts +2 -1
- package/dist/kameleoonError/types.js +1 -0
- package/dist/kameleoonError/types.js.map +1 -1
- package/dist/kameleoonUtils.js +1 -1
- package/dist/kameleoonUtils.js.map +1 -1
- package/dist/requester/constants.d.ts +4 -3
- package/dist/requester/constants.js +16 -8
- package/dist/requester/constants.js.map +1 -1
- package/dist/requester/index.d.ts +2 -2
- package/dist/requester/index.js +12 -0
- package/dist/requester/index.js.map +1 -1
- package/dist/requester/requester.d.ts +2 -1
- package/dist/requester/requester.js +15 -6
- package/dist/requester/requester.js.map +1 -1
- package/dist/requester/types.d.ts +34 -4
- package/dist/requester/types.js +2 -2
- package/dist/requester/types.js.map +1 -1
- package/dist/utilities/utilities.d.ts +3 -0
- package/dist/utilities/utilities.js +28 -0
- package/dist/utilities/utilities.js.map +1 -1
- package/dist/variationConfiguration/variationConfiguration.js +19 -9
- package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { KameleoonDataType } from '../kameleoonData';
|
|
|
5
5
|
import { TargetingDataType } from '../targeting';
|
|
6
6
|
import { IExternalEventSourceConstructor } from '../eventSource';
|
|
7
7
|
interface ICampaignConfiguration {
|
|
8
|
-
initialize: (eventSource: IExternalEventSourceConstructor) => Promise<Result<void, KameleoonError>>;
|
|
8
|
+
initialize: (eventSource: IExternalEventSourceConstructor, useCache?: boolean) => Promise<Result<void, KameleoonError>>;
|
|
9
9
|
addTargetingData: (visitorCode: string, ...data: KameleoonDataType[]) => Result<void, KameleoonError>;
|
|
10
10
|
getUnsentData: (visitorCode: string) => KameleoonDataType[];
|
|
11
11
|
clearUnsentData: (visitorCode: string) => void;
|
|
@@ -29,7 +29,7 @@ export declare class CampaignConfiguration implements ICampaignConfiguration {
|
|
|
29
29
|
private eventSource?;
|
|
30
30
|
private externalClientConfiguration?;
|
|
31
31
|
constructor({ settings, storage, requester, externalClientConfiguration, targetingCleanupInterval, }: CampaignConfigurationParametersType);
|
|
32
|
-
initialize(externalEventSource: IExternalEventSourceConstructor): Promise<Result<void, KameleoonError>>;
|
|
32
|
+
initialize(externalEventSource: IExternalEventSourceConstructor, useCache?: boolean): Promise<Result<void, KameleoonError>>;
|
|
33
33
|
addTargetingData(visitorCode: string, ...data: KameleoonDataType[]): Result<void, KameleoonError>;
|
|
34
34
|
getUnsentData(visitorCode: string): KameleoonDataType[];
|
|
35
35
|
clearUnsentData(visitorCode: string): void;
|
|
@@ -55,12 +55,14 @@ class CampaignConfiguration {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
async initialize(externalEventSource) {
|
|
58
|
+
async initialize(externalEventSource, useCache) {
|
|
59
59
|
const shouldUpdate = this.checkShouldUpdate();
|
|
60
60
|
|
|
61
61
|
// --- Initial data fetch ---
|
|
62
62
|
if (shouldUpdate) {
|
|
63
|
-
const updateResult = await this.updateClientConfiguration(
|
|
63
|
+
const updateResult = await this.updateClientConfiguration({
|
|
64
|
+
useCache
|
|
65
|
+
});
|
|
64
66
|
if (!updateResult.ok) {
|
|
65
67
|
return updateResult;
|
|
66
68
|
}
|
|
@@ -75,7 +77,9 @@ class CampaignConfiguration {
|
|
|
75
77
|
}
|
|
76
78
|
this.eventSource = new _eventSource.ExternalEventSource(this.settings.siteCode, externalEventSource);
|
|
77
79
|
const updateEventCallback = _timeStamp => {
|
|
78
|
-
this.updateClientConfiguration(
|
|
80
|
+
this.updateClientConfiguration({
|
|
81
|
+
useCache
|
|
82
|
+
});
|
|
79
83
|
if (this.configurationUpdateCallback) {
|
|
80
84
|
this.configurationUpdateCallback();
|
|
81
85
|
}
|
|
@@ -96,7 +100,9 @@ class CampaignConfiguration {
|
|
|
96
100
|
// Same as targeting data interval we don't want to make failed configuration
|
|
97
101
|
// retrieval recoverable
|
|
98
102
|
try {
|
|
99
|
-
this.updateConfigurationIntervalId = setInterval(this.updateClientConfiguration.bind(this)
|
|
103
|
+
this.updateConfigurationIntervalId = setInterval(() => this.updateClientConfiguration.bind(this)({
|
|
104
|
+
useCache
|
|
105
|
+
}), this.settings.updateInterval);
|
|
100
106
|
} catch (err) {
|
|
101
107
|
if (this.updateConfigurationIntervalId) {
|
|
102
108
|
clearInterval(this.updateConfigurationIntervalId);
|
|
@@ -208,7 +214,10 @@ class CampaignConfiguration {
|
|
|
208
214
|
this.lastUpdate = new Date(Date.parse(lastUpdate));
|
|
209
215
|
}
|
|
210
216
|
}
|
|
211
|
-
async updateClientConfiguration(
|
|
217
|
+
async updateClientConfiguration({
|
|
218
|
+
useCache = false,
|
|
219
|
+
timeStamp
|
|
220
|
+
} = {}) {
|
|
212
221
|
// --- Note ---
|
|
213
222
|
// if `externalClientConfiguration` is passed, fetching is disabled and passed config is used instead
|
|
214
223
|
if (this.externalClientConfiguration) {
|
|
@@ -228,6 +237,13 @@ class CampaignConfiguration {
|
|
|
228
237
|
} else {
|
|
229
238
|
const clientConfigurationResult = await this.requester.getClientConfiguration(timeStamp);
|
|
230
239
|
if (!clientConfigurationResult.ok) {
|
|
240
|
+
const {
|
|
241
|
+
featureFlags,
|
|
242
|
+
experiments
|
|
243
|
+
} = this.configurationData;
|
|
244
|
+
if (useCache && featureFlags.length && experiments.length) {
|
|
245
|
+
return (0, _tsRes.Ok)(true);
|
|
246
|
+
}
|
|
231
247
|
return clientConfigurationResult;
|
|
232
248
|
}
|
|
233
249
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaignConfiguration.js","names":["_tsRes","require","_constants","_eventSource","_types","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","obj","value","_toPropertyKey","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","CampaignConfiguration","constructor","settings","storage","requester","externalClientConfiguration","targetingCleanupInterval","DEFAULT_CAMPAIGN_CONFIGURATION","targetingData","configurationData","lastUpdate","Date","readStorageData","cleanupIntervalMinutes","targetingDataIntervalId","setInterval","cleanupOutdatedTargetingData","Milliseconds","Minute","err","clearInterval","initialize","externalEventSource","shouldUpdate","checkShouldUpdate","updateResult","updateClientConfiguration","ok","configuration","realTimeUpdate","updateConfigurationIntervalId","eventSource","ExternalEventSource","siteCode","updateEventCallback","_timeStamp","configurationUpdateCallback","open","close","bind","updateInterval","Ok","addTargetingData","visitorCode","data","dataItem","lastActivityTime","now","result","updateStorageData","unsentTargetingData","getUnsentData","unsentDataItem","clearUnsentData","onConfigurationUpdate","callback","storedTargetingData","experiments","featureFlags","lastUpdateTime","getTime","updateWindowEdge","currentTime","resultTargetingData","entries","resultValue","item","isDataExpired","SESSION_DURATION","throw","read","kameleoonTargetingData","kameleoonConfiguration","parse","timeStamp","featureFlagConfigurations","clientConfigurationResult","getClientConfiguration","toString","write","exports"],"sources":["../../src/campaignConfiguration/campaignConfiguration.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from '../kameleoonError/kameleoonError';\nimport { ClientSettingsType } from '../clientSettings/types';\nimport { DEFAULT_CAMPAIGN_CONFIGURATION, SESSION_DURATION } from './constants';\nimport {\n CampaignConfigurationParametersType,\n ConfigurationDataType,\n ConfigurationType,\n ExperimentItemType,\n FeatureFlagType,\n UnsentTargetingDataType,\n} from './types';\nimport { KameleoonDataType } from '../kameleoonData';\nimport { Requester, GetClientConfigurationResultType } from '../requester';\nimport { TargetingDataItemType, TargetingDataType } from '../targeting';\nimport { IStorage, ClientDataType } from '../storage';\nimport {\n ExternalEventSource,\n IEventSource,\n IExternalEventSourceConstructor,\n} from '../eventSource';\nimport { Milliseconds } from '../types';\n\ninterface ICampaignConfiguration {\n initialize: (\n eventSource: IExternalEventSourceConstructor,\n ) => Promise<Result<void, KameleoonError>>;\n addTargetingData: (\n visitorCode: string,\n ...data: KameleoonDataType[]\n ) => Result<void, KameleoonError>;\n getUnsentData: (visitorCode: string) => KameleoonDataType[];\n clearUnsentData: (visitorCode: string) => void;\n onConfigurationUpdate: (callback: () => void) => void;\n readonly experiments: ExperimentItemType[];\n readonly storedTargetingData: TargetingDataType;\n readonly featureFlags: FeatureFlagType[];\n readonly configuration: ConfigurationType;\n}\n\nexport class CampaignConfiguration implements ICampaignConfiguration {\n private configurationUpdateCallback?: () => void;\n private updateConfigurationIntervalId: NodeJS.Timer | null = null;\n private targetingDataIntervalId: NodeJS.Timer | null = null;\n private unsentTargetingData: UnsentTargetingDataType = {};\n private targetingData: TargetingDataType =\n DEFAULT_CAMPAIGN_CONFIGURATION.targetingData;\n private configurationData: ConfigurationDataType =\n DEFAULT_CAMPAIGN_CONFIGURATION.configurationData;\n private settings: ClientSettingsType;\n private lastUpdate: Date;\n private storage: IStorage<ClientDataType>;\n private requester: Requester;\n private eventSource?: IEventSource;\n private externalClientConfiguration?: GetClientConfigurationResultType;\n\n constructor({\n settings,\n storage,\n requester,\n externalClientConfiguration,\n targetingCleanupInterval,\n }: CampaignConfigurationParametersType) {\n this.requester = requester;\n this.settings = settings;\n this.lastUpdate = new Date();\n this.storage = storage;\n this.readStorageData();\n this.externalClientConfiguration = externalClientConfiguration;\n\n if (targetingCleanupInterval) {\n const cleanupIntervalMinutes =\n targetingCleanupInterval < 0 ? 1 : targetingCleanupInterval;\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 () =>\n this.cleanupOutdatedTargetingData.call(this, this.targetingData),\n cleanupIntervalMinutes * 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 async initialize(\n externalEventSource: IExternalEventSourceConstructor,\n ): Promise<Result<void, KameleoonError>> {\n const shouldUpdate = this.checkShouldUpdate();\n\n // --- Initial data fetch ---\n if (shouldUpdate) {\n const updateResult = await this.updateClientConfiguration();\n\n if (!updateResult.ok) {\n return updateResult;\n }\n }\n\n // --- Note ---\n // Interval is cleaned up in case real time update\n // was activated while initialized client already exists\n if (\n this.configurationData.configuration.realTimeUpdate &&\n !this.externalClientConfiguration\n ) {\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n this.eventSource = new ExternalEventSource(\n this.settings.siteCode,\n externalEventSource,\n );\n\n const updateEventCallback = (_timeStamp: number) => {\n this.updateClientConfiguration();\n\n if (this.configurationUpdateCallback) {\n this.configurationUpdateCallback();\n }\n };\n\n this.eventSource.open(updateEventCallback);\n } else {\n // --- Note ---\n // Event Source is cleaned up in case real time update\n // was disabled while initialized client already exists\n if (this.eventSource) {\n this.eventSource.close();\n }\n\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n // --- Note ---\n // Same as targeting data interval we don't want to make failed configuration\n // retrieval recoverable\n try {\n this.updateConfigurationIntervalId = setInterval(\n this.updateClientConfiguration.bind(this),\n this.settings.updateInterval,\n );\n } catch (err) {\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n throw err;\n }\n }\n\n return Ok();\n }\n\n public addTargetingData(\n visitorCode: string,\n ...data: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n if (!(visitorCode in this.targetingData)) {\n this.targetingData[visitorCode] = [];\n }\n\n data.forEach((dataItem) => {\n // --- Note ---\n // Previous check excludes the failure possibility\n (this.targetingData[visitorCode] as TargetingDataItemType[]).push({\n data: dataItem.data,\n lastActivityTime: Date.now(),\n });\n });\n\n // --- Note ---\n // `targetingData` should not refresh `lastUpdate` time\n const result = this.updateStorageData(this.lastUpdate);\n\n if (result.ok) {\n data.forEach((dataItem) => {\n if (!this.unsentTargetingData[visitorCode]) {\n this.unsentTargetingData[visitorCode] = [];\n }\n\n this.unsentTargetingData[visitorCode].push(dataItem);\n });\n }\n\n return result;\n }\n\n public getUnsentData(visitorCode: string): KameleoonDataType[] {\n const unsentDataItem = this.unsentTargetingData[visitorCode];\n\n if (!unsentDataItem) {\n return [];\n }\n\n return unsentDataItem;\n }\n\n public clearUnsentData(visitorCode: string): void {\n this.unsentTargetingData[visitorCode] = [];\n }\n\n public onConfigurationUpdate(callback: () => void): void {\n this.configurationUpdateCallback = callback;\n }\n\n get storedTargetingData(): TargetingDataType {\n return this.targetingData;\n }\n\n get experiments(): ExperimentItemType[] {\n return this.configurationData.experiments;\n }\n\n get featureFlags(): FeatureFlagType[] {\n return this.configurationData.featureFlags;\n }\n\n get configuration(): ConfigurationType {\n return this.configurationData.configuration;\n }\n\n private checkShouldUpdate(): boolean {\n const { featureFlags, experiments, configuration } = this.configurationData;\n const { updateInterval } = this.settings;\n\n if (!featureFlags.length && !experiments.length) {\n return true;\n }\n\n if (configuration.realTimeUpdate) {\n return true;\n }\n\n const lastUpdateTime = this.lastUpdate.getTime();\n const updateWindowEdge = Date.now() - updateInterval;\n\n return lastUpdateTime < updateWindowEdge;\n }\n\n private cleanupOutdatedTargetingData(data: TargetingDataType): void {\n const currentTime = Date.now();\n const resultTargetingData: TargetingDataType = { ...data };\n\n for (const [key, value] of Object.entries(resultTargetingData)) {\n if (value) {\n const resultValue = value.filter((item) => {\n const isDataExpired =\n item.lastActivityTime + SESSION_DURATION < currentTime;\n\n return isDataExpired;\n });\n\n resultTargetingData[key] = resultValue;\n } else {\n resultTargetingData[key] = [];\n }\n }\n\n this.targetingData = resultTargetingData;\n // --- Note ---\n // `targetingData` should not refresh `lastUpdate` time\n this.updateStorageData(this.lastUpdate).throw();\n }\n\n private readStorageData(): void {\n const result = this.storage.read();\n\n if (result.ok) {\n const { kameleoonTargetingData, kameleoonConfiguration, lastUpdate } =\n result.data;\n\n this.configurationData = kameleoonConfiguration;\n this.targetingData = kameleoonTargetingData;\n this.lastUpdate = new Date(Date.parse(lastUpdate));\n }\n }\n\n private async updateClientConfiguration(\n timeStamp?: number,\n ): Promise<Result<boolean, KameleoonError>> {\n // --- Note ---\n // if `externalClientConfiguration` is passed, fetching is disabled and passed config is used instead\n if (this.externalClientConfiguration) {\n // --- Note ---\n // `featureFlags` field is omitted (v1)\n // instead `featureFlagConfigurations` is used (v2)\n const { configuration, experiments, featureFlagConfigurations } =\n this.externalClientConfiguration;\n\n this.configurationData = {\n configuration,\n experiments,\n featureFlags: featureFlagConfigurations,\n };\n } else {\n const clientConfigurationResult =\n await this.requester.getClientConfiguration(timeStamp);\n\n if (!clientConfigurationResult.ok) {\n return clientConfigurationResult;\n }\n\n // --- Note ---\n // `featureFlags` field is omitted (v1)\n // instead `featureFlagConfigurations` is used (v2)\n const { configuration, experiments, featureFlagConfigurations } =\n clientConfigurationResult.data;\n\n this.configurationData = {\n configuration,\n experiments,\n featureFlags: featureFlagConfigurations,\n };\n }\n\n const result = this.updateStorageData(new Date());\n\n if (!result.ok) {\n return result;\n }\n\n return Ok(true);\n }\n\n private updateStorageData(lastUpdate: Date): Result<void, KameleoonError> {\n const data: ClientDataType = {\n kameleoonTargetingData: this.targetingData,\n kameleoonConfiguration: this.configurationData,\n lastUpdate: lastUpdate.toString(),\n };\n\n return this.storage.write(data);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAD,OAAA;AAaA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AAAwC,SAAAI,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,UAAAG,MAAA,WAAAF,SAAA,CAAAD,CAAA,IAAAC,SAAA,CAAAD,CAAA,QAAAA,CAAA,OAAAf,OAAA,CAAAI,MAAA,CAAAc,MAAA,OAAAC,OAAA,WAAAC,GAAA,IAAAC,eAAA,CAAAP,MAAA,EAAAM,GAAA,EAAAF,MAAA,CAAAE,GAAA,SAAAhB,MAAA,CAAAkB,yBAAA,GAAAlB,MAAA,CAAAmB,gBAAA,CAAAT,MAAA,EAAAV,MAAA,CAAAkB,yBAAA,CAAAJ,MAAA,KAAAlB,OAAA,CAAAI,MAAA,CAAAc,MAAA,GAAAC,OAAA,WAAAC,GAAA,IAAAhB,MAAA,C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OqB,MAAM;IACf;IAEA,OAAO,IAAAP,SAAE,EAAC,IAAI,CAAC;EACjB;EAEQQ,iBAAiBA,CAACvC,UAAgB,EAAgC;IACxE,MAAMkC,IAAoB,GAAG;MAC3B2B,sBAAsB,EAAE,IAAI,CAAC/D,aAAa;MAC1CgE,sBAAsB,EAAE,IAAI,CAAC/D,iBAAiB;MAC9CC,UAAU,EAAEA,UAAU,CAACoE,QAAQ;IACjC,CAAC;IAED,OAAO,IAAI,CAAC3E,OAAO,CAAC4E,KAAK,CAACnC,IAAI,CAAC;EACjC;AACF;AAACoC,OAAA,CAAAhF,qBAAA,GAAAA,qBAAA"}
|
|
1
|
+
{"version":3,"file":"campaignConfiguration.js","names":["_tsRes","require","_constants","_eventSource","_types","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","obj","value","_toPropertyKey","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","CampaignConfiguration","constructor","settings","storage","requester","externalClientConfiguration","targetingCleanupInterval","DEFAULT_CAMPAIGN_CONFIGURATION","targetingData","configurationData","lastUpdate","Date","readStorageData","cleanupIntervalMinutes","targetingDataIntervalId","setInterval","cleanupOutdatedTargetingData","Milliseconds","Minute","err","clearInterval","initialize","externalEventSource","useCache","shouldUpdate","checkShouldUpdate","updateResult","updateClientConfiguration","ok","configuration","realTimeUpdate","updateConfigurationIntervalId","eventSource","ExternalEventSource","siteCode","updateEventCallback","_timeStamp","configurationUpdateCallback","open","close","bind","updateInterval","Ok","addTargetingData","visitorCode","data","dataItem","lastActivityTime","now","result","updateStorageData","unsentTargetingData","getUnsentData","unsentDataItem","clearUnsentData","onConfigurationUpdate","callback","storedTargetingData","experiments","featureFlags","lastUpdateTime","getTime","updateWindowEdge","currentTime","resultTargetingData","entries","resultValue","item","isDataExpired","SESSION_DURATION","throw","read","kameleoonTargetingData","kameleoonConfiguration","parse","timeStamp","featureFlagConfigurations","clientConfigurationResult","getClientConfiguration","toString","write","exports"],"sources":["../../src/campaignConfiguration/campaignConfiguration.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from '../kameleoonError/kameleoonError';\nimport { ClientSettingsType } from '../clientSettings/types';\nimport { DEFAULT_CAMPAIGN_CONFIGURATION, SESSION_DURATION } from './constants';\nimport {\n CampaignConfigurationParametersType,\n ConfigurationDataType,\n ConfigurationType,\n ExperimentItemType,\n FeatureFlagType,\n UnsentTargetingDataType,\n UpdateClientConfigurationParameters,\n} from './types';\nimport { KameleoonDataType } from '../kameleoonData';\nimport { Requester, GetClientConfigurationResultType } from '../requester';\nimport { TargetingDataItemType, TargetingDataType } from '../targeting';\nimport { IStorage, ClientDataType } from '../storage';\nimport {\n ExternalEventSource,\n IEventSource,\n IExternalEventSourceConstructor,\n} from '../eventSource';\nimport { Milliseconds } from '../types';\n\ninterface ICampaignConfiguration {\n initialize: (\n eventSource: IExternalEventSourceConstructor,\n useCache?: boolean,\n ) => Promise<Result<void, KameleoonError>>;\n addTargetingData: (\n visitorCode: string,\n ...data: KameleoonDataType[]\n ) => Result<void, KameleoonError>;\n getUnsentData: (visitorCode: string) => KameleoonDataType[];\n clearUnsentData: (visitorCode: string) => void;\n onConfigurationUpdate: (callback: () => void) => void;\n readonly experiments: ExperimentItemType[];\n readonly storedTargetingData: TargetingDataType;\n readonly featureFlags: FeatureFlagType[];\n readonly configuration: ConfigurationType;\n}\n\nexport class CampaignConfiguration implements ICampaignConfiguration {\n private configurationUpdateCallback?: () => void;\n private updateConfigurationIntervalId: NodeJS.Timer | null = null;\n private targetingDataIntervalId: NodeJS.Timer | null = null;\n private unsentTargetingData: UnsentTargetingDataType = {};\n private targetingData: TargetingDataType =\n DEFAULT_CAMPAIGN_CONFIGURATION.targetingData;\n private configurationData: ConfigurationDataType =\n DEFAULT_CAMPAIGN_CONFIGURATION.configurationData;\n private settings: ClientSettingsType;\n private lastUpdate: Date;\n private storage: IStorage<ClientDataType>;\n private requester: Requester;\n private eventSource?: IEventSource;\n private externalClientConfiguration?: GetClientConfigurationResultType;\n\n constructor({\n settings,\n storage,\n requester,\n externalClientConfiguration,\n targetingCleanupInterval,\n }: CampaignConfigurationParametersType) {\n this.requester = requester;\n this.settings = settings;\n this.lastUpdate = new Date();\n this.storage = storage;\n this.readStorageData();\n this.externalClientConfiguration = externalClientConfiguration;\n\n if (targetingCleanupInterval) {\n const cleanupIntervalMinutes =\n targetingCleanupInterval < 0 ? 1 : targetingCleanupInterval;\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 () =>\n this.cleanupOutdatedTargetingData.call(this, this.targetingData),\n cleanupIntervalMinutes * 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 async initialize(\n externalEventSource: IExternalEventSourceConstructor,\n useCache?: boolean,\n ): Promise<Result<void, KameleoonError>> {\n const shouldUpdate = this.checkShouldUpdate();\n\n // --- Initial data fetch ---\n if (shouldUpdate) {\n const updateResult = await this.updateClientConfiguration({ useCache });\n\n if (!updateResult.ok) {\n return updateResult;\n }\n }\n\n // --- Note ---\n // Interval is cleaned up in case real time update\n // was activated while initialized client already exists\n if (\n this.configurationData.configuration.realTimeUpdate &&\n !this.externalClientConfiguration\n ) {\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n this.eventSource = new ExternalEventSource(\n this.settings.siteCode,\n externalEventSource,\n );\n\n const updateEventCallback = (_timeStamp: number) => {\n this.updateClientConfiguration({ useCache });\n\n if (this.configurationUpdateCallback) {\n this.configurationUpdateCallback();\n }\n };\n\n this.eventSource.open(updateEventCallback);\n } else {\n // --- Note ---\n // Event Source is cleaned up in case real time update\n // was disabled while initialized client already exists\n if (this.eventSource) {\n this.eventSource.close();\n }\n\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n // --- Note ---\n // Same as targeting data interval we don't want to make failed configuration\n // retrieval recoverable\n try {\n this.updateConfigurationIntervalId = setInterval(\n () => this.updateClientConfiguration.bind(this)({ useCache }),\n this.settings.updateInterval,\n );\n } catch (err) {\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n throw err;\n }\n }\n\n return Ok();\n }\n\n public addTargetingData(\n visitorCode: string,\n ...data: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n if (!(visitorCode in this.targetingData)) {\n this.targetingData[visitorCode] = [];\n }\n\n data.forEach((dataItem) => {\n // --- Note ---\n // Previous check excludes the failure possibility\n (this.targetingData[visitorCode] as TargetingDataItemType[]).push({\n data: dataItem.data,\n lastActivityTime: Date.now(),\n });\n });\n\n // --- Note ---\n // `targetingData` should not refresh `lastUpdate` time\n const result = this.updateStorageData(this.lastUpdate);\n\n if (result.ok) {\n data.forEach((dataItem) => {\n if (!this.unsentTargetingData[visitorCode]) {\n this.unsentTargetingData[visitorCode] = [];\n }\n\n this.unsentTargetingData[visitorCode].push(dataItem);\n });\n }\n\n return result;\n }\n\n public getUnsentData(visitorCode: string): KameleoonDataType[] {\n const unsentDataItem = this.unsentTargetingData[visitorCode];\n\n if (!unsentDataItem) {\n return [];\n }\n\n return unsentDataItem;\n }\n\n public clearUnsentData(visitorCode: string): void {\n this.unsentTargetingData[visitorCode] = [];\n }\n\n public onConfigurationUpdate(callback: () => void): void {\n this.configurationUpdateCallback = callback;\n }\n\n get storedTargetingData(): TargetingDataType {\n return this.targetingData;\n }\n\n get experiments(): ExperimentItemType[] {\n return this.configurationData.experiments;\n }\n\n get featureFlags(): FeatureFlagType[] {\n return this.configurationData.featureFlags;\n }\n\n get configuration(): ConfigurationType {\n return this.configurationData.configuration;\n }\n\n private checkShouldUpdate(): boolean {\n const { featureFlags, experiments, configuration } = this.configurationData;\n const { updateInterval } = this.settings;\n\n if (!featureFlags.length && !experiments.length) {\n return true;\n }\n\n if (configuration.realTimeUpdate) {\n return true;\n }\n\n const lastUpdateTime = this.lastUpdate.getTime();\n const updateWindowEdge = Date.now() - updateInterval;\n\n return lastUpdateTime < updateWindowEdge;\n }\n\n private cleanupOutdatedTargetingData(data: TargetingDataType): void {\n const currentTime = Date.now();\n const resultTargetingData: TargetingDataType = { ...data };\n\n for (const [key, value] of Object.entries(resultTargetingData)) {\n if (value) {\n const resultValue = value.filter((item) => {\n const isDataExpired =\n item.lastActivityTime + SESSION_DURATION < currentTime;\n\n return isDataExpired;\n });\n\n resultTargetingData[key] = resultValue;\n } else {\n resultTargetingData[key] = [];\n }\n }\n\n this.targetingData = resultTargetingData;\n // --- Note ---\n // `targetingData` should not refresh `lastUpdate` time\n this.updateStorageData(this.lastUpdate).throw();\n }\n\n private readStorageData(): void {\n const result = this.storage.read();\n\n if (result.ok) {\n const { kameleoonTargetingData, kameleoonConfiguration, lastUpdate } =\n result.data;\n\n this.configurationData = kameleoonConfiguration;\n this.targetingData = kameleoonTargetingData;\n this.lastUpdate = new Date(Date.parse(lastUpdate));\n }\n }\n\n private async updateClientConfiguration({\n useCache = false,\n timeStamp,\n }: UpdateClientConfigurationParameters = {}): Promise<\n Result<boolean, KameleoonError>\n > {\n // --- Note ---\n // if `externalClientConfiguration` is passed, fetching is disabled and passed config is used instead\n if (this.externalClientConfiguration) {\n // --- Note ---\n // `featureFlags` field is omitted (v1)\n // instead `featureFlagConfigurations` is used (v2)\n const { configuration, experiments, featureFlagConfigurations } =\n this.externalClientConfiguration;\n\n this.configurationData = {\n configuration,\n experiments,\n featureFlags: featureFlagConfigurations,\n };\n } else {\n const clientConfigurationResult =\n await this.requester.getClientConfiguration(timeStamp);\n\n if (!clientConfigurationResult.ok) {\n const { featureFlags, experiments } = this.configurationData;\n\n if (useCache && featureFlags.length && experiments.length) {\n return Ok(true);\n }\n\n return clientConfigurationResult;\n }\n\n // --- Note ---\n // `featureFlags` field is omitted (v1)\n // instead `featureFlagConfigurations` is used (v2)\n const { configuration, experiments, featureFlagConfigurations } =\n clientConfigurationResult.data;\n\n this.configurationData = {\n configuration,\n experiments,\n featureFlags: featureFlagConfigurations,\n };\n }\n\n const result = this.updateStorageData(new Date());\n\n if (!result.ok) {\n return result;\n }\n\n return Ok(true);\n }\n\n private updateStorageData(lastUpdate: Date): Result<void, KameleoonError> {\n const data: ClientDataType = {\n kameleoonTargetingData: this.targetingData,\n kameleoonConfiguration: this.configurationData,\n lastUpdate: lastUpdate.toString(),\n };\n\n return this.storage.write(data);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAD,OAAA;AAcA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AAAwC,SAAAI,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,UAAAG,MAAA,WAAAF,SAAA,CAAAD,CAAA,IAAAC,SAAA,CAAAD,CAAA,QAAAA,CAAA,OAAAf,OAAA,CAAAI,MAAA,CAAAc,MAAA,OAAAC,OAAA,WAAAC,GAAA,IAAAC,eAAA,CAAAP,MAAA,E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I,CAACE,yBAAyB,CAACjD,EAAE,EAAE;QACjC,MAAM;UAAE+B,YAAY;UAAED;QAAY,CAAC,GAAG,IAAI,CAACjD,iBAAiB;QAE5D,IAAIc,QAAQ,IAAIoC,YAAY,CAACrF,MAAM,IAAIoF,WAAW,CAACpF,MAAM,EAAE;UACzD,OAAO,IAAAoE,SAAE,EAAC,IAAI,CAAC;QACjB;QAEA,OAAOmC,yBAAyB;MAClC;;MAEA;MACA;MACA;MACA,MAAM;QAAEhD,aAAa;QAAE6B,WAAW;QAAEkB;MAA0B,CAAC,GAC7DC,yBAAyB,CAAChC,IAAI;MAEhC,IAAI,CAACpC,iBAAiB,GAAG;QACvBoB,aAAa;QACb6B,WAAW;QACXC,YAAY,EAAEiB;MAChB,CAAC;IACH;IAEA,MAAM3B,MAAM,GAAG,IAAI,CAACC,iBAAiB,CAAC,IAAIvC,IAAI,EAAE,CAAC;IAEjD,IAAI,CAACsC,MAAM,CAACrB,EAAE,EAAE;MACd,OAAOqB,MAAM;IACf;IAEA,OAAO,IAAAP,SAAE,EAAC,IAAI,CAAC;EACjB;EAEQQ,iBAAiBA,CAACxC,UAAgB,EAAgC;IACxE,MAAMmC,IAAoB,GAAG;MAC3B2B,sBAAsB,EAAE,IAAI,CAAChE,aAAa;MAC1CiE,sBAAsB,EAAE,IAAI,CAAChE,iBAAiB;MAC9CC,UAAU,EAAEA,UAAU,CAACqE,QAAQ;IACjC,CAAC;IAED,OAAO,IAAI,CAAC5E,OAAO,CAAC6E,KAAK,CAACnC,IAAI,CAAC;EACjC;AACF;AAACoC,OAAA,CAAAjF,qBAAA,GAAAA,qBAAA"}
|
|
@@ -4,6 +4,10 @@ import { Requester, GetClientConfigurationResultType } from '../requester';
|
|
|
4
4
|
import { ClientDataType, IStorage } from '../storage';
|
|
5
5
|
import { SegmentType, TargetingDataType } from '../targeting';
|
|
6
6
|
import { VariableType } from '../types';
|
|
7
|
+
export type UpdateClientConfigurationParameters = {
|
|
8
|
+
timeStamp?: number;
|
|
9
|
+
useCache?: boolean;
|
|
10
|
+
};
|
|
7
11
|
export type ScheduleType = {
|
|
8
12
|
dateStart: string;
|
|
9
13
|
dateEnd: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["ExperimentType","exports","RuleType","FeatureFlagSdkLanguageType","FeatureStatus","ExperimentStatus"],"sources":["../../src/campaignConfiguration/types.ts"],"sourcesContent":["import { ClientSettingsType } from '../clientSettings';\nimport { KameleoonDataType } from '../kameleoonData';\nimport { Requester, GetClientConfigurationResultType } from '../requester';\nimport { ClientDataType, IStorage } from '../storage';\nimport { SegmentType, TargetingDataType } from '../targeting';\nimport { VariableType } from '../types';\n\nexport type ScheduleType = {\n dateStart: string;\n dateEnd: string;\n};\n\nexport type JSONValue =\n | string\n | number\n | boolean\n | { [x: string]: JSONValue }\n | JSONValue[];\n\nexport type JSONType = Record<string | number | symbol, JSONValue> | null;\n\nexport enum ExperimentType {\n CLASSIC = 'CLASSIC',\n SERVER_SIDE = 'SERVER_SIDE',\n DEVELOPER = 'DEVELOPER',\n MVT = 'MVT',\n HYBRID = 'HYBRID',\n}\n\nexport enum RuleType {\n PROGRESSIVE_DELIVERY = 'PROGRESSIVE_DELIVERY',\n TARGETED_DELIVERY = 'TARGETED_DELIVERY',\n EXPERIMENTATION = 'EXPERIMENTATION',\n}\n\nexport enum FeatureFlagSdkLanguageType {\n ANDROID = 'ANDROID',\n SWIFT = 'SWIFT',\n JAVA = 'JAVA',\n CSHARP = 'CSHARP',\n NODEJS = 'NODEJS',\n PHP = 'PHP',\n RUBY = 'RUBY',\n GO = 'GO',\n FLUTTER = 'FLUTTER',\n REACTJS = 'REACTJS',\n}\n\nexport enum FeatureStatus {\n ACTIVATED = 'ACTIVATED',\n DEACTIVATED = 'DEACTIVATED',\n SCHEDULED = 'SCHEDULED',\n}\n\nexport type ExperimentItemType = {\n id: string;\n name: string;\n type: ExperimentType;\n siteId: string;\n siteCode: string;\n status: ExperimentStatus;\n siteEnabled: boolean;\n variations: ExperimentVariationType[];\n deviations: DeviationType[];\n respoolTime: RespoolTimeType[];\n segment: SegmentType | null;\n};\n\nexport type ExperimentVariationType = {\n id: string;\n customJson: string;\n};\n\nexport type DeviationType = {\n variationId: string;\n value: number;\n};\n\nexport type RespoolTimeType = {\n variationId: string;\n value: number;\n};\n\nexport enum ExperimentStatus {\n DRAFT = 'DRAFT',\n ACTIVE = 'ACTIVE',\n PAUSED = 'PAUSED',\n SCHEDULED = 'SCHEDULED',\n STOPPED = 'STOPPED',\n USED_AS_PERSONALIZATION = 'USED_AS_PERSONALIZATION',\n DEVIATED = 'DEVIATED',\n}\n\nexport type FeatureFlagType = {\n id: number;\n featureKey: string;\n variations: FeatureVariationType[];\n defaultVariationKey: string;\n rules: RuleItemType[];\n};\n\nexport type FeatureVariationType = {\n key: string;\n variables: FeatureVariableType[];\n};\n\nexport type FeatureVariableType = {\n key: string;\n type: VariableType;\n value: string | number | boolean;\n};\n\nexport type RuleItemType = {\n type: RuleType;\n id: number;\n respoolTime: number | null;\n order: number;\n exposition: number;\n experimentId: number;\n variationByExposition: VariationByExpositionType[];\n segment: SegmentType | null;\n};\n\nexport type VariationByExpositionType = {\n variationKey: string;\n variationId: number | null;\n exposition: number;\n};\n\nexport type ConfigurationDataType = {\n experiments: ExperimentItemType[];\n featureFlags: FeatureFlagType[];\n configuration: ConfigurationType;\n};\n\nexport type ConfigurationType = {\n realTimeUpdate: boolean;\n};\n\nexport type CampaignConfigurationType = {\n targetingData: TargetingDataType;\n configurationData: ConfigurationDataType;\n};\n\nexport type UnsentTargetingDataType = {\n [visitorCode: string]: KameleoonDataType[];\n};\n\nexport type CampaignConfigurationParametersType = {\n settings: ClientSettingsType;\n storage: IStorage<ClientDataType>;\n requester: Requester;\n externalClientConfiguration?: GetClientConfigurationResultType;\n targetingCleanupInterval?: number;\n};\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"types.js","names":["ExperimentType","exports","RuleType","FeatureFlagSdkLanguageType","FeatureStatus","ExperimentStatus"],"sources":["../../src/campaignConfiguration/types.ts"],"sourcesContent":["import { ClientSettingsType } from '../clientSettings';\nimport { KameleoonDataType } from '../kameleoonData';\nimport { Requester, GetClientConfigurationResultType } from '../requester';\nimport { ClientDataType, IStorage } from '../storage';\nimport { SegmentType, TargetingDataType } from '../targeting';\nimport { VariableType } from '../types';\n\nexport type UpdateClientConfigurationParameters = {\n timeStamp?: number;\n useCache?: boolean;\n};\n\nexport type ScheduleType = {\n dateStart: string;\n dateEnd: string;\n};\n\nexport type JSONValue =\n | string\n | number\n | boolean\n | { [x: string]: JSONValue }\n | JSONValue[];\n\nexport type JSONType = Record<string | number | symbol, JSONValue> | null;\n\nexport enum ExperimentType {\n CLASSIC = 'CLASSIC',\n SERVER_SIDE = 'SERVER_SIDE',\n DEVELOPER = 'DEVELOPER',\n MVT = 'MVT',\n HYBRID = 'HYBRID',\n}\n\nexport enum RuleType {\n PROGRESSIVE_DELIVERY = 'PROGRESSIVE_DELIVERY',\n TARGETED_DELIVERY = 'TARGETED_DELIVERY',\n EXPERIMENTATION = 'EXPERIMENTATION',\n}\n\nexport enum FeatureFlagSdkLanguageType {\n ANDROID = 'ANDROID',\n SWIFT = 'SWIFT',\n JAVA = 'JAVA',\n CSHARP = 'CSHARP',\n NODEJS = 'NODEJS',\n PHP = 'PHP',\n RUBY = 'RUBY',\n GO = 'GO',\n FLUTTER = 'FLUTTER',\n REACTJS = 'REACTJS',\n}\n\nexport enum FeatureStatus {\n ACTIVATED = 'ACTIVATED',\n DEACTIVATED = 'DEACTIVATED',\n SCHEDULED = 'SCHEDULED',\n}\n\nexport type ExperimentItemType = {\n id: string;\n name: string;\n type: ExperimentType;\n siteId: string;\n siteCode: string;\n status: ExperimentStatus;\n siteEnabled: boolean;\n variations: ExperimentVariationType[];\n deviations: DeviationType[];\n respoolTime: RespoolTimeType[];\n segment: SegmentType | null;\n};\n\nexport type ExperimentVariationType = {\n id: string;\n customJson: string;\n};\n\nexport type DeviationType = {\n variationId: string;\n value: number;\n};\n\nexport type RespoolTimeType = {\n variationId: string;\n value: number;\n};\n\nexport enum ExperimentStatus {\n DRAFT = 'DRAFT',\n ACTIVE = 'ACTIVE',\n PAUSED = 'PAUSED',\n SCHEDULED = 'SCHEDULED',\n STOPPED = 'STOPPED',\n USED_AS_PERSONALIZATION = 'USED_AS_PERSONALIZATION',\n DEVIATED = 'DEVIATED',\n}\n\nexport type FeatureFlagType = {\n id: number;\n featureKey: string;\n variations: FeatureVariationType[];\n defaultVariationKey: string;\n rules: RuleItemType[];\n};\n\nexport type FeatureVariationType = {\n key: string;\n variables: FeatureVariableType[];\n};\n\nexport type FeatureVariableType = {\n key: string;\n type: VariableType;\n value: string | number | boolean;\n};\n\nexport type RuleItemType = {\n type: RuleType;\n id: number;\n respoolTime: number | null;\n order: number;\n exposition: number;\n experimentId: number;\n variationByExposition: VariationByExpositionType[];\n segment: SegmentType | null;\n};\n\nexport type VariationByExpositionType = {\n variationKey: string;\n variationId: number | null;\n exposition: number;\n};\n\nexport type ConfigurationDataType = {\n experiments: ExperimentItemType[];\n featureFlags: FeatureFlagType[];\n configuration: ConfigurationType;\n};\n\nexport type ConfigurationType = {\n realTimeUpdate: boolean;\n};\n\nexport type CampaignConfigurationType = {\n targetingData: TargetingDataType;\n configurationData: ConfigurationDataType;\n};\n\nexport type UnsentTargetingDataType = {\n [visitorCode: string]: KameleoonDataType[];\n};\n\nexport type CampaignConfigurationParametersType = {\n settings: ClientSettingsType;\n storage: IStorage<ClientDataType>;\n requester: Requester;\n externalClientConfiguration?: GetClientConfigurationResultType;\n targetingCleanupInterval?: number;\n};\n"],"mappings":";;;;;;IA0BYA,cAAc,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA;AAAAC,OAAA,CAAAD,cAAA,GAAAA,cAAA;AAAA,IAQdE,QAAQ,0BAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA;AAAAD,OAAA,CAAAC,QAAA,GAAAA,QAAA;AAAA,IAMRC,0BAA0B,0BAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAA1BA,0BAA0B;EAAA,OAA1BA,0BAA0B;AAAA;AAAAF,OAAA,CAAAE,0BAAA,GAAAA,0BAAA;AAAA,IAa1BC,aAAa,0BAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAbA,aAAa;EAAA,OAAbA,aAAa;AAAA;AAAAH,OAAA,CAAAG,aAAA,GAAAA,aAAA;AAAA,IAmCbC,gBAAgB,0BAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAA,OAAhBA,gBAAgB;AAAA;AAAAJ,OAAA,CAAAI,gBAAA,GAAAA,gBAAA"}
|
|
@@ -10,7 +10,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
10
10
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
11
11
|
class ClientSettings {
|
|
12
12
|
constructor(siteCode, configuration) {
|
|
13
|
-
_defineProperty(this, "updateInterval",
|
|
13
|
+
_defineProperty(this, "updateInterval", 60 * _types.Milliseconds.Minute);
|
|
14
14
|
_defineProperty(this, "environment", void 0);
|
|
15
15
|
_defineProperty(this, "siteCode", void 0);
|
|
16
16
|
this.siteCode = siteCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientSettings.js","names":["_types","require","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","ClientSettings","constructor","siteCode","configuration","Milliseconds","Minute","environment","updateInterval","settings","exports"],"sources":["../../src/clientSettings/clientSettings.ts"],"sourcesContent":["import { Environment, Milliseconds, SDKConfigurationType } from '../types';\nimport { ClientSettingsType } from './types';\n\nexport interface IClientSettings {\n readonly settings: ClientSettingsType;\n}\n\nexport class ClientSettings implements IClientSettings {\n private updateInterval: number =
|
|
1
|
+
{"version":3,"file":"clientSettings.js","names":["_types","require","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","ClientSettings","constructor","siteCode","configuration","Milliseconds","Minute","environment","updateInterval","settings","exports"],"sources":["../../src/clientSettings/clientSettings.ts"],"sourcesContent":["import { Environment, Milliseconds, SDKConfigurationType } from '../types';\nimport { ClientSettingsType } from './types';\n\nexport interface IClientSettings {\n readonly settings: ClientSettingsType;\n}\n\nexport class ClientSettings implements IClientSettings {\n private updateInterval: number = 60 * Milliseconds.Minute;\n private environment?: Environment;\n private siteCode: string;\n\n constructor(siteCode: string, configuration?: Partial<SDKConfigurationType>) {\n this.siteCode = siteCode;\n\n if (configuration?.environment) {\n this.environment = configuration.environment;\n }\n\n if (configuration?.updateInterval) {\n if (configuration.updateInterval < 1) {\n this.updateInterval = 1 * Milliseconds.Minute;\n }\n\n this.updateInterval = configuration.updateInterval * Milliseconds.Minute;\n }\n }\n\n get settings(): ClientSettingsType {\n return {\n updateInterval: this.updateInterval,\n environment: this.environment,\n siteCode: this.siteCode,\n };\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAA2E,SAAAC,gBAAAC,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AGH,mBAAY,CAACC,MAAM;IAC1E;EACF;EAEA,IAAIG,QAAQA,CAAA,EAAuB;IACjC,OAAO;MACLD,cAAc,EAAE,IAAI,CAACA,cAAc;MACnCD,WAAW,EAAE,IAAI,CAACA,WAAW;MAC7BJ,QAAQ,EAAE,IAAI,CAACA;IACjB,CAAC;EACH;AACF;AAACO,OAAA,CAAAT,cAAA,GAAAA,cAAA"}
|
|
@@ -14,7 +14,7 @@ class ExternalEventSource {
|
|
|
14
14
|
constructor(siteCode, externalEventSource) {
|
|
15
15
|
_defineProperty(this, "eventSource", void 0);
|
|
16
16
|
_defineProperty(this, "siteCode", void 0);
|
|
17
|
-
const url = _requester.URL.
|
|
17
|
+
const url = _requester.URL.SERVER_SENT_EVENTS + _constants.UrlQuery.Sse + siteCode;
|
|
18
18
|
const eventSource = externalEventSource.initialize(url);
|
|
19
19
|
this.eventSource = eventSource;
|
|
20
20
|
this.siteCode = siteCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"externalEventSource.js","names":["_requester","require","_constants","_constants2","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","ExternalEventSource","constructor","siteCode","externalEventSource","url","URL","
|
|
1
|
+
{"version":3,"file":"externalEventSource.js","names":["_requester","require","_constants","_constants2","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","ExternalEventSource","constructor","siteCode","externalEventSource","url","URL","SERVER_SENT_EVENTS","UrlQuery","Sse","eventSource","initialize","open","onEvent","eventType","REAL_TIME_EVENT","close","exports"],"sources":["../../src/eventSource/externalEventSource.ts"],"sourcesContent":["import { URL } from '../requester';\nimport { UrlQuery } from '../requester/constants';\nimport { REAL_TIME_EVENT } from './constants';\nimport { IExternalEventSource, IExternalEventSourceConstructor } from './types';\n\nexport interface IEventSource {\n open: (onEvent: (timestamp: number) => void) => void;\n close: () => void;\n}\n\nexport class ExternalEventSource implements IEventSource {\n private eventSource: IExternalEventSource;\n private siteCode: string;\n\n constructor(\n siteCode: string,\n externalEventSource: IExternalEventSourceConstructor,\n ) {\n const url = URL.SERVER_SENT_EVENTS + UrlQuery.Sse + siteCode;\n const eventSource = externalEventSource.initialize(url);\n\n this.eventSource = eventSource;\n this.siteCode = siteCode;\n }\n\n public open(onEvent: (timestamp: number) => void): void {\n this.eventSource.open({\n onEvent,\n siteCode: this.siteCode,\n eventType: REAL_TIME_EVENT,\n });\n }\n\n public close(): void {\n this.eventSource.close();\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAA8C,SAAAG,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,GAAA,QAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,2BAAAR,GAAA,gBAAAA,GAAA,GAAAU,MAAA,CAAAV,GAAA;AAAA,SAAAS,aAAAE,KAAA,EAAAC,IAAA,eAAAD,KAAA,iBAAAA,KAAA,kBAAAA,KAAA,MAAAE,IAAA,GAAAF,KAAA,CAAAG,MAAA,CAAAC,WAAA,OAAAF,IAAA,KAAAG,SAAA,QAAAC,GAAA,GAAAJ,IAAA,CAAAK,IAAA,CAAAP,KAAA,EAAAC,IAAA,2BAAAK,GAAA,sBAAAA,GAAA,YAAAE,SAAA,4DAAAP,IAAA,gBAAAF,MAAA,GAAAU,MAAA,EAAAT,KAAA;AAQvC,MAAMU,mBAAmB,CAAyB;EAIvDC,WAAWA,CACTC,QAAgB,EAChBC,mBAAoD,EACpD;IAAA1B,eAAA;IAAAA,eAAA;IACA,MAAM2B,GAAG,GAAGC,cAAG,CAACC,kBAAkB,GAAGC,mBAAQ,CAACC,GAAG,GAAGN,QAAQ;IAC5D,MAAMO,WAAW,GAAGN,mBAAmB,CAACO,UAAU,CAACN,GAAG,CAAC;IAEvD,IAAI,CAACK,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACP,QAAQ,GAAGA,QAAQ;EAC1B;EAEOS,IAAIA,CAACC,OAAoC,EAAQ;IACtD,IAAI,CAACH,WAAW,CAACE,IAAI,CAAC;MACpBC,OAAO;MACPV,QAAQ,EAAE,IAAI,CAACA,QAAQ;MACvBW,SAAS,EAAEC;IACb,CAAC,CAAC;EACJ;EAEOC,KAAKA,CAAA,EAAS;IACnB,IAAI,CAACN,WAAW,CAACM,KAAK,EAAE;EAC1B;AACF;AAACC,OAAA,CAAAhB,mBAAA,GAAAA,mBAAA"}
|
|
@@ -7,13 +7,16 @@ import { TrackConversionParamsType, ExperimentType, FeatureFlagType, GetFeatureF
|
|
|
7
7
|
export interface IKameleoonClient {
|
|
8
8
|
/**
|
|
9
9
|
* @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
|
|
10
|
+
* @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.
|
|
10
11
|
* @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail
|
|
11
12
|
* @throws `KameleoonError` with one of the following `type` s:
|
|
12
13
|
*
|
|
13
14
|
* - `KameleoonException.StorageWrite` Couldn't update storage data
|
|
14
15
|
* - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api
|
|
16
|
+
* - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed
|
|
15
17
|
*/
|
|
16
|
-
initialize
|
|
18
|
+
initialize(useCache?: boolean): Promise<boolean>;
|
|
19
|
+
initialize(): Promise<boolean>;
|
|
17
20
|
/**
|
|
18
21
|
* @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.
|
|
19
22
|
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
|
|
@@ -26,6 +29,16 @@ export interface IKameleoonClient {
|
|
|
26
29
|
* - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
|
|
27
30
|
*/
|
|
28
31
|
addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;
|
|
32
|
+
/**
|
|
33
|
+
* @method getRemoteVisitorData - an asynchronous method for retrieving custom data for the latest visit of `visitorCode` from Kameleoon Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.
|
|
34
|
+
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
|
|
35
|
+
* @param {boolean | undefined} shouldAddData - optional parameter for adding retrieved data to the storage like `addData` method does, default value is `true`
|
|
36
|
+
* @returns {KameleoonDataType[]} promise resolved to an array of `KameleoonData` instances, only includes custom data
|
|
37
|
+
* @throws `KameleoonError` with one of the following `type` s:
|
|
38
|
+
*
|
|
39
|
+
* - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server
|
|
40
|
+
*/
|
|
41
|
+
getRemoteVisitorData: (visitorCode: string, shouldAddData?: boolean) => Promise<KameleoonDataType[]>;
|
|
29
42
|
/**
|
|
30
43
|
* @method triggerExperiment - triggers experiment by assigning the variation to the user with `visitorCode`, if the variation is already assigned just returns it's id. Note: returned id `0` indicates default variation. At the same time executes `flushData` without sending extra request.
|
|
31
44
|
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
|
|
@@ -181,18 +194,19 @@ export interface IKameleoonClient {
|
|
|
181
194
|
* for communicating with Kameleoon JavaScript SDK Core, when new instance is created
|
|
182
195
|
*/
|
|
183
196
|
export declare class KameleoonClient implements IKameleoonClient {
|
|
184
|
-
private internalConfiguration;
|
|
185
197
|
private variationConfiguration?;
|
|
186
|
-
private campaignConfiguration
|
|
187
|
-
private
|
|
198
|
+
private campaignConfiguration;
|
|
199
|
+
private variationDataStorage;
|
|
188
200
|
private trackingCache;
|
|
189
201
|
private requester;
|
|
202
|
+
private externalEventSource;
|
|
190
203
|
/**
|
|
191
204
|
* @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core
|
|
192
205
|
*/
|
|
193
206
|
constructor({ siteCode, configuration, internalConfiguration, }: SDKCoreParameters);
|
|
194
|
-
initialize(): Promise<boolean>;
|
|
207
|
+
initialize(useCache?: boolean): Promise<boolean>;
|
|
195
208
|
addData(visitorCode: string, ...data: KameleoonDataType[]): void;
|
|
209
|
+
getRemoteVisitorData(visitorCode: string, shouldAddData?: boolean): Promise<KameleoonDataType[]>;
|
|
196
210
|
triggerExperiment(visitorCode: string, experimentId: number): number;
|
|
197
211
|
trackConversion({ visitorCode, goalId, revenue, }: TrackConversionParamsType): void;
|
|
198
212
|
flushData(visitorCode: string): void;
|
package/dist/kameleoonClient.js
CHANGED
|
@@ -35,18 +35,22 @@ class KameleoonClient {
|
|
|
35
35
|
configuration,
|
|
36
36
|
internalConfiguration
|
|
37
37
|
}) {
|
|
38
|
-
_defineProperty(this, "internalConfiguration", void 0);
|
|
39
38
|
_defineProperty(this, "variationConfiguration", void 0);
|
|
40
39
|
_defineProperty(this, "campaignConfiguration", void 0);
|
|
41
|
-
_defineProperty(this, "
|
|
40
|
+
_defineProperty(this, "variationDataStorage", void 0);
|
|
42
41
|
_defineProperty(this, "trackingCache", void 0);
|
|
43
42
|
_defineProperty(this, "requester", void 0);
|
|
43
|
+
_defineProperty(this, "externalEventSource", void 0);
|
|
44
44
|
const {
|
|
45
45
|
settings: clientSettings
|
|
46
46
|
} = new _clientSettings.ClientSettings(siteCode, configuration);
|
|
47
47
|
const {
|
|
48
|
+
externalStorage,
|
|
49
|
+
externalEventSource,
|
|
48
50
|
externalPackageInfo,
|
|
49
|
-
externalRequestDispatcher
|
|
51
|
+
externalRequestDispatcher,
|
|
52
|
+
externalClientConfiguration,
|
|
53
|
+
targetingDataCleanupInterval
|
|
50
54
|
} = internalConfiguration;
|
|
51
55
|
const requester = new _requester.Requester({
|
|
52
56
|
siteCode,
|
|
@@ -55,32 +59,26 @@ class KameleoonClient {
|
|
|
55
59
|
requestDispatcher: externalRequestDispatcher
|
|
56
60
|
});
|
|
57
61
|
const trackingCache = new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT);
|
|
58
|
-
this.requester = requester;
|
|
59
|
-
this.settings = clientSettings;
|
|
60
|
-
this.trackingCache = trackingCache;
|
|
61
|
-
this.internalConfiguration = internalConfiguration;
|
|
62
|
-
}
|
|
63
|
-
async initialize() {
|
|
64
|
-
const {
|
|
65
|
-
externalStorage,
|
|
66
|
-
externalEventSource,
|
|
67
|
-
externalClientConfiguration,
|
|
68
|
-
targetingDataCleanupInterval
|
|
69
|
-
} = this.internalConfiguration;
|
|
70
62
|
const clientDataStorage = new _externalStorage.ExternalStorage(externalStorage.initialize(_storage.KameleoonStorageKey.ClientData));
|
|
71
63
|
const variationDataStorage = new _externalStorage.ExternalStorage(externalStorage.initialize(_storage.KameleoonStorageKey.VariationData));
|
|
72
64
|
const campaignConfiguration = new _campaignConfiguration.CampaignConfiguration({
|
|
73
|
-
settings:
|
|
65
|
+
settings: clientSettings,
|
|
74
66
|
storage: clientDataStorage,
|
|
75
|
-
requester
|
|
67
|
+
requester,
|
|
76
68
|
externalClientConfiguration,
|
|
77
69
|
targetingCleanupInterval: targetingDataCleanupInterval
|
|
78
70
|
});
|
|
79
|
-
|
|
71
|
+
this.requester = requester;
|
|
72
|
+
this.trackingCache = trackingCache;
|
|
73
|
+
this.campaignConfiguration = campaignConfiguration;
|
|
74
|
+
this.variationDataStorage = variationDataStorage;
|
|
75
|
+
this.externalEventSource = externalEventSource;
|
|
76
|
+
}
|
|
77
|
+
async initialize(useCache) {
|
|
78
|
+
const result = await this.campaignConfiguration.initialize(this.externalEventSource, useCache);
|
|
80
79
|
result.throw();
|
|
81
|
-
const variationConfiguration = new _variationConfiguration.VariationConfiguration(campaignConfiguration.experiments, variationDataStorage);
|
|
80
|
+
const variationConfiguration = new _variationConfiguration.VariationConfiguration(this.campaignConfiguration.experiments, this.variationDataStorage);
|
|
82
81
|
this.variationConfiguration = variationConfiguration;
|
|
83
|
-
this.campaignConfiguration = campaignConfiguration;
|
|
84
82
|
return result.ok;
|
|
85
83
|
}
|
|
86
84
|
addData(visitorCode, ...data) {
|
|
@@ -90,6 +88,17 @@ class KameleoonClient {
|
|
|
90
88
|
}
|
|
91
89
|
this.campaignConfiguration.addTargetingData(visitorCode, ...data).throw();
|
|
92
90
|
}
|
|
91
|
+
async getRemoteVisitorData(visitorCode, shouldAddData = true) {
|
|
92
|
+
const result = await this.requester.getVisitorData(visitorCode);
|
|
93
|
+
const data = result.throw();
|
|
94
|
+
const visitorData = _utilities.Utilities.parseVisitorData(data);
|
|
95
|
+
if (shouldAddData) {
|
|
96
|
+
for (const item of visitorData) {
|
|
97
|
+
this.addData(visitorCode, item);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return visitorData;
|
|
101
|
+
}
|
|
93
102
|
triggerExperiment(visitorCode, experimentId) {
|
|
94
103
|
_utilities.Utilities.validateVisitorCode(visitorCode).throw();
|
|
95
104
|
if (!this.campaignConfiguration || !this.variationConfiguration) {
|