@kameleoon/javascript-sdk-core 2.0.0 → 2.1.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/dist/cacheManager/cacheManager.d.ts +38 -0
- package/dist/cacheManager/cacheManager.js +74 -0
- package/dist/cacheManager/cacheManager.js.map +1 -0
- package/dist/cacheManager/index.d.ts +2 -0
- package/dist/cacheManager/index.js +20 -0
- package/dist/cacheManager/index.js.map +1 -0
- package/dist/cacheManager/types.d.ts +14 -0
- package/dist/cacheManager/types.js +6 -0
- package/dist/cacheManager/types.js.map +1 -0
- package/dist/campaignConfiguration/campaignConfiguration.d.ts +1 -1
- package/dist/campaignConfiguration/campaignConfiguration.js +15 -10
- package/dist/campaignConfiguration/campaignConfiguration.js.map +1 -1
- package/dist/campaignConfiguration/constants.d.ts +3 -3
- package/dist/campaignConfiguration/constants.js +3 -3
- package/dist/campaignConfiguration/constants.js.map +1 -1
- package/dist/campaignConfiguration/index.d.ts +1 -0
- package/dist/campaignConfiguration/index.js +7 -0
- package/dist/campaignConfiguration/index.js.map +1 -1
- package/dist/campaignConfiguration/types.d.ts +4 -1
- package/dist/campaignConfiguration/types.js.map +1 -1
- package/dist/constants.d.ts +12 -1
- package/dist/constants.js +17 -2
- package/dist/constants.js.map +1 -1
- package/dist/hasher/hasher.d.ts +1 -1
- package/dist/hasher/hasher.js +7 -7
- package/dist/hasher/hasher.js.map +1 -1
- package/dist/hasher/types.d.ts +1 -1
- package/dist/hasher/types.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +16 -3
- package/dist/kameleoonClient.js +50 -3
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonError/constants.d.ts +1 -1
- package/dist/kameleoonError/constants.js +1 -1
- package/dist/kameleoonError/constants.js.map +1 -1
- package/dist/kameleoonError/kameleoonError.d.ts +1 -1
- package/dist/kameleoonError/kameleoonError.js +1 -1
- package/dist/kameleoonError/kameleoonError.js.map +1 -1
- package/dist/kameleoonError/types.d.ts +1 -1
- package/dist/kameleoonError/types.js +1 -1
- package/dist/kameleoonError/types.js.map +1 -1
- package/dist/requester/requester.js +3 -13
- package/dist/requester/requester.js.map +1 -1
- package/dist/types.d.ts +19 -2
- package/dist/types.js +9 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/types.d.ts +8 -0
- package/dist/utilities/types.js.map +1 -1
- package/dist/utilities/utilities.d.ts +5 -2
- package/dist/utilities/utilities.js +54 -0
- package/dist/utilities/utilities.js.map +1 -1
- package/dist/variationConfiguration/types.d.ts +1 -1
- package/dist/variationConfiguration/types.js.map +1 -1
- package/dist/variationConfiguration/variationConfiguration.d.ts +0 -1
- package/dist/variationConfiguration/variationConfiguration.js +70 -79
- package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
- package/package.json +1 -1
- package/dist/hasher/constants.d.ts +0 -1
- package/dist/hasher/constants.js +0 -9
- package/dist/hasher/constants.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AddParametersType } from './types';
|
|
2
|
+
interface ICacheManager<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Add item to cache
|
|
5
|
+
* @param {AddParametersType<T>} parameters - parameters for adding new item cache
|
|
6
|
+
* @returns {void}
|
|
7
|
+
*/
|
|
8
|
+
add({ key, data, lifetime }: AddParametersType<T>): void;
|
|
9
|
+
/**
|
|
10
|
+
* Get item that is not expired from cache
|
|
11
|
+
* @param {string} key - key of item
|
|
12
|
+
* @returns {T} an item that is not expired
|
|
13
|
+
*/
|
|
14
|
+
getAliveItem(key: string): T | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @class
|
|
18
|
+
* CacheManager - a class for managing cache
|
|
19
|
+
*/
|
|
20
|
+
export declare class CacheManager<T> implements ICacheManager<T> {
|
|
21
|
+
private cacheMap;
|
|
22
|
+
private intervalId;
|
|
23
|
+
private cleanupTimeout;
|
|
24
|
+
/**
|
|
25
|
+
* @param {number} cleanupTimeout - timeout for cleaning cache in seconds
|
|
26
|
+
* generic type `T` is a type of data that will be stored in cache
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const cacheManager = new CacheManager<number>(60);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
constructor(cleanupTimeout: number);
|
|
33
|
+
add({ key, data, lifetime }: AddParametersType<T>): void;
|
|
34
|
+
getAliveItem(key: string): T | null;
|
|
35
|
+
private activate;
|
|
36
|
+
private cleanupInterval;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CacheManager = void 0;
|
|
7
|
+
var _types = require("../types");
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
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
|
+
/**
|
|
12
|
+
* @class
|
|
13
|
+
* CacheManager - a class for managing cache
|
|
14
|
+
*/
|
|
15
|
+
class CacheManager {
|
|
16
|
+
/**
|
|
17
|
+
* @param {number} cleanupTimeout - timeout for cleaning cache in seconds
|
|
18
|
+
* generic type `T` is a type of data that will be stored in cache
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const cacheManager = new CacheManager<number>(60);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
constructor(cleanupTimeout) {
|
|
25
|
+
_defineProperty(this, "cacheMap", new Map());
|
|
26
|
+
_defineProperty(this, "intervalId", null);
|
|
27
|
+
_defineProperty(this, "cleanupTimeout", void 0);
|
|
28
|
+
this.cleanupTimeout = cleanupTimeout * _types.Milliseconds.Second;
|
|
29
|
+
}
|
|
30
|
+
add({
|
|
31
|
+
key,
|
|
32
|
+
data,
|
|
33
|
+
lifetime
|
|
34
|
+
}) {
|
|
35
|
+
if (this.intervalId === null) {
|
|
36
|
+
this.activate();
|
|
37
|
+
}
|
|
38
|
+
const expirationTime = lifetime * _types.Milliseconds.Second;
|
|
39
|
+
const cacheItem = {
|
|
40
|
+
data,
|
|
41
|
+
expirationTime: Date.now() + expirationTime
|
|
42
|
+
};
|
|
43
|
+
this.cacheMap.set(key, cacheItem);
|
|
44
|
+
}
|
|
45
|
+
getAliveItem(key) {
|
|
46
|
+
const cacheItem = this.cacheMap.get(key);
|
|
47
|
+
if (cacheItem && cacheItem.expirationTime >= Date.now()) {
|
|
48
|
+
return cacheItem.data;
|
|
49
|
+
}
|
|
50
|
+
cacheItem && this.cacheMap.delete(key);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
activate() {
|
|
54
|
+
this.intervalId = setInterval(() => {
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
for (const [key, item] of this.cacheMap) {
|
|
57
|
+
if (item.expirationTime < now) {
|
|
58
|
+
this.cacheMap.delete(key);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!this.cacheMap.size) {
|
|
62
|
+
this.cleanupInterval();
|
|
63
|
+
}
|
|
64
|
+
}, this.cleanupTimeout);
|
|
65
|
+
}
|
|
66
|
+
cleanupInterval() {
|
|
67
|
+
if (this.intervalId) {
|
|
68
|
+
clearInterval(this.intervalId);
|
|
69
|
+
this.intervalId = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.CacheManager = CacheManager;
|
|
74
|
+
//# sourceMappingURL=cacheManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cacheManager.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","CacheManager","constructor","cleanupTimeout","Map","Milliseconds","Second","add","data","lifetime","intervalId","activate","expirationTime","cacheItem","Date","now","cacheMap","set","getAliveItem","get","delete","setInterval","item","size","cleanupInterval","clearInterval","exports"],"sources":["../../src/cacheManager/cacheManager.ts"],"sourcesContent":["import { AddParametersType, CacheItemType } from './types';\nimport { Milliseconds } from '../types';\n\ninterface ICacheManager<T> {\n /**\n * Add item to cache\n * @param {AddParametersType<T>} parameters - parameters for adding new item cache\n * @returns {void}\n */\n add({ key, data, lifetime }: AddParametersType<T>): void;\n /**\n * Get item that is not expired from cache\n * @param {string} key - key of item\n * @returns {T} an item that is not expired\n */\n getAliveItem(key: string): T | null;\n}\n\n/**\n * @class\n * CacheManager - a class for managing cache\n */\nexport class CacheManager<T> implements ICacheManager<T> {\n private cacheMap = new Map<string, CacheItemType<T>>();\n private intervalId: NodeJS.Timeout | null = null;\n private cleanupTimeout: number;\n\n /**\n * @param {number} cleanupTimeout - timeout for cleaning cache in seconds\n * generic type `T` is a type of data that will be stored in cache\n * @example\n * ```typescript\n * const cacheManager = new CacheManager<number>(60);\n * ```\n */\n constructor(cleanupTimeout: number) {\n this.cleanupTimeout = cleanupTimeout * Milliseconds.Second;\n }\n\n public add({ key, data, lifetime }: AddParametersType<T>): void {\n if (this.intervalId === null) {\n this.activate();\n }\n\n const expirationTime = lifetime * Milliseconds.Second;\n\n const cacheItem: CacheItemType<T> = {\n data,\n expirationTime: Date.now() + expirationTime,\n };\n\n this.cacheMap.set(key, cacheItem);\n }\n\n public getAliveItem(key: string): T | null {\n const cacheItem = this.cacheMap.get(key);\n\n if (cacheItem && cacheItem.expirationTime >= Date.now()) {\n return cacheItem.data;\n }\n\n cacheItem && this.cacheMap.delete(key);\n\n return null;\n }\n\n private activate(): void {\n this.intervalId = setInterval(() => {\n const now = Date.now();\n\n for (const [key, item] of this.cacheMap) {\n if (item.expirationTime < now) {\n this.cacheMap.delete(key);\n }\n }\n\n if (!this.cacheMap.size) {\n this.cleanupInterval();\n }\n }, this.cleanupTimeout);\n }\n\n private cleanupInterval(): void {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n this.intervalId = null;\n }\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAAwC,SAAAC,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;AAiBxC;AACA;AACA;AACA;AACO,MAAMU,YAAY,CAAgC;EAKvD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,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AC;QAC3B;MACF;MAEA,IAAI,CAAC,IAAI,CAACoC,QAAQ,CAACO,IAAI,EAAE;QACvB,IAAI,CAACC,eAAe,EAAE;MACxB;IACF,CAAC,EAAE,IAAI,CAACrB,cAAc,CAAC;EACzB;EAEQqB,eAAeA,CAAA,EAAS;IAC9B,IAAI,IAAI,CAACd,UAAU,EAAE;MACnBe,aAAa,CAAC,IAAI,CAACf,UAAU,CAAC;MAC9B,IAAI,CAACA,UAAU,GAAG,IAAI;IACxB;EACF;AACF;AAACgB,OAAA,CAAAzB,YAAA,GAAAA,YAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AddParametersType", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _types.AddParametersType;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "CacheManager", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _cacheManager.CacheManager;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _cacheManager = require("./cacheManager");
|
|
19
|
+
var _types = require("./types");
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_cacheManager","require","_types"],"sources":["../../src/cacheManager/index.ts"],"sourcesContent":["export { CacheManager } from './cacheManager';\nexport { AddParametersType } from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} key - key for adding new item cache, key must be unique otherwise the item will be overwritten
|
|
3
|
+
* @param {T} data - data for adding new item cache
|
|
4
|
+
* @param {number} lifetime - lifetime for adding new item cache in seconds
|
|
5
|
+
*/
|
|
6
|
+
export type AddParametersType<T> = {
|
|
7
|
+
key: string;
|
|
8
|
+
data: T;
|
|
9
|
+
lifetime: number;
|
|
10
|
+
};
|
|
11
|
+
export type CacheItemType<T> = {
|
|
12
|
+
data: T;
|
|
13
|
+
expirationTime: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/cacheManager/types.ts"],"sourcesContent":["/**\n * @param {string} key - key for adding new item cache, key must be unique otherwise the item will be overwritten\n * @param {T} data - data for adding new item cache\n * @param {number} lifetime - lifetime for adding new item cache in seconds\n */\nexport type AddParametersType<T> = {\n key: string;\n data: T;\n lifetime: number;\n};\n\nexport type CacheItemType<T> = {\n data: T;\n expirationTime: number;\n};\n"],"mappings":""}
|
|
@@ -28,7 +28,7 @@ export declare class CampaignConfiguration implements ICampaignConfiguration {
|
|
|
28
28
|
private requester;
|
|
29
29
|
private eventSource?;
|
|
30
30
|
private externalClientConfiguration?;
|
|
31
|
-
constructor({ settings, storage, requester, externalClientConfiguration, }: CampaignConfigurationParametersType);
|
|
31
|
+
constructor({ settings, storage, requester, externalClientConfiguration, targetingCleanupInterval, }: CampaignConfigurationParametersType);
|
|
32
32
|
initialize(externalEventSource: IExternalEventSourceConstructor): Promise<Result<void, KameleoonError>>;
|
|
33
33
|
addTargetingData(visitorCode: string, ...data: KameleoonDataType[]): Result<void, KameleoonError>;
|
|
34
34
|
getUnsentData(visitorCode: string): KameleoonDataType[];
|
|
@@ -7,6 +7,7 @@ exports.CampaignConfiguration = void 0;
|
|
|
7
7
|
var _tsRes = require("ts-res");
|
|
8
8
|
var _constants = require("./constants");
|
|
9
9
|
var _eventSource = require("../eventSource");
|
|
10
|
+
var _types = require("../types");
|
|
10
11
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
12
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
13
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -17,7 +18,8 @@ class CampaignConfiguration {
|
|
|
17
18
|
settings,
|
|
18
19
|
storage,
|
|
19
20
|
requester,
|
|
20
|
-
externalClientConfiguration
|
|
21
|
+
externalClientConfiguration,
|
|
22
|
+
targetingCleanupInterval
|
|
21
23
|
}) {
|
|
22
24
|
_defineProperty(this, "configurationUpdateCallback", void 0);
|
|
23
25
|
_defineProperty(this, "updateConfigurationIntervalId", null);
|
|
@@ -37,17 +39,20 @@ class CampaignConfiguration {
|
|
|
37
39
|
this.storage = storage;
|
|
38
40
|
this.readStorageData();
|
|
39
41
|
this.externalClientConfiguration = externalClientConfiguration;
|
|
42
|
+
if (targetingCleanupInterval) {
|
|
43
|
+
const cleanupIntervalMinutes = targetingCleanupInterval < 0 ? 1 : targetingCleanupInterval;
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
// --- Note ---
|
|
46
|
+
// We can not make delayed code execution recoverable, as it might lead
|
|
47
|
+
// to targeting data storage size overflow
|
|
48
|
+
try {
|
|
49
|
+
this.targetingDataIntervalId = setInterval(() => this.cleanupOutdatedTargetingData.call(this, this.targetingData), cleanupIntervalMinutes * _types.Milliseconds.Minute);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (this.targetingDataIntervalId) {
|
|
52
|
+
clearInterval(this.targetingDataIntervalId);
|
|
53
|
+
}
|
|
54
|
+
throw err;
|
|
49
55
|
}
|
|
50
|
-
throw err;
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
async initialize(externalEventSource) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"campaignConfiguration.js","names":["_tsRes","require","_constants","_eventSource","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","DEFAULT_CAMPAIGN_CONFIGURATION","targetingData","configurationData","lastUpdate","Date","readStorageData","targetingDataIntervalId","setInterval","cleanupOutdatedTargetingData","CLEANUP_TARGETING_DATA_INTERVAL","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 {\n CLEANUP_TARGETING_DATA_INTERVAL,\n DEFAULT_CAMPAIGN_CONFIGURATION,\n SESSION_DURATION,\n} 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';\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 }: 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 // --- 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 () => this.cleanupOutdatedTargetingData.call(this, this.targetingData),\n CLEANUP_TARGETING_DATA_INTERVAL,\n );\n } catch (err) {\n if (this.targetingDataIntervalId) {\n clearInterval(this.targetingDataIntervalId);\n }\n\n throw err;\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 last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ACnC,IAAI,CAAC;EACjC;AACF;AAACoC,OAAA,CAAA7E,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","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,OAA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jC,CAAC;IAED,OAAO,IAAI,CAAC3E,OAAO,CAAC4E,KAAK,CAACnC,IAAI,CAAC;EACjC;AACF;AAACoC,OAAA,CAAAhF,qBAAA,GAAAA,qBAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @constant default cleanup interval in
|
|
2
|
+
* @constant default cleanup interval in minutes
|
|
3
3
|
* */
|
|
4
|
-
export declare const CLEANUP_TARGETING_DATA_INTERVAL
|
|
4
|
+
export declare const CLEANUP_TARGETING_DATA_INTERVAL = 30;
|
|
5
5
|
/**
|
|
6
|
-
* @constant default session duration in
|
|
6
|
+
* @constant default session duration in milliseconds
|
|
7
7
|
* */
|
|
8
8
|
export declare const SESSION_DURATION: number;
|
|
9
9
|
export declare const DEFAULT_CAMPAIGN_CONFIGURATION: {
|
|
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.SESSION_DURATION = exports.DEFAULT_CAMPAIGN_CONFIGURATION = exports.CLEANUP_TARGETING_DATA_INTERVAL = void 0;
|
|
7
7
|
var _types = require("../types");
|
|
8
8
|
/**
|
|
9
|
-
* @constant default cleanup interval in
|
|
9
|
+
* @constant default cleanup interval in minutes
|
|
10
10
|
* */
|
|
11
|
-
const CLEANUP_TARGETING_DATA_INTERVAL = 30
|
|
11
|
+
const CLEANUP_TARGETING_DATA_INTERVAL = 30;
|
|
12
12
|
/**
|
|
13
|
-
* @constant default session duration in
|
|
13
|
+
* @constant default session duration in milliseconds
|
|
14
14
|
* */
|
|
15
15
|
exports.CLEANUP_TARGETING_DATA_INTERVAL = CLEANUP_TARGETING_DATA_INTERVAL;
|
|
16
16
|
const SESSION_DURATION = 30 * _types.Milliseconds.Minute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["_types","require","CLEANUP_TARGETING_DATA_INTERVAL","
|
|
1
|
+
{"version":3,"file":"constants.js","names":["_types","require","CLEANUP_TARGETING_DATA_INTERVAL","exports","SESSION_DURATION","Milliseconds","Minute","DEFAULT_CAMPAIGN_CONFIGURATION","targetingData","configurationData","experiments","featureFlags","configuration","realTimeUpdate"],"sources":["../../src/campaignConfiguration/constants.ts"],"sourcesContent":["import { Milliseconds } from '../types';\n\n/**\n * @constant default cleanup interval in minutes\n * */\nexport const CLEANUP_TARGETING_DATA_INTERVAL = 30;\n/**\n * @constant default session duration in milliseconds\n * */\nexport const SESSION_DURATION = 30 * Milliseconds.Minute;\n\nexport const DEFAULT_CAMPAIGN_CONFIGURATION = {\n targetingData: {},\n configurationData: {\n experiments: [],\n featureFlags: [],\n configuration: {\n realTimeUpdate: false,\n },\n },\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACO,MAAMC,+BAA+B,GAAG,EAAE;AACjD;AACA;AACA;AAFAC,OAAA,CAAAD,+BAAA,GAAAA,+BAAA;AAGO,MAAME,gBAAgB,GAAG,EAAE,GAAGC,mBAAY,CAACC,MAAM;AAACH,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAElD,MAAMG,8BAA8B,GAAG;EAC5CC,aAAa,EAAE,CAAC,CAAC;EACjBC,iBAAiB,EAAE;IACjBC,WAAW,EAAE,EAAE;IACfC,YAAY,EAAE,EAAE;IAChBC,aAAa,EAAE;MACbC,cAAc,EAAE;IAClB;EACF;AACF,CAAC;AAACV,OAAA,CAAAI,8BAAA,GAAAA,8BAAA"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { ConfigurationDataType, CampaignConfigurationType, VariationByExpositionType, FeatureVariableType, ExperimentItemType, RespoolTimeType, FeatureFlagType, RuleItemType, JSONValue, RuleType, JSONType, } from './types';
|
|
2
2
|
export { CampaignConfiguration } from './campaignConfiguration';
|
|
3
|
+
export { CLEANUP_TARGETING_DATA_INTERVAL } from './constants';
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "CLEANUP_TARGETING_DATA_INTERVAL", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _constants.CLEANUP_TARGETING_DATA_INTERVAL;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "CampaignConfiguration", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -77,4 +83,5 @@ Object.defineProperty(exports, "VariationByExpositionType", {
|
|
|
77
83
|
});
|
|
78
84
|
var _types = require("./types");
|
|
79
85
|
var _campaignConfiguration = require("./campaignConfiguration");
|
|
86
|
+
var _constants = require("./constants");
|
|
80
87
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_types","require","_campaignConfiguration"],"sources":["../../src/campaignConfiguration/index.ts"],"sourcesContent":["export {\n ConfigurationDataType,\n CampaignConfigurationType,\n VariationByExpositionType,\n FeatureVariableType,\n ExperimentItemType,\n RespoolTimeType,\n FeatureFlagType,\n RuleItemType,\n JSONValue,\n RuleType,\n JSONType,\n} from './types';\nexport { CampaignConfiguration } from './campaignConfiguration';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_types","require","_campaignConfiguration","_constants"],"sources":["../../src/campaignConfiguration/index.ts"],"sourcesContent":["export {\n ConfigurationDataType,\n CampaignConfigurationType,\n VariationByExpositionType,\n FeatureVariableType,\n ExperimentItemType,\n RespoolTimeType,\n FeatureFlagType,\n RuleItemType,\n JSONValue,\n RuleType,\n JSONType,\n} from './types';\nexport { CampaignConfiguration } from './campaignConfiguration';\nexport { CLEANUP_TARGETING_DATA_INTERVAL } from './constants';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAaA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA"}
|
|
@@ -56,7 +56,7 @@ export type ExperimentItemType = {
|
|
|
56
56
|
};
|
|
57
57
|
export type ExperimentVariationType = {
|
|
58
58
|
id: string;
|
|
59
|
-
customJson:
|
|
59
|
+
customJson: string;
|
|
60
60
|
};
|
|
61
61
|
export type DeviationType = {
|
|
62
62
|
variationId: string;
|
|
@@ -93,6 +93,8 @@ export type FeatureVariableType = {
|
|
|
93
93
|
};
|
|
94
94
|
export type RuleItemType = {
|
|
95
95
|
type: RuleType;
|
|
96
|
+
id: number;
|
|
97
|
+
respoolTime: number | null;
|
|
96
98
|
order: number;
|
|
97
99
|
exposition: number;
|
|
98
100
|
experimentId: number;
|
|
@@ -124,4 +126,5 @@ export type CampaignConfigurationParametersType = {
|
|
|
124
126
|
storage: IStorage<ClientDataType>;
|
|
125
127
|
requester: Requester;
|
|
126
128
|
externalClientConfiguration?: GetClientConfigurationResultType;
|
|
129
|
+
targetingCleanupInterval?: number;
|
|
127
130
|
};
|
|
@@ -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:
|
|
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":";;;;;;IAqBYA,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"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,10 +2,21 @@ export declare const UNALLOCATED_VARIATION_ID = 0;
|
|
|
2
2
|
export declare const OFF_VARIATION_KEY = "off";
|
|
3
3
|
export declare const KAMELEOON_COOKIE_KEY = "kameleoonVisitorCode";
|
|
4
4
|
export declare const VISITOR_CODE_LENGTH = 16;
|
|
5
|
+
export declare const CACHE_CLEANUP_TIMEOUT = 10;
|
|
6
|
+
export declare const CACHE_ITEM_LIFETIME = 5;
|
|
5
7
|
export declare enum Cookie {
|
|
6
8
|
PairsDelimiter = "; ",
|
|
7
9
|
KeyValueDelimiter = "=",
|
|
8
|
-
MaxAge = "
|
|
10
|
+
MaxAge = "Max-Age",
|
|
9
11
|
Path = "Path",
|
|
10
12
|
Domain = "Domain"
|
|
11
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @readonly
|
|
16
|
+
* @enum {string} an Enum of all the possible Kameleoon SDK types
|
|
17
|
+
* */
|
|
18
|
+
export declare enum SDKType {
|
|
19
|
+
NodeJS = "nodejs",
|
|
20
|
+
JavaScript = "javascript",
|
|
21
|
+
React = "react"
|
|
22
|
+
}
|
package/dist/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.VISITOR_CODE_LENGTH = exports.UNALLOCATED_VARIATION_ID = exports.OFF_VARIATION_KEY = exports.KAMELEOON_COOKIE_KEY = exports.Cookie = void 0;
|
|
6
|
+
exports.VISITOR_CODE_LENGTH = exports.UNALLOCATED_VARIATION_ID = exports.SDKType = exports.OFF_VARIATION_KEY = exports.KAMELEOON_COOKIE_KEY = exports.Cookie = exports.CACHE_ITEM_LIFETIME = exports.CACHE_CLEANUP_TIMEOUT = void 0;
|
|
7
7
|
const UNALLOCATED_VARIATION_ID = 0;
|
|
8
8
|
exports.UNALLOCATED_VARIATION_ID = UNALLOCATED_VARIATION_ID;
|
|
9
9
|
const OFF_VARIATION_KEY = 'off';
|
|
@@ -12,13 +12,28 @@ const KAMELEOON_COOKIE_KEY = 'kameleoonVisitorCode';
|
|
|
12
12
|
exports.KAMELEOON_COOKIE_KEY = KAMELEOON_COOKIE_KEY;
|
|
13
13
|
const VISITOR_CODE_LENGTH = 16;
|
|
14
14
|
exports.VISITOR_CODE_LENGTH = VISITOR_CODE_LENGTH;
|
|
15
|
+
const CACHE_CLEANUP_TIMEOUT = 10;
|
|
16
|
+
exports.CACHE_CLEANUP_TIMEOUT = CACHE_CLEANUP_TIMEOUT;
|
|
17
|
+
const CACHE_ITEM_LIFETIME = 5;
|
|
18
|
+
exports.CACHE_ITEM_LIFETIME = CACHE_ITEM_LIFETIME;
|
|
15
19
|
let Cookie = /*#__PURE__*/function (Cookie) {
|
|
16
20
|
Cookie["PairsDelimiter"] = "; ";
|
|
17
21
|
Cookie["KeyValueDelimiter"] = "=";
|
|
18
|
-
Cookie["MaxAge"] = "
|
|
22
|
+
Cookie["MaxAge"] = "Max-Age";
|
|
19
23
|
Cookie["Path"] = "Path";
|
|
20
24
|
Cookie["Domain"] = "Domain";
|
|
21
25
|
return Cookie;
|
|
22
26
|
}({});
|
|
27
|
+
/**
|
|
28
|
+
* @readonly
|
|
29
|
+
* @enum {string} an Enum of all the possible Kameleoon SDK types
|
|
30
|
+
* */
|
|
23
31
|
exports.Cookie = Cookie;
|
|
32
|
+
let SDKType = /*#__PURE__*/function (SDKType) {
|
|
33
|
+
SDKType["NodeJS"] = "nodejs";
|
|
34
|
+
SDKType["JavaScript"] = "javascript";
|
|
35
|
+
SDKType["React"] = "react";
|
|
36
|
+
return SDKType;
|
|
37
|
+
}({});
|
|
38
|
+
exports.SDKType = SDKType;
|
|
24
39
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["UNALLOCATED_VARIATION_ID","exports","OFF_VARIATION_KEY","KAMELEOON_COOKIE_KEY","VISITOR_CODE_LENGTH","Cookie"],"sources":["../src/constants.ts"],"sourcesContent":["export const UNALLOCATED_VARIATION_ID = 0;\nexport const OFF_VARIATION_KEY = 'off';\nexport const KAMELEOON_COOKIE_KEY = 'kameleoonVisitorCode';\nexport const VISITOR_CODE_LENGTH = 16;\n\nexport enum Cookie {\n PairsDelimiter = '; ',\n KeyValueDelimiter = '=',\n MaxAge = '
|
|
1
|
+
{"version":3,"file":"constants.js","names":["UNALLOCATED_VARIATION_ID","exports","OFF_VARIATION_KEY","KAMELEOON_COOKIE_KEY","VISITOR_CODE_LENGTH","CACHE_CLEANUP_TIMEOUT","CACHE_ITEM_LIFETIME","Cookie","SDKType"],"sources":["../src/constants.ts"],"sourcesContent":["export const UNALLOCATED_VARIATION_ID = 0;\nexport const OFF_VARIATION_KEY = 'off';\nexport const KAMELEOON_COOKIE_KEY = 'kameleoonVisitorCode';\nexport const VISITOR_CODE_LENGTH = 16;\nexport const CACHE_CLEANUP_TIMEOUT = 10;\nexport const CACHE_ITEM_LIFETIME = 5;\n\nexport enum Cookie {\n PairsDelimiter = '; ',\n KeyValueDelimiter = '=',\n MaxAge = 'Max-Age',\n Path = 'Path',\n Domain = 'Domain',\n}\n\n/**\n * @readonly\n * @enum {string} an Enum of all the possible Kameleoon SDK types\n * */\nexport enum SDKType {\n NodeJS = 'nodejs',\n JavaScript = 'javascript',\n React = 'react',\n}\n"],"mappings":";;;;;;AAAO,MAAMA,wBAAwB,GAAG,CAAC;AAACC,OAAA,CAAAD,wBAAA,GAAAA,wBAAA;AACnC,MAAME,iBAAiB,GAAG,KAAK;AAACD,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAChC,MAAMC,oBAAoB,GAAG,sBAAsB;AAACF,OAAA,CAAAE,oBAAA,GAAAA,oBAAA;AACpD,MAAMC,mBAAmB,GAAG,EAAE;AAACH,OAAA,CAAAG,mBAAA,GAAAA,mBAAA;AAC/B,MAAMC,qBAAqB,GAAG,EAAE;AAACJ,OAAA,CAAAI,qBAAA,GAAAA,qBAAA;AACjC,MAAMC,mBAAmB,GAAG,CAAC;AAACL,OAAA,CAAAK,mBAAA,GAAAA,mBAAA;AAAA,IAEzBC,MAAM,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA;AAQlB;AACA;AACA;AACA;AAHAN,OAAA,CAAAM,MAAA,GAAAA,MAAA;AAAA,IAIYC,OAAO,0BAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAA,OAAPA,OAAO;AAAA;AAAAP,OAAA,CAAAO,OAAA,GAAAA,OAAA"}
|
package/dist/hasher/hasher.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ObtainExperimentHashDoubleParamsType, ObtainFeatureFlagHashDoubleParamsType } from './types';
|
|
2
2
|
export declare class Hasher {
|
|
3
3
|
static obtainExperimentHashDouble({ visitorCode, campaignId, respoolTime, }: ObtainExperimentHashDoubleParamsType): number;
|
|
4
|
-
static obtainFeatureFlagHashDouble({ visitorCode, campaignId,
|
|
4
|
+
static obtainFeatureFlagHashDouble({ visitorCode, campaignId, respoolTime, }: ObtainFeatureFlagHashDoubleParamsType): number;
|
|
5
5
|
static calculateHash(seed: string): number;
|
|
6
6
|
}
|
package/dist/hasher/hasher.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Hasher = void 0;
|
|
7
7
|
var _cryptoJs = require("crypto-js");
|
|
8
|
-
var _constants = require("./constants");
|
|
9
8
|
class Hasher {
|
|
10
9
|
static obtainExperimentHashDouble({
|
|
11
10
|
visitorCode,
|
|
@@ -23,18 +22,19 @@ class Hasher {
|
|
|
23
22
|
static obtainFeatureFlagHashDouble({
|
|
24
23
|
visitorCode,
|
|
25
24
|
campaignId,
|
|
26
|
-
|
|
27
|
-
// For some cases of feature flag rules we need to obtain `hashDouble` twice
|
|
28
|
-
// in a row, but the second `hashDouble` should be different (yet still predictable)
|
|
29
|
-
reShuffle = false
|
|
25
|
+
respoolTime
|
|
30
26
|
}) {
|
|
31
|
-
|
|
27
|
+
let suffix = '';
|
|
28
|
+
if (respoolTime) {
|
|
29
|
+
suffix += String(respoolTime);
|
|
30
|
+
}
|
|
31
|
+
return this.calculateHash(visitorCode + campaignId + suffix);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// --- Note ---
|
|
35
35
|
// `hashDouble` is a seeded pseudo-random number between 0 and 1
|
|
36
36
|
// used for deciding what variation to assign
|
|
37
|
-
// `calculateHash`
|
|
37
|
+
// `calculateHash` algorithm is consistent between every SDK
|
|
38
38
|
// and will always provide same pseudo-random value for the same input parameters
|
|
39
39
|
static calculateHash(seed) {
|
|
40
40
|
const hashDigest = (0, _cryptoJs.SHA256)(seed).toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasher.js","names":["_cryptoJs","require","
|
|
1
|
+
{"version":3,"file":"hasher.js","names":["_cryptoJs","require","Hasher","obtainExperimentHashDouble","visitorCode","campaignId","respoolTime","respoolTimeString","length","forEach","respoolObject","String","value","calculateHash","obtainFeatureFlagHashDouble","suffix","seed","hashDigest","SHA256","toString","parseInt","Math","pow","exports"],"sources":["../../src/hasher/hasher.ts"],"sourcesContent":["import { SHA256 } from 'crypto-js';\nimport {\n ObtainExperimentHashDoubleParamsType,\n ObtainFeatureFlagHashDoubleParamsType,\n} from './types';\n\nexport class Hasher {\n static obtainExperimentHashDouble({\n visitorCode,\n campaignId,\n respoolTime,\n }: ObtainExperimentHashDoubleParamsType): number {\n let respoolTimeString = '';\n\n if (respoolTime.length) {\n respoolTime.forEach((respoolObject) => {\n respoolTimeString += String(respoolObject.value);\n });\n }\n\n return this.calculateHash(visitorCode + campaignId + respoolTimeString);\n }\n\n static obtainFeatureFlagHashDouble({\n visitorCode,\n campaignId,\n respoolTime,\n }: ObtainFeatureFlagHashDoubleParamsType): number {\n let suffix = '';\n\n if (respoolTime) {\n suffix += String(respoolTime);\n }\n\n return this.calculateHash(visitorCode + campaignId + suffix);\n }\n\n // --- Note ---\n // `hashDouble` is a seeded pseudo-random number between 0 and 1\n // used for deciding what variation to assign\n // `calculateHash` algorithm is consistent between every SDK\n // and will always provide same pseudo-random value for the same input parameters\n static calculateHash(seed: string): number {\n const hashDigest = SHA256(seed).toString();\n\n return parseInt(hashDigest, 16) / Math.pow(2, 256);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAMO,MAAMC,MAAM,CAAC;EAClB,OAAOC,0BAA0BA,CAAC;IAChCC,WAAW;IACXC,UAAU;IACVC;EACoC,CAAC,EAAU;IAC/C,IAAIC,iBAAiB,GAAG,EAAE;IAE1B,IAAID,WAAW,CAACE,MAAM,EAAE;MACtBF,WAAW,CAACG,OAAO,CAAEC,aAAa,IAAK;QACrCH,iBAAiB,IAAII,MAAM,CAACD,aAAa,CAACE,KAAK,CAAC;MAClD,CAAC,CAAC;IACJ;IAEA,OAAO,IAAI,CAACC,aAAa,CAACT,WAAW,GAAGC,UAAU,GAAGE,iBAAiB,CAAC;EACzE;EAEA,OAAOO,2BAA2BA,CAAC;IACjCV,WAAW;IACXC,UAAU;IACVC;EACqC,CAAC,EAAU;IAChD,IAAIS,MAAM,GAAG,EAAE;IAEf,IAAIT,WAAW,EAAE;MACfS,MAAM,IAAIJ,MAAM,CAACL,WAAW,CAAC;IAC/B;IAEA,OAAO,IAAI,CAACO,aAAa,CAACT,WAAW,GAAGC,UAAU,GAAGU,MAAM,CAAC;EAC9D;;EAEA;EACA;EACA;EACA;EACA;EACA,OAAOF,aAAaA,CAACG,IAAY,EAAU;IACzC,MAAMC,UAAU,GAAG,IAAAC,gBAAM,EAACF,IAAI,CAAC,CAACG,QAAQ,EAAE;IAE1C,OAAOC,QAAQ,CAACH,UAAU,EAAE,EAAE,CAAC,GAAGI,IAAI,CAACC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;EACpD;AACF;AAACC,OAAA,CAAArB,MAAA,GAAAA,MAAA"}
|
package/dist/hasher/types.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ export type ObtainExperimentHashDoubleParamsType = ObtainHashDoubleParamsType &
|
|
|
7
7
|
respoolTime: RespoolTimeType[];
|
|
8
8
|
};
|
|
9
9
|
export type ObtainFeatureFlagHashDoubleParamsType = ObtainHashDoubleParamsType & {
|
|
10
|
-
|
|
10
|
+
respoolTime: number | null;
|
|
11
11
|
};
|
|
12
12
|
export {};
|
package/dist/hasher/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/hasher/types.ts"],"sourcesContent":["import { RespoolTimeType } from '../campaignConfiguration/types';\n\ntype ObtainHashDoubleParamsType = {\n visitorCode: string;\n campaignId: string;\n};\n\nexport type ObtainExperimentHashDoubleParamsType =\n ObtainHashDoubleParamsType & {\n respoolTime: RespoolTimeType[];\n };\n\nexport type ObtainFeatureFlagHashDoubleParamsType =\n ObtainHashDoubleParamsType & {\n
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/hasher/types.ts"],"sourcesContent":["import { RespoolTimeType } from '../campaignConfiguration/types';\n\ntype ObtainHashDoubleParamsType = {\n visitorCode: string;\n campaignId: string;\n};\n\nexport type ObtainExperimentHashDoubleParamsType =\n ObtainHashDoubleParamsType & {\n respoolTime: RespoolTimeType[];\n };\n\nexport type ObtainFeatureFlagHashDoubleParamsType =\n ObtainHashDoubleParamsType & {\n respoolTime: number | null;\n };\n"],"mappings":""}
|