@kameleoon/javascript-sdk-core 2.4.6 → 2.5.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.js +3 -65
- package/dist/cacheManager/cacheManager.js.map +1 -1
- package/dist/cacheManager/index.js +1 -19
- package/dist/cacheManager/index.js.map +1 -1
- package/dist/cacheManager/types.js +1 -5
- package/dist/campaignConfiguration/campaignConfiguration.d.ts +10 -7
- package/dist/campaignConfiguration/campaignConfiguration.js +9 -283
- package/dist/campaignConfiguration/campaignConfiguration.js.map +1 -1
- package/dist/campaignConfiguration/constants.d.ts +2 -10
- package/dist/campaignConfiguration/constants.js +2 -21
- package/dist/campaignConfiguration/constants.js.map +1 -1
- package/dist/campaignConfiguration/index.js +1 -86
- package/dist/campaignConfiguration/index.js.map +1 -1
- package/dist/campaignConfiguration/types.d.ts +8 -7
- package/dist/campaignConfiguration/types.js +1 -54
- package/dist/campaignConfiguration/types.js.map +1 -1
- package/dist/clientSettings/clientSettings.d.ts +1 -1
- package/dist/clientSettings/clientSettings.js +1 -35
- package/dist/clientSettings/clientSettings.js.map +1 -1
- package/dist/clientSettings/index.js +1 -19
- package/dist/clientSettings/index.js.map +1 -1
- package/dist/clientSettings/types.d.ts +1 -1
- package/dist/clientSettings/types.js +1 -5
- package/dist/clientSettings/types.js.map +1 -1
- package/dist/constants.d.ts +13 -4
- package/dist/constants.js +2 -36
- package/dist/constants.js.map +1 -1
- package/dist/eventSource/constants.js +1 -8
- package/dist/eventSource/constants.js.map +1 -1
- package/dist/eventSource/externalEventSource.js +1 -33
- package/dist/eventSource/externalEventSource.js.map +1 -1
- package/dist/eventSource/index.js +1 -50
- package/dist/eventSource/index.js.map +1 -1
- package/dist/eventSource/types.js +1 -5
- package/dist/hasher/hasher.js +6 -44
- package/dist/hasher/hasher.js.map +1 -1
- package/dist/hasher/index.js +1 -12
- package/dist/hasher/index.js.map +1 -1
- package/dist/hasher/types.d.ts +1 -1
- package/dist/hasher/types.js +1 -5
- package/dist/hasher/types.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -310
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +16 -4
- package/dist/kameleoonClient.js +10 -384
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonData/browser.d.ts +8 -3
- package/dist/kameleoonData/browser.js +9 -40
- package/dist/kameleoonData/browser.js.map +1 -1
- package/dist/kameleoonData/conversion.d.ts +2 -2
- package/dist/kameleoonData/conversion.js +5 -50
- package/dist/kameleoonData/conversion.js.map +1 -1
- package/dist/kameleoonData/customData.d.ts +2 -2
- package/dist/kameleoonData/customData.js +5 -55
- package/dist/kameleoonData/customData.js.map +1 -1
- package/dist/kameleoonData/device.d.ts +2 -2
- package/dist/kameleoonData/device.js +5 -40
- package/dist/kameleoonData/device.js.map +1 -1
- package/dist/kameleoonData/index.d.ts +1 -1
- package/dist/kameleoonData/index.js +1 -102
- package/dist/kameleoonData/index.js.map +1 -1
- package/dist/kameleoonData/pageView.d.ts +2 -2
- package/dist/kameleoonData/pageView.js +5 -56
- package/dist/kameleoonData/pageView.js.map +1 -1
- package/dist/kameleoonData/types.d.ts +44 -27
- package/dist/kameleoonData/types.js +6 -42
- package/dist/kameleoonData/types.js.map +1 -1
- package/dist/kameleoonData/userAgent.d.ts +2 -2
- package/dist/kameleoonData/userAgent.js +4 -37
- package/dist/kameleoonData/userAgent.js.map +1 -1
- package/dist/kameleoonError/constants.d.ts +4 -2
- package/dist/kameleoonError/constants.js +1 -31
- package/dist/kameleoonError/constants.js.map +1 -1
- package/dist/kameleoonError/helpers.js +1 -9
- package/dist/kameleoonError/helpers.js.map +1 -1
- package/dist/kameleoonError/index.js +1 -26
- package/dist/kameleoonError/index.js.map +1 -1
- package/dist/kameleoonError/kameleoonError.d.ts +3 -3
- package/dist/kameleoonError/kameleoonError.js +2 -75
- package/dist/kameleoonError/kameleoonError.js.map +1 -1
- package/dist/kameleoonError/types.d.ts +2 -0
- package/dist/kameleoonError/types.js +1 -31
- package/dist/kameleoonError/types.js.map +1 -1
- package/dist/kameleoonUtils.js +2 -44
- package/dist/kameleoonUtils.js.map +1 -1
- package/dist/requester/constants.js +1 -73
- package/dist/requester/constants.js.map +1 -1
- package/dist/requester/index.js +1 -80
- package/dist/requester/index.js.map +1 -1
- package/dist/requester/requester.d.ts +4 -5
- package/dist/requester/requester.js +1 -106
- package/dist/requester/requester.js.map +1 -1
- package/dist/requester/types.d.ts +8 -7
- package/dist/requester/types.js +1 -16
- package/dist/requester/types.js.map +1 -1
- package/dist/storage/constants.js +2 -15
- package/dist/storage/constants.js.map +1 -1
- package/dist/storage/externalStorage.d.ts +1 -1
- package/dist/storage/externalStorage.js +1 -40
- package/dist/storage/externalStorage.js.map +1 -1
- package/dist/storage/index.js +1 -56
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/types.d.ts +4 -4
- package/dist/storage/types.js +1 -5
- package/dist/storage/types.js.map +1 -1
- package/dist/targeting/conditions/browserCondition.d.ts +13 -0
- package/dist/targeting/conditions/browserCondition.js +2 -0
- package/dist/targeting/conditions/browserCondition.js.map +1 -0
- package/dist/targeting/conditions/conditionFactory.d.ts +1 -1
- package/dist/targeting/conditions/conditionFactory.js +1 -30
- package/dist/targeting/conditions/conditionFactory.js.map +1 -1
- package/dist/targeting/conditions/conversionCondition.d.ts +10 -0
- package/dist/targeting/conditions/conversionCondition.js +4 -0
- package/dist/targeting/conditions/conversionCondition.js.map +1 -0
- package/dist/targeting/conditions/customDataCondition.d.ts +5 -7
- package/dist/targeting/conditions/customDataCondition.js +7 -114
- package/dist/targeting/conditions/customDataCondition.js.map +1 -1
- package/dist/targeting/conditions/deviceCondition.d.ts +9 -0
- package/dist/targeting/conditions/deviceCondition.js +2 -0
- package/dist/targeting/conditions/deviceCondition.js.map +1 -0
- package/dist/targeting/conditions/exclusiveExperimentCondition.d.ts +3 -5
- package/dist/targeting/conditions/exclusiveExperimentCondition.js +1 -32
- package/dist/targeting/conditions/exclusiveExperimentCondition.js.map +1 -1
- package/dist/targeting/conditions/index.d.ts +7 -0
- package/dist/targeting/conditions/index.js +1 -46
- package/dist/targeting/conditions/index.js.map +1 -1
- package/dist/targeting/conditions/pageTitleCondition.d.ts +11 -0
- package/dist/targeting/conditions/pageTitleCondition.js +2 -0
- package/dist/targeting/conditions/pageTitleCondition.js.map +1 -0
- package/dist/targeting/conditions/pageUrlCondition.d.ts +11 -0
- package/dist/targeting/conditions/pageUrlCondition.js +2 -0
- package/dist/targeting/conditions/pageUrlCondition.js.map +1 -0
- package/dist/targeting/conditions/sdkLanguageCondition.d.ts +15 -0
- package/dist/targeting/conditions/sdkLanguageCondition.js +2 -0
- package/dist/targeting/conditions/sdkLanguageCondition.js.map +1 -0
- package/dist/targeting/conditions/targetExperimentCondition.d.ts +3 -4
- package/dist/targeting/conditions/targetExperimentCondition.js +1 -63
- package/dist/targeting/conditions/targetExperimentCondition.js.map +1 -1
- package/dist/targeting/conditions/types.d.ts +25 -6
- package/dist/targeting/conditions/types.js +1 -5
- package/dist/targeting/conditions/types.js.map +1 -1
- package/dist/targeting/conditions/visitorCodeCondition.d.ts +11 -0
- package/dist/targeting/conditions/visitorCodeCondition.js +2 -0
- package/dist/targeting/conditions/visitorCodeCondition.js.map +1 -0
- package/dist/targeting/index.d.ts +2 -2
- package/dist/targeting/index.js +1 -80
- package/dist/targeting/index.js.map +1 -1
- package/dist/targeting/targetingNode.d.ts +3 -1
- package/dist/targeting/targetingNode.js +1 -47
- package/dist/targeting/targetingNode.js.map +1 -1
- package/dist/targeting/targetingTree.d.ts +3 -1
- package/dist/targeting/targetingTree.js +34 -135
- package/dist/targeting/targetingTree.js.map +1 -1
- package/dist/targeting/types.d.ts +24 -9
- package/dist/targeting/types.js +1 -100
- package/dist/targeting/types.js.map +1 -1
- package/dist/types.d.ts +9 -4
- package/dist/types.js +12 -41
- package/dist/types.js.map +1 -1
- package/dist/utilities/constants.d.ts +1 -0
- package/dist/utilities/constants.js +1 -8
- package/dist/utilities/constants.js.map +1 -1
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.js +1 -12
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/types.d.ts +14 -7
- package/dist/utilities/types.js +1 -5
- package/dist/utilities/types.js.map +1 -1
- package/dist/utilities/utilities.d.ts +12 -8
- package/dist/utilities/utilities.js +1 -216
- package/dist/utilities/utilities.js.map +1 -1
- package/dist/variationConfiguration/index.js +1 -25
- package/dist/variationConfiguration/index.js.map +1 -1
- package/dist/variationConfiguration/types.d.ts +5 -3
- package/dist/variationConfiguration/types.js +1 -5
- package/dist/variationConfiguration/types.js.map +1 -1
- package/dist/variationConfiguration/variation.d.ts +1 -1
- package/dist/variationConfiguration/variation.js +6 -44
- package/dist/variationConfiguration/variation.js.map +1 -1
- package/dist/variationConfiguration/variationConfiguration.d.ts +4 -4
- package/dist/variationConfiguration/variationConfiguration.js +65 -290
- package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
- package/package.json +1 -1
- package/dist/kameleoonData/constants.d.ts +0 -1
- package/dist/kameleoonData/constants.js +0 -9
- package/dist/kameleoonData/constants.js.map +0 -1
- package/dist/kameleoonData/nonce.d.ts +0 -5
- package/dist/kameleoonData/nonce.js +0 -32
- package/dist/kameleoonData/nonce.js.map +0 -1
|
@@ -1,74 +1,12 @@
|
|
|
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
|
-
/**
|
|
1
|
+
"use strict";var _types=require("../types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheManager=void 0;function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArrayLimit(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f,g,h=[],i=!0,j=!1;try{if(f=(c=c.call(a)).next,0===b){if(Object(c)!==c)return;i=!1}else for(;!(i=(d=f.call(c)).done)&&(h.push(d.value),h.length!==b);i=!0);}catch(a){j=!0,e=a}finally{try{if(!i&&null!=c.return&&(g=c.return(),Object(g)!==g))return}finally{if(j)throw e}}return h}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}/**
|
|
12
2
|
* @class
|
|
13
3
|
* CacheManager - a class for managing cache
|
|
14
|
-
*/
|
|
15
|
-
class CacheManager {
|
|
16
|
-
/**
|
|
4
|
+
*/var CacheManager=/*#__PURE__*/function(){/**
|
|
17
5
|
* @param {number} cleanupTimeout - timeout for cleaning cache in seconds
|
|
18
6
|
* generic type `T` is a type of data that will be stored in cache
|
|
19
7
|
* @example
|
|
20
8
|
* ```typescript
|
|
21
9
|
* const cacheManager = new CacheManager<number>(60);
|
|
22
10
|
* ```
|
|
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;
|
|
11
|
+
*/function a(b){_classCallCheck(this,a),_defineProperty(this,"cacheMap",new Map),_defineProperty(this,"intervalId",null),_defineProperty(this,"cleanupTimeout",void 0),this.cleanupTimeout=b*_types.Milliseconds.Second}return _createClass(a,[{key:"add",value:function add(a){var b=a.key,c=a.data,d=a.lifetime;null===this.intervalId&&this.activate();var e=d*_types.Milliseconds.Second,f={data:c,expirationTime:Date.now()+e};this.cacheMap.set(b,f)}},{key:"getAliveItem",value:function getAliveItem(a){var b=this.cacheMap.get(a);return b&&b.expirationTime>=Date.now()?b.data:(b&&this.cacheMap.delete(a),null)}},{key:"activate",value:function activate(){var a=this;this.intervalId=setInterval(function(){var b,c=Date.now(),d=_createForOfIteratorHelper(a.cacheMap);try{for(d.s();!(b=d.n()).done;){var e=_slicedToArray(b.value,2),f=e[0],g=e[1];g.expirationTime<c&&a.cacheMap.delete(f)}}catch(a){d.e(a)}finally{d.f()}a.cacheMap.size||a.cleanupInterval()},this.cleanupTimeout)}},{key:"cleanupInterval",value:function cleanupInterval(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null)}}]),a}();exports.CacheManager=CacheManager;
|
|
74
12
|
//# sourceMappingURL=cacheManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheManager.js","names":["_types","require","
|
|
1
|
+
{"version":3,"file":"cacheManager.js","names":["_types","require","Object","defineProperty","exports","value","CacheManager","_typeof","a","Symbol","iterator","constructor","prototype","_slicedToArray","b","_arrayWithHoles","_iterableToArrayLimit","_unsupportedIterableToArray","_nonIterableRest","TypeError","c","d","e","f","g","h","i","j","call","next","done","push","length","return","Array","isArray","_createForOfIteratorHelper","s","n","_arrayLikeToArray","toString","slice","name","from","test","_classCallCheck","_defineProperties","enumerable","configurable","writable","_toPropertyKey","key","_createClass","_defineProperty","_toPrimitive","toPrimitive","String","Number","cleanupTimeout","Map","Milliseconds","Second","add","data","lifetime","intervalId","activate","expirationTime","cacheItem","Date","now","cacheMap","set","getAliveItem","get","delete","setInterval","item","size","cleanupInterval","clearInterval"],"sources":["../../src/cacheManager/cacheManager.ts"],"sourcesContent":["import { Milliseconds } from 'src/types';\nimport { AddParametersType, CacheItemType } 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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D,IAAI,CAACC,GAAG,EAAE,CAAAjD,CAAA,CAAAe,0BAAA,CAEI5B,CAAI,CAAC+D,QAAQ,MAAvC,IAAAlD,CAAA,CAAAgB,CAAA,KAAAvB,CAAA,CAAAO,CAAA,CAAAiB,CAAA,IAAAR,IAAA,EAAyC,KAAAR,CAAA,CAAAT,cAAA,CAAAC,CAAA,CAAAT,KAAA,IAA7B8C,CAAG,CAAA7B,CAAA,IAAEuD,CAAI,CAAAvD,CAAA,IACfuD,CAAI,CAACV,cAAc,CAAGG,CAAG,EAC3B9D,CAAI,CAAC+D,QAAQ,CAACI,MAAM,CAACxB,CAAG,CAE5B,CAAC,OAAA3C,CAAA,EAAAa,CAAA,CAAAC,CAAA,CAAAd,CAAA,UAAAa,CAAA,CAAAE,CAAA,GAEIf,CAAI,CAAC+D,QAAQ,CAACO,IAAI,EACrBtE,CAAI,CAACuE,eAAe,EAExB,CAAC,CAAE,IAAI,CAACrB,cAAc,CACxB,CAAC,GAAAP,GAAA,mBAAA9C,KAAA,CAED,SAAA0E,gBAAA,CAAgC,CAC1B,IAAI,CAACd,UAAU,GACjBe,aAAa,CAAC,IAAI,CAACf,UAAU,CAAC,CAC9B,IAAI,CAACA,UAAU,CAAG,IAAI,CAE1B,CAAC,IAAAzD,CAAA,IAAAJ,OAAA,CAAAE,YAAA,CAAAA,YAAA"}
|
|
@@ -1,20 +1,2 @@
|
|
|
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");
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"AddParametersType",{enumerable:!0,get:function get(){return _types.AddParametersType}}),Object.defineProperty(exports,"CacheManager",{enumerable:!0,get:function get(){return _cacheManager.CacheManager}});var _cacheManager=require("./cacheManager"),_types=require("./types");
|
|
20
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/cacheManager/index.ts"],"sourcesContent":["export { CacheManager } from './cacheManager';\nexport { AddParametersType } from './types';\n"],"mappings":""}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { Result } from 'ts-res';
|
|
2
|
-
import { KameleoonError } from '
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { KameleoonError } from 'src/kameleoonError/kameleoonError';
|
|
3
|
+
import { KameleoonDataType } from 'src/kameleoonData';
|
|
4
|
+
import { TargetingDataType } from 'src/targeting';
|
|
5
|
+
import { IExternalEventSourceConstructor } from 'src/eventSource';
|
|
6
|
+
import { CampaignConfigurationParametersType, ConfigurationType, ExperimentItemType, FeatureFlagType, UnsentTargetingDataType } from './types';
|
|
7
7
|
interface ICampaignConfiguration {
|
|
8
8
|
initialize: (eventSource: IExternalEventSourceConstructor, useCache?: boolean) => Promise<Result<void, KameleoonError>>;
|
|
9
9
|
addTargetingData: (visitorCode: string, ...data: KameleoonDataType[]) => Result<void, KameleoonError>;
|
|
10
|
-
getUnsentData: (visitorCode: string) =>
|
|
10
|
+
getUnsentData: (visitorCode: string) => UnsentTargetingDataType[string] | undefined;
|
|
11
11
|
clearUnsentData: (visitorCode: string) => void;
|
|
12
12
|
onConfigurationUpdate: (callback: () => void) => void;
|
|
13
13
|
readonly experiments: ExperimentItemType[];
|
|
14
14
|
readonly storedTargetingData: TargetingDataType;
|
|
15
15
|
readonly featureFlags: FeatureFlagType[];
|
|
16
16
|
readonly configuration: ConfigurationType;
|
|
17
|
+
readonly unsentDataVisitors: string[];
|
|
17
18
|
}
|
|
18
19
|
export declare class CampaignConfiguration implements ICampaignConfiguration {
|
|
19
20
|
private configurationUpdateCallback?;
|
|
@@ -29,12 +30,14 @@ export declare class CampaignConfiguration implements ICampaignConfiguration {
|
|
|
29
30
|
private eventSource?;
|
|
30
31
|
private externalClientConfiguration?;
|
|
31
32
|
private targetingDataLifetime;
|
|
33
|
+
private localCustomDataIndexes;
|
|
32
34
|
constructor({ settings, storage, requester, externalClientConfiguration, targetingCleanupInterval, }: CampaignConfigurationParametersType);
|
|
33
35
|
initialize(externalEventSource: IExternalEventSourceConstructor, useCache?: boolean): Promise<Result<void, KameleoonError>>;
|
|
34
36
|
addTargetingData(visitorCode: string, ...data: KameleoonDataType[]): Result<void, KameleoonError>;
|
|
35
|
-
getUnsentData(visitorCode: string):
|
|
37
|
+
getUnsentData(visitorCode: string): UnsentTargetingDataType[string] | undefined;
|
|
36
38
|
clearUnsentData(visitorCode: string): void;
|
|
37
39
|
onConfigurationUpdate(callback: () => void): void;
|
|
40
|
+
get unsentDataVisitors(): string[];
|
|
38
41
|
get storedTargetingData(): TargetingDataType;
|
|
39
42
|
get experiments(): ExperimentItemType[];
|
|
40
43
|
get featureFlags(): FeatureFlagType[];
|
|
@@ -1,284 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var _types = require("../types");
|
|
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; }
|
|
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; }
|
|
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; }
|
|
14
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
-
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); }
|
|
16
|
-
class CampaignConfiguration {
|
|
17
|
-
constructor({
|
|
18
|
-
settings,
|
|
19
|
-
storage,
|
|
20
|
-
requester,
|
|
21
|
-
externalClientConfiguration,
|
|
22
|
-
targetingCleanupInterval
|
|
23
|
-
}) {
|
|
24
|
-
_defineProperty(this, "configurationUpdateCallback", void 0);
|
|
25
|
-
_defineProperty(this, "updateConfigurationIntervalId", null);
|
|
26
|
-
_defineProperty(this, "targetingDataIntervalId", null);
|
|
27
|
-
_defineProperty(this, "unsentTargetingData", {});
|
|
28
|
-
_defineProperty(this, "targetingData", _constants.DEFAULT_CAMPAIGN_CONFIGURATION.targetingData);
|
|
29
|
-
_defineProperty(this, "configurationData", _constants.DEFAULT_CAMPAIGN_CONFIGURATION.configurationData);
|
|
30
|
-
_defineProperty(this, "settings", void 0);
|
|
31
|
-
_defineProperty(this, "lastUpdate", void 0);
|
|
32
|
-
_defineProperty(this, "storage", void 0);
|
|
33
|
-
_defineProperty(this, "requester", void 0);
|
|
34
|
-
_defineProperty(this, "eventSource", void 0);
|
|
35
|
-
_defineProperty(this, "externalClientConfiguration", void 0);
|
|
36
|
-
_defineProperty(this, "targetingDataLifetime", _constants.CLEANUP_TARGETING_DATA_INTERVAL * _types.Milliseconds.Minute);
|
|
37
|
-
this.requester = requester;
|
|
38
|
-
this.settings = settings;
|
|
39
|
-
this.lastUpdate = new Date();
|
|
40
|
-
this.storage = storage;
|
|
41
|
-
this.readStorageData();
|
|
42
|
-
this.externalClientConfiguration = externalClientConfiguration;
|
|
43
|
-
if (targetingCleanupInterval) {
|
|
44
|
-
this.targetingDataLifetime = targetingCleanupInterval * _types.Milliseconds.Minute;
|
|
45
|
-
const cleanupIntervalMinutes = targetingCleanupInterval < 0 ? 1 : targetingCleanupInterval;
|
|
46
|
-
|
|
47
|
-
// --- Note ---
|
|
48
|
-
// We can not make delayed code execution recoverable, as it might lead
|
|
49
|
-
// to targeting data storage size overflow
|
|
50
|
-
try {
|
|
51
|
-
this.targetingDataIntervalId = setInterval(() => this.cleanupOutdatedTargetingData.call(this, this.targetingData), cleanupIntervalMinutes * _types.Milliseconds.Minute);
|
|
52
|
-
} catch (err) {
|
|
53
|
-
if (this.targetingDataIntervalId) {
|
|
54
|
-
clearInterval(this.targetingDataIntervalId);
|
|
55
|
-
}
|
|
56
|
-
throw err;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async initialize(externalEventSource, useCache) {
|
|
61
|
-
const shouldUpdate = this.checkShouldUpdate();
|
|
62
|
-
|
|
63
|
-
// --- Initial data fetch ---
|
|
64
|
-
if (shouldUpdate) {
|
|
65
|
-
const updateResult = await this.updateClientConfiguration({
|
|
66
|
-
useCache
|
|
67
|
-
});
|
|
68
|
-
if (!updateResult.ok) {
|
|
69
|
-
return updateResult;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// --- Note ---
|
|
74
|
-
// Interval is cleaned up in case real time update
|
|
75
|
-
// was activated while initialized client already exists
|
|
76
|
-
if (this.configurationData.configuration.realTimeUpdate && !this.externalClientConfiguration) {
|
|
77
|
-
if (this.updateConfigurationIntervalId) {
|
|
78
|
-
clearInterval(this.updateConfigurationIntervalId);
|
|
79
|
-
}
|
|
80
|
-
this.eventSource = new _eventSource.ExternalEventSource(this.settings.siteCode, externalEventSource);
|
|
81
|
-
const updateEventCallback = _timeStamp => {
|
|
82
|
-
this.updateClientConfiguration({
|
|
83
|
-
useCache
|
|
84
|
-
});
|
|
85
|
-
if (this.configurationUpdateCallback) {
|
|
86
|
-
this.configurationUpdateCallback();
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
this.eventSource.open(updateEventCallback);
|
|
90
|
-
} else {
|
|
91
|
-
// --- Note ---
|
|
92
|
-
// Event Source is cleaned up in case real time update
|
|
93
|
-
// was disabled while initialized client already exists
|
|
94
|
-
if (this.eventSource) {
|
|
95
|
-
this.eventSource.close();
|
|
96
|
-
}
|
|
97
|
-
if (this.updateConfigurationIntervalId) {
|
|
98
|
-
clearInterval(this.updateConfigurationIntervalId);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// --- Note ---
|
|
102
|
-
// Same as targeting data interval we don't want to make failed configuration
|
|
103
|
-
// retrieval recoverable
|
|
104
|
-
try {
|
|
105
|
-
this.updateConfigurationIntervalId = setInterval(() => this.updateClientConfiguration.bind(this)({
|
|
106
|
-
useCache
|
|
107
|
-
}), this.settings.updateInterval);
|
|
108
|
-
} catch (err) {
|
|
109
|
-
if (this.updateConfigurationIntervalId) {
|
|
110
|
-
clearInterval(this.updateConfigurationIntervalId);
|
|
111
|
-
}
|
|
112
|
-
throw err;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return (0, _tsRes.Ok)();
|
|
116
|
-
}
|
|
117
|
-
addTargetingData(visitorCode, ...data) {
|
|
118
|
-
if (!(visitorCode in this.targetingData)) {
|
|
119
|
-
this.targetingData[visitorCode] = [];
|
|
120
|
-
}
|
|
121
|
-
data.forEach(dataItem => {
|
|
122
|
-
// --- Note ---
|
|
123
|
-
// Previous check excludes the failure possibility
|
|
124
|
-
this.targetingData[visitorCode].push({
|
|
125
|
-
data: dataItem.data,
|
|
126
|
-
lastActivityTime: Date.now()
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// --- Note ---
|
|
131
|
-
// `targetingData` should not refresh `lastUpdate` time
|
|
132
|
-
const result = this.updateStorageData(this.lastUpdate);
|
|
133
|
-
if (result.ok) {
|
|
134
|
-
data.forEach(dataItem => {
|
|
135
|
-
if (!this.unsentTargetingData[visitorCode]) {
|
|
136
|
-
this.unsentTargetingData[visitorCode] = [];
|
|
137
|
-
}
|
|
138
|
-
this.unsentTargetingData[visitorCode].push(dataItem);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return result;
|
|
142
|
-
}
|
|
143
|
-
getUnsentData(visitorCode) {
|
|
144
|
-
const unsentDataItem = this.unsentTargetingData[visitorCode];
|
|
145
|
-
if (!unsentDataItem) {
|
|
146
|
-
return [];
|
|
147
|
-
}
|
|
148
|
-
return unsentDataItem;
|
|
149
|
-
}
|
|
150
|
-
clearUnsentData(visitorCode) {
|
|
151
|
-
this.unsentTargetingData[visitorCode] = [];
|
|
152
|
-
}
|
|
153
|
-
onConfigurationUpdate(callback) {
|
|
154
|
-
this.configurationUpdateCallback = callback;
|
|
155
|
-
}
|
|
156
|
-
get storedTargetingData() {
|
|
157
|
-
return this.targetingData;
|
|
158
|
-
}
|
|
159
|
-
get experiments() {
|
|
160
|
-
return this.configurationData.experiments;
|
|
161
|
-
}
|
|
162
|
-
get featureFlags() {
|
|
163
|
-
return this.configurationData.featureFlags;
|
|
164
|
-
}
|
|
165
|
-
get configuration() {
|
|
166
|
-
return this.configurationData.configuration;
|
|
167
|
-
}
|
|
168
|
-
checkShouldUpdate() {
|
|
169
|
-
const {
|
|
170
|
-
featureFlags,
|
|
171
|
-
experiments,
|
|
172
|
-
configuration
|
|
173
|
-
} = this.configurationData;
|
|
174
|
-
const {
|
|
175
|
-
updateInterval
|
|
176
|
-
} = this.settings;
|
|
177
|
-
if (!featureFlags.length && !experiments.length) {
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
if (configuration.realTimeUpdate) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
const lastUpdateTime = this.lastUpdate.getTime();
|
|
184
|
-
const updateWindowEdge = Date.now() - updateInterval;
|
|
185
|
-
return lastUpdateTime < updateWindowEdge;
|
|
186
|
-
}
|
|
187
|
-
cleanupOutdatedTargetingData(data) {
|
|
188
|
-
const currentTime = Date.now();
|
|
189
|
-
const resultTargetingData = _objectSpread({}, data);
|
|
190
|
-
for (const [key, value] of Object.entries(resultTargetingData)) {
|
|
191
|
-
if (value) {
|
|
192
|
-
const resultValue = value.filter(item => {
|
|
193
|
-
const isDataExpired = item.lastActivityTime + this.targetingDataLifetime < currentTime;
|
|
194
|
-
return !isDataExpired;
|
|
195
|
-
});
|
|
196
|
-
if (resultValue.length) {
|
|
197
|
-
resultTargetingData[key] = resultValue;
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
delete resultTargetingData[key];
|
|
202
|
-
}
|
|
203
|
-
this.targetingData = resultTargetingData;
|
|
204
|
-
// --- Note ---
|
|
205
|
-
// `targetingData` should not refresh `lastUpdate` time
|
|
206
|
-
this.updateStorageData(this.lastUpdate).throw();
|
|
207
|
-
}
|
|
208
|
-
readStorageData() {
|
|
209
|
-
const result = this.storage.read();
|
|
210
|
-
if (result.ok) {
|
|
211
|
-
const {
|
|
212
|
-
kameleoonTargetingData,
|
|
213
|
-
kameleoonConfiguration,
|
|
214
|
-
lastUpdate
|
|
215
|
-
} = result.data;
|
|
216
|
-
this.configurationData = kameleoonConfiguration;
|
|
217
|
-
this.targetingData = kameleoonTargetingData;
|
|
218
|
-
this.lastUpdate = new Date(Date.parse(lastUpdate));
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
async updateClientConfiguration({
|
|
222
|
-
useCache = false,
|
|
223
|
-
timeStamp
|
|
224
|
-
} = {}) {
|
|
225
|
-
// --- Note ---
|
|
226
|
-
// if `externalClientConfiguration` is passed, fetching is disabled and passed config is used instead
|
|
227
|
-
if (this.externalClientConfiguration) {
|
|
228
|
-
// --- Note ---
|
|
229
|
-
// `featureFlags` field is omitted (v1)
|
|
230
|
-
// instead `featureFlagConfigurations` is used (v2)
|
|
231
|
-
const {
|
|
232
|
-
configuration,
|
|
233
|
-
experiments,
|
|
234
|
-
featureFlagConfigurations
|
|
235
|
-
} = this.externalClientConfiguration;
|
|
236
|
-
this.configurationData = {
|
|
237
|
-
configuration,
|
|
238
|
-
experiments,
|
|
239
|
-
featureFlags: featureFlagConfigurations
|
|
240
|
-
};
|
|
241
|
-
} else {
|
|
242
|
-
const clientConfigurationResult = await this.requester.getClientConfiguration(timeStamp);
|
|
243
|
-
if (!clientConfigurationResult.ok) {
|
|
244
|
-
const {
|
|
245
|
-
featureFlags,
|
|
246
|
-
experiments
|
|
247
|
-
} = this.configurationData;
|
|
248
|
-
if (useCache && featureFlags.length && experiments.length) {
|
|
249
|
-
return (0, _tsRes.Ok)(true);
|
|
250
|
-
}
|
|
251
|
-
return clientConfigurationResult;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// --- Note ---
|
|
255
|
-
// `featureFlags` field is omitted (v1)
|
|
256
|
-
// instead `featureFlagConfigurations` is used (v2)
|
|
257
|
-
const {
|
|
258
|
-
configuration,
|
|
259
|
-
experiments,
|
|
260
|
-
featureFlagConfigurations
|
|
261
|
-
} = clientConfigurationResult.data;
|
|
262
|
-
this.configurationData = {
|
|
263
|
-
configuration,
|
|
264
|
-
experiments,
|
|
265
|
-
featureFlags: featureFlagConfigurations
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
const result = this.updateStorageData(new Date());
|
|
269
|
-
if (!result.ok) {
|
|
270
|
-
return result;
|
|
271
|
-
}
|
|
272
|
-
return (0, _tsRes.Ok)(true);
|
|
273
|
-
}
|
|
274
|
-
updateStorageData(lastUpdate) {
|
|
275
|
-
const data = {
|
|
276
|
-
kameleoonTargetingData: this.targetingData,
|
|
277
|
-
kameleoonConfiguration: this.configurationData,
|
|
278
|
-
lastUpdate: lastUpdate.toString()
|
|
279
|
-
};
|
|
280
|
-
return this.storage.write(data);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
exports.CampaignConfiguration = CampaignConfiguration;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CampaignConfiguration=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../kameleoonData"),_eventSource=require("../eventSource"),_types=require("../types"),_constants=require("./constants"),_utilities=require("../utilities"),_excluded=["customData"];function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _iterableToArrayLimit(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f,g,h=[],i=!0,j=!1;try{if(f=(c=c.call(a)).next,0===b){if(Object(c)!==c)return;i=!1}else for(;!(i=(d=f.call(c)).done)&&(h.push(d.value),h.length!==b);i=!0);}catch(a){j=!0,e=a}finally{try{if(!i&&null!=c.return&&(g=c.return(),Object(g)!==g))return}finally{if(j)throw e}}return h}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,c,e){var f=b&&b.prototype instanceof d?b:d,g=Object.create(f.prototype),h=new m(e||[]);return s(g,"_invoke",{value:i(a,c,h)}),g}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&r.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;s(this,"_invoke",{value:function value(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}})}function i(a,b,d){var e="suspendedStart";return function(f,g){if("executing"==e)throw new Error("Generator is already running");if("completed"==e){if("throw"===f)throw g;return o()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=j(h,d);if(i){if(i===x)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"==e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===x)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function j(a,b){var d=b.method,e=a.iterator[d];if(void 0===e)return b.delegate=null,"throw"===d&&a.iterator.return&&(b.method="return",b.arg=void 0,j(a,b),"throw"===b.method)||"return"!==d&&(b.method="throw",b.arg=new TypeError("The iterator does not provide a '"+d+"' method")),x;var f=c(e,a.iterator,b.arg);if("throw"===f.type)return b.method="throw",b.arg=f.arg,b.delegate=null,x;var g=f.arg;return g?g.done?(b[a.resultName]=g.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,x):g:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,x)}function k(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function l(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function m(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(k,this),this.reset(!0)}function n(a){if(a){var b=a[u];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(r.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:o}}function o(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return p};var p={},q=Object.prototype,r=q.hasOwnProperty,s=Object.defineProperty||function(a,b,c){a[b]=c.value},t="function"==typeof Symbol?Symbol:{},u=t.iterator||"@@iterator",v=t.asyncIterator||"@@asyncIterator",w=t.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}p.wrap=b;var x={},y={};a(y,u,function(){return this});var z=Object.getPrototypeOf,A=z&&z(z(n([])));A&&A!==q&&r.call(A,u)&&(y=A);var B=f.prototype=d.prototype=Object.create(y);return e.prototype=f,s(B,"constructor",{value:f,configurable:!0}),s(f,"constructor",{value:e,configurable:!0}),e.displayName=a(f,w,"GeneratorFunction"),p.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},p.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,w,"GeneratorFunction")),b.prototype=Object.create(B),b},p.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,v,function(){return this}),p.AsyncIterator=h,p.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return p.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(B),a(B,w,"Generator"),a(B,u,function(){return this}),a(B,"toString",function(){return"[object Generator]"}),p.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},p.values=n,m.prototype={constructor:m,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(l),!a)for(var b in this)"t"===b.charAt(0)&&r.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=r.call(e,"catchLoc"),h=r.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&r.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,x):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),x},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),l(b),x},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;l(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:n(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),x}},p}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var CampaignConfiguration=/*#__PURE__*/function(){function a(b){var c=b.settings,d=b.storage,e=b.requester,f=b.externalClientConfiguration,g=b.targetingCleanupInterval;if(_classCallCheck(this,a),_defineProperty(this,"configurationUpdateCallback",void 0),_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"targetingDataIntervalId",null),_defineProperty(this,"unsentTargetingData",{}),_defineProperty(this,"targetingData",{}),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"settings",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"targetingDataLifetime",_constants.CLEANUP_TARGETING_DATA_INTERVAL*_types.Milliseconds.Minute),_defineProperty(this,"localCustomDataIndexes",new Set),this.requester=e,this.settings=c,this.lastUpdate=new Date,this.storage=d,this.readStorageData(),this.externalClientConfiguration=f,g){this.targetingDataLifetime=g*_types.Milliseconds.Minute;var h=0>g?1:g;// --- Note ---
|
|
2
|
+
// We can not make delayed code execution recoverable, as it might lead
|
|
3
|
+
// to targeting data storage size overflow
|
|
4
|
+
try{this.targetingDataIntervalId=setInterval(this.cleanupOutdatedTargetingData.bind(this),h*_types.Milliseconds.Minute)}catch(a){throw this.targetingDataIntervalId&&clearInterval(this.targetingDataIntervalId),a}}}return _createClass(a,[{key:"initialize",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function c(a,b){var d,e,f,g=this;return _regeneratorRuntime().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(d=this.checkShouldUpdate(),!d){c.next=7;break}return c.next=4,this.updateClientConfiguration({useCache:b});case 4:if(e=c.sent,e.ok){c.next=7;break}return c.abrupt("return",e);case 7:if(!this.configurationData.configuration.realTimeUpdate||this.externalClientConfiguration){c.next=14;break}this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),this.eventSource=new _eventSource.ExternalEventSource(this.settings.siteCode,a),f=function(){g.updateClientConfiguration({useCache:b}),g.configurationUpdateCallback&&g.configurationUpdateCallback()},this.eventSource.open(f),c.next=24;break;case 14:this.eventSource&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),c.prev=16,this.updateConfigurationIntervalId=setInterval(function(){return g.updateClientConfiguration.bind(g)({useCache:b})},this.settings.updateInterval),c.next=24;break;case 20:throw c.prev=20,c.t0=c["catch"](16),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),c.t0;case 24:return c.abrupt("return",(0,_tsRes.Ok)());case 25:case"end":return c.stop();}},c,this,[[16,20]])}));return a}()},{key:"addTargetingData",value:function addTargetingData(a){var b=this;a in this.targetingData||(this.targetingData[a]={});for(var c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];d.forEach(function(c){// --- Custom data case ---
|
|
5
|
+
if(_utilities.Utilities.isCustomData(c)){var d=_objectSpread(_objectSpread({},c.data),{},{lastActivityTime:Date.now()}),e=(_kameleoonData.KameleoonData.CustomData in b.targetingData[a]);e?b.targetingData[a][d.type][d.index]=d:b.targetingData[a]=_objectSpread(_objectSpread({},b.targetingData[a]),{},_defineProperty({},d.type,_objectSpread(_objectSpread({},b.targetingData[a][d.type]),{},_defineProperty({},d.index,d))))}else{var f=_objectSpread(_objectSpread({},c.data),{},{lastActivityTime:Date.now()}),g=(c.data.type in b.targetingData[a]);g?b.targetingData[a][c.data.type]=f:b.targetingData[a]=_objectSpread(_objectSpread({},b.targetingData[a]),{},_defineProperty({},c.data.type,f))}});// --- Note ---
|
|
6
|
+
// `targetingData` should not refresh `lastUpdate` time
|
|
7
|
+
var f=this.updateStorageData(this.lastUpdate);return f.ok&&d.forEach(function(c){b.unsentTargetingData[a]||(b.unsentTargetingData[a]=new Map);var d;if(_utilities.Utilities.isCustomData(c)){if(b.localCustomDataIndexes.has(c.data.index))return;d=c.data.index}else d=c.data.type;b.unsentTargetingData[a].set(d,c)}),f}},{key:"getUnsentData",value:function getUnsentData(a){return this.unsentTargetingData[a]}},{key:"clearUnsentData",value:function clearUnsentData(a){delete this.unsentTargetingData[a]}},{key:"onConfigurationUpdate",value:function onConfigurationUpdate(a){this.configurationUpdateCallback=a}},{key:"unsentDataVisitors",get:function get(){return Object.keys(this.unsentTargetingData)}},{key:"storedTargetingData",get:function get(){return this.targetingData}},{key:"experiments",get:function get(){return this.configurationData.experiments}},{key:"featureFlags",get:function get(){return this.configurationData.featureFlags}},{key:"configuration",get:function get(){return this.configurationData.configuration}},{key:"checkShouldUpdate",value:function checkShouldUpdate(){var a=this.configurationData,b=a.featureFlags,c=a.experiments,d=a.configuration,e=this.settings.updateInterval;if(!b.length&&!c.length)return!0;if(d.realTimeUpdate)return!0;var f=this.lastUpdate.getTime(),g=Date.now()-e;return f<g}},{key:"cleanupOutdatedTargetingData",value:function cleanupOutdatedTargetingData(){for(var a=Date.now(),b=0,c=Object.entries(this.targetingData);b<c.length;b++){var d=_slicedToArray(c[b],2),e=d[0],f=d[1],g=f.customData,h=_objectWithoutProperties(f,_excluded);if(g)for(var i=0,j=Object.entries(g);i<j.length;i++){var k=_slicedToArray(j[i],2),l=k[0],m=k[1];if(m){var n=m.lastActivityTime+this.targetingDataLifetime<a,o=f[_kameleoonData.KameleoonData.CustomData];n&&o&&delete o[+l],o&&!Object.keys(o).length&&delete f[_kameleoonData.KameleoonData.CustomData]}}for(var p=0,q=Object.entries(h);p<q.length;p++){var r=_slicedToArray(q[p],2),s=r[0],t=r[1],u=t.lastActivityTime+this.targetingDataLifetime<a;u&&delete f[s]}Object.keys(this.targetingData[e]).length||delete this.targetingData[e]}// --- Note ---
|
|
8
|
+
// `targetingData` should not refresh `lastUpdate` time
|
|
9
|
+
this.updateStorageData(this.lastUpdate).throw()}},{key:"readStorageData",value:function readStorageData(){var a=this.storage.read();if(a.ok){var b=a.data,c=b.kameleoonTargetingData,d=b.kameleoonConfiguration,e=b.lastUpdate;this.configurationData=d,this.targetingData=c,this.lastUpdate=new Date(Date.parse(e))}}},{key:"updateClientConfiguration",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function a(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s=arguments;return _regeneratorRuntime().wrap(function t(a){for(;1;)switch(a.prev=a.next){case 0:if(b=0<s.length&&void 0!==s[0]?s[0]:{},c=b.useCache,d=void 0!==c&&c,e=b.timeStamp,!this.externalClientConfiguration){a.next=6;break}f=this.externalClientConfiguration,g=f.configuration,h=f.experiments,i=f.featureFlagConfigurations,this.configurationData={configuration:g,experiments:h,featureFlags:i},a.next=17;break;case 6:return a.next=8,this.requester.getClientConfiguration(e);case 8:if(j=a.sent,j.ok){a.next=14;break}if(k=this.configurationData,l=k.featureFlags,m=k.experiments,!(d&&l.length&&m.length)){a.next=13;break}return a.abrupt("return",(0,_tsRes.Ok)(!0));case 13:return a.abrupt("return",j);case 14:n=j.data,o=n.configuration,p=n.experiments,q=n.featureFlagConfigurations,this.localCustomDataIndexes=new Set(o.customDataLocalOnlyIndexes),this.configurationData={configuration:o,experiments:p,featureFlags:q};case 17:if(r=this.updateStorageData(new Date),r.ok){a.next=20;break}return a.abrupt("return",r);case 20:return a.abrupt("return",(0,_tsRes.Ok)(!0));case 21:case"end":return a.stop();}},a,this)}));return a}()},{key:"updateStorageData",value:function updateStorageData(a){var b={kameleoonTargetingData:this.targetingData,kameleoonConfiguration:this.configurationData,lastUpdate:a.toString()};return this.storage.write(b)}}]),a}();exports.CampaignConfiguration=CampaignConfiguration;
|
|
284
10
|
//# sourceMappingURL=campaignConfiguration.js.map
|