@ninetailed/experience.js 2.2.11-beta.0 → 3.0.0-beta.11

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/index.esm.js CHANGED
@@ -1,7 +1,5 @@
1
- import get$2 from 'lodash/get';
2
1
  import unionBy from 'lodash/unionBy';
3
- import { buildEmptyCache, buildTrackEvent, buildIdentifyEvent, buildPageEvent } from '@ninetailed/experience.js-shared';
4
- import { diary, enable } from 'diary';
2
+ import { NinetailedApiClient, logger, ConsoleLogSink, buildTrackEvent, buildIdentifyEvent, buildPageEvent, OnLogLogSink, OnErrorLogSink } from '@ninetailed/experience.js-shared';
5
3
  import Analytics from 'analytics';
6
4
  import flatten from 'lodash/flatten';
7
5
  import find from 'lodash/find';
@@ -90,32 +88,32 @@ var NATIVE_BIND$2 = functionBindNative;
90
88
  var FunctionPrototype$2 = Function.prototype;
91
89
  var bind$5 = FunctionPrototype$2.bind;
92
90
  var call$e = FunctionPrototype$2.call;
93
- var uncurryThis$n = NATIVE_BIND$2 && bind$5.bind(call$e, call$e);
91
+ var uncurryThis$o = NATIVE_BIND$2 && bind$5.bind(call$e, call$e);
94
92
 
95
93
  var functionUncurryThis = NATIVE_BIND$2 ? function (fn) {
96
- return fn && uncurryThis$n(fn);
94
+ return fn && uncurryThis$o(fn);
97
95
  } : function (fn) {
98
96
  return fn && function () {
99
97
  return call$e.apply(fn, arguments);
100
98
  };
101
99
  };
102
100
 
103
- var uncurryThis$m = functionUncurryThis;
101
+ var uncurryThis$n = functionUncurryThis;
104
102
 
105
- var toString$9 = uncurryThis$m({}.toString);
106
- var stringSlice$6 = uncurryThis$m(''.slice);
103
+ var toString$a = uncurryThis$n({}.toString);
104
+ var stringSlice$6 = uncurryThis$n(''.slice);
107
105
 
108
106
  var classofRaw$1 = function (it) {
109
- return stringSlice$6(toString$9(it), 8, -1);
107
+ return stringSlice$6(toString$a(it), 8, -1);
110
108
  };
111
109
 
112
110
  var global$J = global$K;
113
- var uncurryThis$l = functionUncurryThis;
111
+ var uncurryThis$m = functionUncurryThis;
114
112
  var fails$h = fails$k;
115
113
  var classof$7 = classofRaw$1;
116
114
 
117
115
  var Object$5 = global$J.Object;
118
- var split = uncurryThis$l(''.split);
116
+ var split = uncurryThis$m(''.split);
119
117
 
120
118
  // fallback for non-array-like ES3 and non-enumerable old V8 strings
121
119
  var indexedObject = fails$h(function () {
@@ -132,17 +130,17 @@ var TypeError$h = global$I.TypeError;
132
130
 
133
131
  // `RequireObjectCoercible` abstract operation
134
132
  // https://tc39.es/ecma262/#sec-requireobjectcoercible
135
- var requireObjectCoercible$7 = function (it) {
133
+ var requireObjectCoercible$8 = function (it) {
136
134
  if (it == undefined) throw TypeError$h("Can't call method on " + it);
137
135
  return it;
138
136
  };
139
137
 
140
138
  // toObject with fallback for non-array-like ES3 strings
141
139
  var IndexedObject$2 = indexedObject;
142
- var requireObjectCoercible$6 = requireObjectCoercible$7;
140
+ var requireObjectCoercible$7 = requireObjectCoercible$8;
143
141
 
144
142
  var toIndexedObject$5 = function (it) {
145
- return IndexedObject$2(requireObjectCoercible$6(it));
143
+ return IndexedObject$2(requireObjectCoercible$7(it));
146
144
  };
147
145
 
148
146
  // `IsCallable` abstract operation
@@ -168,9 +166,9 @@ var getBuiltIn$7 = function (namespace, method) {
168
166
  return arguments.length < 2 ? aFunction(global$H[namespace]) : global$H[namespace] && global$H[namespace][method];
169
167
  };
170
168
 
171
- var uncurryThis$k = functionUncurryThis;
169
+ var uncurryThis$l = functionUncurryThis;
172
170
 
173
- var objectIsPrototypeOf = uncurryThis$k({}.isPrototypeOf);
171
+ var objectIsPrototypeOf = uncurryThis$l({}.isPrototypeOf);
174
172
 
175
173
  var getBuiltIn$6 = getBuiltIn$7;
176
174
 
@@ -328,20 +326,20 @@ var store$2 = sharedStore;
328
326
  });
329
327
 
330
328
  var global$z = global$K;
331
- var requireObjectCoercible$5 = requireObjectCoercible$7;
329
+ var requireObjectCoercible$6 = requireObjectCoercible$8;
332
330
 
333
331
  var Object$3 = global$z.Object;
334
332
 
335
333
  // `ToObject` abstract operation
336
334
  // https://tc39.es/ecma262/#sec-toobject
337
335
  var toObject$5 = function (argument) {
338
- return Object$3(requireObjectCoercible$5(argument));
336
+ return Object$3(requireObjectCoercible$6(argument));
339
337
  };
340
338
 
341
- var uncurryThis$j = functionUncurryThis;
339
+ var uncurryThis$k = functionUncurryThis;
342
340
  var toObject$4 = toObject$5;
343
341
 
344
- var hasOwnProperty = uncurryThis$j({}.hasOwnProperty);
342
+ var hasOwnProperty = uncurryThis$k({}.hasOwnProperty);
345
343
 
346
344
  // `HasOwnProperty` abstract operation
347
345
  // https://tc39.es/ecma262/#sec-hasownproperty
@@ -349,14 +347,14 @@ var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) {
349
347
  return hasOwnProperty(toObject$4(it), key);
350
348
  };
351
349
 
352
- var uncurryThis$i = functionUncurryThis;
350
+ var uncurryThis$j = functionUncurryThis;
353
351
 
354
352
  var id = 0;
355
353
  var postfix = Math.random();
356
- var toString$8 = uncurryThis$i(1.0.toString);
354
+ var toString$9 = uncurryThis$j(1.0.toString);
357
355
 
358
356
  var uid$2 = function (key) {
359
- return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$8(++id + postfix, 36);
357
+ return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$9(++id + postfix, 36);
360
358
  };
361
359
 
362
360
  var global$y = global$K;
@@ -552,11 +550,11 @@ var createNonEnumerableProperty$6 = DESCRIPTORS$5 ? function (object, key, value
552
550
 
553
551
  var redefine$6 = {exports: {}};
554
552
 
555
- var uncurryThis$h = functionUncurryThis;
553
+ var uncurryThis$i = functionUncurryThis;
556
554
  var isCallable$d = isCallable$j;
557
555
  var store$1 = sharedStore;
558
556
 
559
- var functionToString = uncurryThis$h(Function.toString);
557
+ var functionToString = uncurryThis$i(Function.toString);
560
558
 
561
559
  // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
562
560
  if (!isCallable$d(store$1.inspectSource)) {
@@ -588,7 +586,7 @@ var hiddenKeys$4 = {};
588
586
 
589
587
  var NATIVE_WEAK_MAP = nativeWeakMap;
590
588
  var global$s = global$K;
591
- var uncurryThis$g = functionUncurryThis;
589
+ var uncurryThis$h = functionUncurryThis;
592
590
  var isObject$3 = isObject$8;
593
591
  var createNonEnumerableProperty$5 = createNonEnumerableProperty$6;
594
592
  var hasOwn$7 = hasOwnProperty_1;
@@ -599,16 +597,16 @@ var hiddenKeys$3 = hiddenKeys$4;
599
597
  var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
600
598
  var TypeError$b = global$s.TypeError;
601
599
  var WeakMap = global$s.WeakMap;
602
- var set$2, get$1, has;
600
+ var set$1, get, has;
603
601
 
604
602
  var enforce = function (it) {
605
- return has(it) ? get$1(it) : set$2(it, {});
603
+ return has(it) ? get(it) : set$1(it, {});
606
604
  };
607
605
 
608
606
  var getterFor = function (TYPE) {
609
607
  return function (it) {
610
608
  var state;
611
- if (!isObject$3(it) || (state = get$1(it)).type !== TYPE) {
609
+ if (!isObject$3(it) || (state = get(it)).type !== TYPE) {
612
610
  throw TypeError$b('Incompatible receiver, ' + TYPE + ' required');
613
611
  } return state;
614
612
  };
@@ -616,16 +614,16 @@ var getterFor = function (TYPE) {
616
614
 
617
615
  if (NATIVE_WEAK_MAP || shared$1.state) {
618
616
  var store = shared$1.state || (shared$1.state = new WeakMap());
619
- var wmget = uncurryThis$g(store.get);
620
- var wmhas = uncurryThis$g(store.has);
621
- var wmset = uncurryThis$g(store.set);
622
- set$2 = function (it, metadata) {
617
+ var wmget = uncurryThis$h(store.get);
618
+ var wmhas = uncurryThis$h(store.has);
619
+ var wmset = uncurryThis$h(store.set);
620
+ set$1 = function (it, metadata) {
623
621
  if (wmhas(store, it)) throw new TypeError$b(OBJECT_ALREADY_INITIALIZED);
624
622
  metadata.facade = it;
625
623
  wmset(store, it, metadata);
626
624
  return metadata;
627
625
  };
628
- get$1 = function (it) {
626
+ get = function (it) {
629
627
  return wmget(store, it) || {};
630
628
  };
631
629
  has = function (it) {
@@ -634,13 +632,13 @@ if (NATIVE_WEAK_MAP || shared$1.state) {
634
632
  } else {
635
633
  var STATE = sharedKey$2('state');
636
634
  hiddenKeys$3[STATE] = true;
637
- set$2 = function (it, metadata) {
635
+ set$1 = function (it, metadata) {
638
636
  if (hasOwn$7(it, STATE)) throw new TypeError$b(OBJECT_ALREADY_INITIALIZED);
639
637
  metadata.facade = it;
640
638
  createNonEnumerableProperty$5(it, STATE, metadata);
641
639
  return metadata;
642
640
  };
643
- get$1 = function (it) {
641
+ get = function (it) {
644
642
  return hasOwn$7(it, STATE) ? it[STATE] : {};
645
643
  };
646
644
  has = function (it) {
@@ -649,8 +647,8 @@ if (NATIVE_WEAK_MAP || shared$1.state) {
649
647
  }
650
648
 
651
649
  var internalState = {
652
- set: set$2,
653
- get: get$1,
650
+ set: set$1,
651
+ get: get,
654
652
  has: has,
655
653
  enforce: enforce,
656
654
  getterFor: getterFor
@@ -798,13 +796,13 @@ var arrayIncludes = {
798
796
  indexOf: createMethod$3(false)
799
797
  };
800
798
 
801
- var uncurryThis$f = functionUncurryThis;
799
+ var uncurryThis$g = functionUncurryThis;
802
800
  var hasOwn$4 = hasOwnProperty_1;
803
801
  var toIndexedObject$2 = toIndexedObject$5;
804
802
  var indexOf$1 = arrayIncludes.indexOf;
805
803
  var hiddenKeys$2 = hiddenKeys$4;
806
804
 
807
- var push$2 = uncurryThis$f([].push);
805
+ var push$2 = uncurryThis$g([].push);
808
806
 
809
807
  var objectKeysInternal = function (object, names) {
810
808
  var O = toIndexedObject$2(object);
@@ -848,12 +846,12 @@ var objectGetOwnPropertySymbols = {};
848
846
  objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols;
849
847
 
850
848
  var getBuiltIn$4 = getBuiltIn$7;
851
- var uncurryThis$e = functionUncurryThis;
849
+ var uncurryThis$f = functionUncurryThis;
852
850
  var getOwnPropertyNamesModule = objectGetOwnPropertyNames;
853
851
  var getOwnPropertySymbolsModule$1 = objectGetOwnPropertySymbols;
854
852
  var anObject$c = anObject$e;
855
853
 
856
- var concat$2 = uncurryThis$e([].concat);
854
+ var concat$2 = uncurryThis$f([].concat);
857
855
 
858
856
  // all object keys, includes non-enumerable and symbols
859
857
  var ownKeys$1 = getBuiltIn$4('Reflect', 'ownKeys') || function ownKeys(it) {
@@ -982,7 +980,7 @@ var aPossiblePrototype$1 = function (argument) {
982
980
 
983
981
  /* eslint-disable no-proto -- safe */
984
982
 
985
- var uncurryThis$d = functionUncurryThis;
983
+ var uncurryThis$e = functionUncurryThis;
986
984
  var anObject$b = anObject$e;
987
985
  var aPossiblePrototype = aPossiblePrototype$1;
988
986
 
@@ -996,7 +994,7 @@ var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? functio
996
994
  var setter;
997
995
  try {
998
996
  // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
999
- setter = uncurryThis$d(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set);
997
+ setter = uncurryThis$e(Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set);
1000
998
  setter(test, []);
1001
999
  CORRECT_SETTER = test instanceof Array;
1002
1000
  } catch (error) { /* empty */ }
@@ -1051,11 +1049,11 @@ var anInstance$1 = function (it, Prototype) {
1051
1049
  throw TypeError$9('Incorrect invocation');
1052
1050
  };
1053
1051
 
1054
- var uncurryThis$c = functionUncurryThis;
1052
+ var uncurryThis$d = functionUncurryThis;
1055
1053
  var aCallable$4 = aCallable$6;
1056
1054
  var NATIVE_BIND$1 = functionBindNative;
1057
1055
 
1058
- var bind$4 = uncurryThis$c(uncurryThis$c.bind);
1056
+ var bind$4 = uncurryThis$d(uncurryThis$d.bind);
1059
1057
 
1060
1058
  // optional / simple context binding
1061
1059
  var functionBindContext = function (fn, that) {
@@ -1276,7 +1274,7 @@ var checkCorrectnessOfIteration$1 = function (exec, SKIP_CLOSING) {
1276
1274
  return ITERATION_SUPPORT;
1277
1275
  };
1278
1276
 
1279
- var uncurryThis$b = functionUncurryThis;
1277
+ var uncurryThis$c = functionUncurryThis;
1280
1278
  var fails$c = fails$k;
1281
1279
  var isCallable$7 = isCallable$j;
1282
1280
  var classof$4 = classof$6;
@@ -1287,7 +1285,7 @@ var noop = function () { /* empty */ };
1287
1285
  var empty = [];
1288
1286
  var construct = getBuiltIn$2('Reflect', 'construct');
1289
1287
  var constructorRegExp = /^\s*(?:class|function)\b/;
1290
- var exec$3 = uncurryThis$b(constructorRegExp.exec);
1288
+ var exec$3 = uncurryThis$c(constructorRegExp.exec);
1291
1289
  var INCORRECT_TO_STRING = !constructorRegExp.exec(noop);
1292
1290
 
1293
1291
  var isConstructorModern = function isConstructor(argument) {
@@ -1370,9 +1368,9 @@ var getBuiltIn$1 = getBuiltIn$7;
1370
1368
 
1371
1369
  var html$2 = getBuiltIn$1('document', 'documentElement');
1372
1370
 
1373
- var uncurryThis$a = functionUncurryThis;
1371
+ var uncurryThis$b = functionUncurryThis;
1374
1372
 
1375
- var arraySlice$2 = uncurryThis$a([].slice);
1373
+ var arraySlice$2 = uncurryThis$b([].slice);
1376
1374
 
1377
1375
  var global$i = global$K;
1378
1376
 
@@ -1405,7 +1403,7 @@ var validateArgumentsLength = validateArgumentsLength$1;
1405
1403
  var IS_IOS$1 = engineIsIos;
1406
1404
  var IS_NODE$3 = engineIsNode;
1407
1405
 
1408
- var set$1 = global$g.setImmediate;
1406
+ var set = global$g.setImmediate;
1409
1407
  var clear = global$g.clearImmediate;
1410
1408
  var process$2 = global$g.process;
1411
1409
  var Dispatch = global$g.Dispatch;
@@ -1446,8 +1444,8 @@ var post = function (id) {
1446
1444
  };
1447
1445
 
1448
1446
  // Node.js 0.9+ & IE10+ has setImmediate, otherwise:
1449
- if (!set$1 || !clear) {
1450
- set$1 = function setImmediate(handler) {
1447
+ if (!set || !clear) {
1448
+ set = function setImmediate(handler) {
1451
1449
  validateArgumentsLength(arguments.length, 1);
1452
1450
  var fn = isCallable$6(handler) ? handler : Function$1(handler);
1453
1451
  var args = arraySlice$1(arguments, 1);
@@ -1505,7 +1503,7 @@ if (!set$1 || !clear) {
1505
1503
  }
1506
1504
 
1507
1505
  var task$1 = {
1508
- set: set$1,
1506
+ set: set,
1509
1507
  clear: clear
1510
1508
  };
1511
1509
 
@@ -1681,7 +1679,7 @@ var queue = Queue$1;
1681
1679
 
1682
1680
  var engineIsBrowser = typeof window == 'object';
1683
1681
 
1684
- var $$6 = _export;
1682
+ var $$7 = _export;
1685
1683
  var global$c = global$K;
1686
1684
  var getBuiltIn = getBuiltIn$7;
1687
1685
  var call$6 = functionCall;
@@ -2006,7 +2004,7 @@ if (FORCED$1) {
2006
2004
  }
2007
2005
  }
2008
2006
 
2009
- $$6({ global: true, wrap: true, forced: FORCED$1 }, {
2007
+ $$7({ global: true, wrap: true, forced: FORCED$1 }, {
2010
2008
  Promise: PromiseConstructor
2011
2009
  });
2012
2010
 
@@ -2016,7 +2014,7 @@ setSpecies(PROMISE);
2016
2014
  PromiseWrapper = getBuiltIn(PROMISE);
2017
2015
 
2018
2016
  // statics
2019
- $$6({ target: PROMISE, stat: true, forced: FORCED$1 }, {
2017
+ $$7({ target: PROMISE, stat: true, forced: FORCED$1 }, {
2020
2018
  // `Promise.reject` method
2021
2019
  // https://tc39.es/ecma262/#sec-promise.reject
2022
2020
  reject: function reject(r) {
@@ -2026,7 +2024,7 @@ $$6({ target: PROMISE, stat: true, forced: FORCED$1 }, {
2026
2024
  }
2027
2025
  });
2028
2026
 
2029
- $$6({ target: PROMISE, stat: true, forced: FORCED$1 }, {
2027
+ $$7({ target: PROMISE, stat: true, forced: FORCED$1 }, {
2030
2028
  // `Promise.resolve` method
2031
2029
  // https://tc39.es/ecma262/#sec-promise.resolve
2032
2030
  resolve: function resolve(x) {
@@ -2034,7 +2032,7 @@ $$6({ target: PROMISE, stat: true, forced: FORCED$1 }, {
2034
2032
  }
2035
2033
  });
2036
2034
 
2037
- $$6({ target: PROMISE, stat: true, forced: INCORRECT_ITERATION }, {
2035
+ $$7({ target: PROMISE, stat: true, forced: INCORRECT_ITERATION }, {
2038
2036
  // `Promise.all` method
2039
2037
  // https://tc39.es/ecma262/#sec-promise.all
2040
2038
  all: function all(iterable) {
@@ -2091,7 +2089,7 @@ var objectKeys$2 = Object.keys || function keys(O) {
2091
2089
  };
2092
2090
 
2093
2091
  var DESCRIPTORS$2 = descriptors;
2094
- var uncurryThis$9 = functionUncurryThis;
2092
+ var uncurryThis$a = functionUncurryThis;
2095
2093
  var call$5 = functionCall;
2096
2094
  var fails$a = fails$k;
2097
2095
  var objectKeys$1 = objectKeys$2;
@@ -2104,7 +2102,7 @@ var IndexedObject$1 = indexedObject;
2104
2102
  var $assign = Object.assign;
2105
2103
  // eslint-disable-next-line es/no-object-defineproperty -- required for testing
2106
2104
  var defineProperty$1 = Object.defineProperty;
2107
- var concat$1 = uncurryThis$9([].concat);
2105
+ var concat$1 = uncurryThis$a([].concat);
2108
2106
 
2109
2107
  // `Object.assign` method
2110
2108
  // https://tc39.es/ecma262/#sec-object.assign
@@ -2147,16 +2145,87 @@ var objectAssign = !$assign || fails$a(function () {
2147
2145
  } return T;
2148
2146
  } : $assign;
2149
2147
 
2150
- var $$5 = _export;
2148
+ var $$6 = _export;
2151
2149
  var assign = objectAssign;
2152
2150
 
2153
2151
  // `Object.assign` method
2154
2152
  // https://tc39.es/ecma262/#sec-object.assign
2155
2153
  // eslint-disable-next-line es/no-object-assign -- required for testing
2156
- $$5({ target: 'Object', stat: true, forced: Object.assign !== assign }, {
2154
+ $$6({ target: 'Object', stat: true, forced: Object.assign !== assign }, {
2157
2155
  assign: assign
2158
2156
  });
2159
2157
 
2158
+ var isObject = isObject$8;
2159
+ var classof$2 = classofRaw$1;
2160
+ var wellKnownSymbol$7 = wellKnownSymbol$i;
2161
+
2162
+ var MATCH$1 = wellKnownSymbol$7('match');
2163
+
2164
+ // `IsRegExp` abstract operation
2165
+ // https://tc39.es/ecma262/#sec-isregexp
2166
+ var isRegexp = function (it) {
2167
+ var isRegExp;
2168
+ return isObject(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classof$2(it) == 'RegExp');
2169
+ };
2170
+
2171
+ var global$b = global$K;
2172
+ var isRegExp$1 = isRegexp;
2173
+
2174
+ var TypeError$3 = global$b.TypeError;
2175
+
2176
+ var notARegexp = function (it) {
2177
+ if (isRegExp$1(it)) {
2178
+ throw TypeError$3("The method doesn't accept regular expressions");
2179
+ } return it;
2180
+ };
2181
+
2182
+ var global$a = global$K;
2183
+ var classof$1 = classof$6;
2184
+
2185
+ var String$1 = global$a.String;
2186
+
2187
+ var toString$8 = function (argument) {
2188
+ if (classof$1(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string');
2189
+ return String$1(argument);
2190
+ };
2191
+
2192
+ var wellKnownSymbol$6 = wellKnownSymbol$i;
2193
+
2194
+ var MATCH = wellKnownSymbol$6('match');
2195
+
2196
+ var correctIsRegexpLogic = function (METHOD_NAME) {
2197
+ var regexp = /./;
2198
+ try {
2199
+ '/./'[METHOD_NAME](regexp);
2200
+ } catch (error1) {
2201
+ try {
2202
+ regexp[MATCH] = false;
2203
+ return '/./'[METHOD_NAME](regexp);
2204
+ } catch (error2) { /* empty */ }
2205
+ } return false;
2206
+ };
2207
+
2208
+ var $$5 = _export;
2209
+ var uncurryThis$9 = functionUncurryThis;
2210
+ var notARegExp$1 = notARegexp;
2211
+ var requireObjectCoercible$5 = requireObjectCoercible$8;
2212
+ var toString$7 = toString$8;
2213
+ var correctIsRegExpLogic$1 = correctIsRegexpLogic;
2214
+
2215
+ var stringIndexOf$1 = uncurryThis$9(''.indexOf);
2216
+
2217
+ // `String.prototype.includes` method
2218
+ // https://tc39.es/ecma262/#sec-string.prototype.includes
2219
+ $$5({ target: 'String', proto: true, forced: !correctIsRegExpLogic$1('includes') }, {
2220
+ includes: function includes(searchString /* , position = 0 */) {
2221
+ return !!~stringIndexOf$1(
2222
+ toString$7(requireObjectCoercible$5(this)),
2223
+ toString$7(notARegExp$1(searchString)),
2224
+ arguments.length > 1 ? arguments[1] : undefined
2225
+ );
2226
+ }
2227
+ });
2228
+
2160
2229
  /*! *****************************************************************************
2161
2230
  Copyright (c) Microsoft Corporation.
2162
2231
 
@@ -2182,48 +2251,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
2182
2251
  });
2183
2252
  }
2184
2253
 
2185
- const NINETAILED_CACHE_KEY = '__nt-cache__';
2186
- const initialize = ({
2187
- instance
2188
- }, data = {}) => {
2189
- const cache = buildEmptyCache();
2190
- instance.storage.setItem(NINETAILED_CACHE_KEY, Object.assign(Object.assign({}, cache), data));
2191
- return cache;
2192
- };
2193
- const get = ({
2194
- instance
2195
- }) => {
2196
- const cache = instance.storage.getItem(NINETAILED_CACHE_KEY);
2197
- return cache;
2198
- };
2199
- const set = (cache, {
2200
- instance
2201
- }) => {
2202
- instance.storage.setItem(NINETAILED_CACHE_KEY, cache);
2203
- return cache;
2204
- };
2205
- const remove = ({
2206
- instance
2207
- }) => {
2208
- instance.storage.removeItem(NINETAILED_CACHE_KEY);
2209
- };
2210
- const reset = ({
2211
- instance
2212
- }) => {
2213
- return initialize({
2214
- instance
2215
- });
2216
- };
2217
-
2218
- var index = /*#__PURE__*/Object.freeze({
2219
- __proto__: null,
2220
- initialize: initialize,
2221
- get: get,
2222
- set: set,
2223
- remove: remove,
2224
- reset: reset
2225
- });
2226
-
2227
2254
  const buildClientLocale = () => navigator.languages && navigator.languages.length ? navigator.languages[0] : navigator.language;
2228
2255
 
2229
2256
  const buildClientNinetailedRequestContext = () => ({
@@ -2236,161 +2263,312 @@ const buildClientNinetailedRequestContext = () => ({
2236
2263
  }
2237
2264
  });
2238
2265
 
2239
- const BASE_URL = 'https://api.ninetailed.co';
2240
-
2241
- const fetchWithTimeout = (input, init) => __awaiter(void 0, void 0, void 0, function* () {
2242
- const {
2243
- timeout
2244
- } = init;
2245
- const controller = new AbortController();
2246
- const id = setTimeout(() => {
2247
- logger.warn('Ninetailed Request timed out.');
2248
- controller.abort();
2249
- }, timeout);
2250
- const response = yield fetch(input, Object.assign(Object.assign({}, init), {
2251
- signal: controller.signal
2252
- }));
2253
- clearTimeout(id);
2254
- return response;
2255
- });
2256
-
2257
- class NinetailedApiClient {
2258
- constructor({
2259
- clientId,
2260
- environment = 'main',
2261
- url = BASE_URL
2262
- }) {
2263
- this.clientId = clientId;
2264
- this.environment = environment;
2265
- this.url = url;
2266
- }
2267
-
2268
- profile(options) {
2269
- return __awaiter(this, void 0, void 0, function* () {
2270
- logger.info('Sending Profile Request.');
2271
- const {
2272
- events
2273
- } = options; // TODO throw error if not all events have same anon id.
2266
+ /**
2267
+ * Similar to _.throttle but waits for the promise to resolve. There is no
2268
+ * wait time because you can simply await `Promise.timeout` inside `fn`
2269
+ * to wait some time before the next call.
2270
+ */
2274
2271
 
2275
- const anonymousId = events[0].anonymousId;
2276
- const body = options;
2277
- logger.debug('Profile Request Body: ', body);
2272
+ function asyncThrottle(fn) {
2273
+ let runningPromise;
2274
+ let queuedPromise;
2275
+ let nextArgs;
2276
+ return args => __awaiter(this, void 0, void 0, function* () {
2277
+ if (runningPromise) {
2278
+ nextArgs = args;
2278
2279
 
2279
- try {
2280
- const request = yield fetchWithTimeout(`${this.url}/v1/organizations/${this.clientId}/environments/${this.environment}/profiles/${anonymousId}/events`, {
2281
- method: 'POST',
2282
- headers: {
2283
- 'Content-Type': 'application/json'
2284
- },
2285
- body: JSON.stringify(body),
2286
- timeout: options.timeout || 3000
2280
+ if (queuedPromise) {
2281
+ return queuedPromise;
2282
+ } else {
2283
+ queuedPromise = runningPromise.then(() => {
2284
+ queuedPromise = undefined;
2285
+ runningPromise = fn(nextArgs);
2286
+ return runningPromise;
2287
2287
  });
2288
- logger.debug('Profile Request: ', request);
2289
- const {
2290
- data
2291
- } = yield request.json();
2292
- logger.debug('Profile Request completed.');
2293
- return data;
2294
- } catch (error) {
2295
- throw error;
2288
+ return queuedPromise;
2296
2289
  }
2297
- });
2298
- }
2299
-
2290
+ } else {
2291
+ runningPromise = fn(args);
2292
+ return runningPromise;
2293
+ }
2294
+ });
2300
2295
  }
2301
2296
 
2302
- var objectDefineProperties = {};
2303
-
2304
- var DESCRIPTORS$1 = descriptors;
2305
- var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug;
2306
- var definePropertyModule$2 = objectDefineProperty;
2307
- var anObject$5 = anObject$e;
2308
- var toIndexedObject$1 = toIndexedObject$5;
2309
- var objectKeys = objectKeys$2;
2297
+ const LEGACY_ANONYMOUS_ID = '__anon_id';
2298
+ const ANONYMOUS_ID = '__nt_anonymous_id__';
2299
+ const DEBUG_FLAG = '__nt_debug__';
2300
+ const PROFILE_FALLBACK_CACHE = '__nt_profile__';
2310
2301
 
2311
- // `Object.defineProperties` method
2312
- // https://tc39.es/ecma262/#sec-object.defineproperties
2313
- // eslint-disable-next-line es/no-object-defineproperties -- safe
2314
- objectDefineProperties.f = DESCRIPTORS$1 && !V8_PROTOTYPE_DEFINE_BUG ? Object.defineProperties : function defineProperties(O, Properties) {
2315
- anObject$5(O);
2316
- var props = toIndexedObject$1(Properties);
2317
- var keys = objectKeys(Properties);
2318
- var length = keys.length;
2319
- var index = 0;
2320
- var key;
2321
- while (length > index) definePropertyModule$2.f(O, key = keys[index++], props[key]);
2322
- return O;
2302
+ const NINETAILED_TRACKER_EVENTS = {
2303
+ /**
2304
+ * `profile` - Fires when the profile is returned by the cdp API.
2305
+ */
2306
+ profile: 'profile'
2323
2307
  };
2308
+ const PLUGIN_NAME = 'ninetailed';
2324
2309
 
2325
- /* global ActiveXObject -- old IE, WSH */
2310
+ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
2326
2311
 
2327
- var anObject$4 = anObject$e;
2328
- var definePropertiesModule = objectDefineProperties;
2329
- var enumBugKeys = enumBugKeys$3;
2330
- var hiddenKeys = hiddenKeys$4;
2331
- var html = html$2;
2332
- var documentCreateElement$1 = documentCreateElement$2;
2333
- var sharedKey$1 = sharedKey$3;
2312
+ const emptyProfile = {
2313
+ id: '',
2314
+ random: 0,
2315
+ audiences: [],
2316
+ traits: {},
2317
+ location: {}
2318
+ };
2319
+ const ninetailedPlugin = ({
2320
+ clientId,
2321
+ environment,
2322
+ preview: _preview = false,
2323
+ url,
2324
+ profile,
2325
+ locale
2326
+ }) => {
2327
+ const apiClient = new NinetailedApiClient({
2328
+ clientId,
2329
+ environment,
2330
+ url
2331
+ });
2332
+ let queue = [];
2334
2333
 
2335
- var GT = '>';
2336
- var LT = '<';
2337
- var PROTOTYPE = 'prototype';
2338
- var SCRIPT = 'script';
2339
- var IE_PROTO$1 = sharedKey$1('IE_PROTO');
2334
+ const flush = instance => __awaiter(void 0, void 0, void 0, function* () {
2335
+ const events = Object.assign([], queue);
2336
+ logger.info('Start flushing events.');
2337
+ queue = [];
2340
2338
 
2341
- var EmptyConstructor = function () { /* empty */ };
2339
+ if (!events.length) {
2340
+ return;
2341
+ }
2342
2342
 
2343
- var scriptTag = function (content) {
2344
- return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
2345
- };
2343
+ try {
2344
+ const anonymousId = instance.storage.getItem(ANONYMOUS_ID);
2345
+ const profile = yield apiClient.upsertProfile(events, anonymousId);
2346
+ instance.storage.setItem(ANONYMOUS_ID, profile.id);
2347
+ instance.storage.setItem(PROFILE_FALLBACK_CACHE, profile);
2348
+ logger.debug('Profile from api: ', profile);
2349
+ instance.dispatch({
2350
+ type: NINETAILED_TRACKER_EVENTS.profile,
2351
+ profile
2352
+ });
2353
+ } catch (error) {
2354
+ logger.debug('An error occurred during flushing the events: ', error);
2355
+ const fallbackProfile = instance.storage.getItem(PROFILE_FALLBACK_CACHE) || emptyProfile;
2356
+ instance.dispatch({
2357
+ type: NINETAILED_TRACKER_EVENTS.profile,
2358
+ profile: fallbackProfile
2359
+ });
2360
+ } // This is necessary to make sure that the cache is updated before the next flush is performed
2346
2361
 
2347
- // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
2348
- var NullProtoObjectViaActiveX = function (activeXDocument) {
2349
- activeXDocument.write(scriptTag(''));
2350
- activeXDocument.close();
2351
- var temp = activeXDocument.parentWindow.Object;
2352
- activeXDocument = null; // avoid memory leak
2353
- return temp;
2354
- };
2355
2362
 
2356
- // Create object with fake `null` prototype: use iframe Object with cleared prototype
2357
- var NullProtoObjectViaIFrame = function () {
2358
- // Thrash, waste and sodomy: IE GC bug
2359
- var iframe = documentCreateElement$1('iframe');
2360
- var JS = 'java' + SCRIPT + ':';
2361
- var iframeDocument;
2362
- iframe.style.display = 'none';
2363
- html.appendChild(iframe);
2364
- // https://github.com/zloirock/core-js/issues/475
2365
- iframe.src = String(JS);
2366
- iframeDocument = iframe.contentWindow.document;
2367
- iframeDocument.open();
2368
- iframeDocument.write(scriptTag('document.F=Object'));
2369
- iframeDocument.close();
2370
- return iframeDocument.F;
2371
- };
2363
+ yield delay(20);
2364
+ });
2372
2365
 
2373
- // Check for document.domain and active x support
2374
- // No need to use active x approach when document.domain is not set
2375
- // see https://github.com/es-shims/es5-shim/issues/150
2376
- // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
2377
- // avoid IE GC bug
2378
- var activeXDocument;
2379
- var NullProtoObject = function () {
2380
- try {
2381
- activeXDocument = new ActiveXObject('htmlfile');
2382
- } catch (error) { /* ignore */ }
2383
- NullProtoObject = typeof document != 'undefined'
2384
- ? document.domain && activeXDocument
2385
- ? NullProtoObjectViaActiveX(activeXDocument) // old IE
2386
- : NullProtoObjectViaIFrame()
2387
- : NullProtoObjectViaActiveX(activeXDocument); // WSH
2388
- var length = enumBugKeys.length;
2389
- while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
2390
- return NullProtoObject();
2391
- };
2366
+ const throttledFlush = asyncThrottle(flush);
2392
2367
 
2393
- hiddenKeys[IE_PROTO$1] = true;
2368
+ const enqueueEvent = (event, instance) => __awaiter(void 0, void 0, void 0, function* () {
2369
+ queue = unionBy([event], queue, 'messageId');
2370
+ throttledFlush(instance);
2371
+ });
2372
+
2373
+ return {
2374
+ name: 'ninetailed',
2375
+ config: {},
2376
+ initialize: ({
2377
+ instance
2378
+ }) => {
2379
+ if (instance.storage.getItem(DEBUG_FLAG)) {
2380
+ logger.addSink(new ConsoleLogSink());
2381
+ logger.info('Ninetailed Debug Mode is enabled.');
2382
+ } // legacy support for the old anonymousId
2383
+
2384
+
2385
+ const legacyAnonymousId = instance.storage.getItem(LEGACY_ANONYMOUS_ID);
2386
+
2387
+ if (legacyAnonymousId) {
2388
+ logger.debug('Found legacy anonymousId, migrating to new one.', legacyAnonymousId);
2389
+ instance.storage.setItem(ANONYMOUS_ID, legacyAnonymousId);
2390
+ instance.storage.removeItem(LEGACY_ANONYMOUS_ID);
2391
+ }
2392
+
2393
+ if (profile) {
2394
+ instance.storage.setItem(ANONYMOUS_ID, profile.id);
2395
+ }
2396
+
2397
+ logger.debug('Ninetailed Core plugin initialized.');
2398
+ },
2399
+ page: ({
2400
+ payload,
2401
+ instance
2402
+ }) => __awaiter(void 0, void 0, void 0, function* () {
2403
+ logger.info('Sending Page event.');
2404
+ const ctx = buildClientNinetailedRequestContext();
2405
+ yield enqueueEvent(buildPageEvent({
2406
+ messageId: payload.meta.rid,
2407
+ timestamp: payload.meta.ts,
2408
+ properties: payload.properties,
2409
+ ctx
2410
+ }), instance);
2411
+ }),
2412
+ track: ({
2413
+ payload,
2414
+ instance
2415
+ }) => __awaiter(void 0, void 0, void 0, function* () {
2416
+ logger.info('Sending Track event.');
2417
+ const ctx = buildClientNinetailedRequestContext();
2418
+ yield enqueueEvent(buildTrackEvent({
2419
+ messageId: payload.meta.rid,
2420
+ timestamp: payload.meta.ts,
2421
+ event: payload.event,
2422
+ properties: payload.properties,
2423
+ ctx
2424
+ }), instance);
2425
+ }),
2426
+ identify: ({
2427
+ payload,
2428
+ instance
2429
+ }) => __awaiter(void 0, void 0, void 0, function* () {
2430
+ logger.info('Sending Identify event.');
2431
+ const ctx = buildClientNinetailedRequestContext();
2432
+ yield enqueueEvent(buildIdentifyEvent({
2433
+ // doing this here as the anonymous id is set to late from init
2434
+ messageId: payload.meta.rid,
2435
+ timestamp: payload.meta.ts,
2436
+ traits: payload.traits,
2437
+ userId: payload.userId,
2438
+ ctx
2439
+ }), instance);
2440
+ }),
2441
+ setItemStart: ({
2442
+ abort,
2443
+ payload
2444
+ }) => {
2445
+ if (![ANONYMOUS_ID, DEBUG_FLAG, PROFILE_FALLBACK_CACHE].includes(payload.key)) {
2446
+ return abort();
2447
+ }
2448
+
2449
+ return payload;
2450
+ },
2451
+ methods: {
2452
+ reset: (...args) => __awaiter(void 0, void 0, void 0, function* () {
2453
+ const instance = args[args.length - 1];
2454
+ yield instance.storage.removeItem(ANONYMOUS_ID);
2455
+ instance.dispatch({
2456
+ type: NINETAILED_TRACKER_EVENTS.profile,
2457
+ profile: emptyProfile
2458
+ });
2459
+ yield delay(10);
2460
+ }),
2461
+ debug: (...args) => __awaiter(void 0, void 0, void 0, function* () {
2462
+ const enabled = args[0];
2463
+ const instance = args[args.length - 1];
2464
+ const consoleLogSink = new ConsoleLogSink();
2465
+
2466
+ if (enabled) {
2467
+ yield instance.storage.setItem(DEBUG_FLAG, true);
2468
+ logger.addSink(consoleLogSink);
2469
+ logger.info('Debug mode enabled.');
2470
+ } else {
2471
+ yield instance.storage.removeItem(DEBUG_FLAG);
2472
+ logger.info('Debug mode disabled.');
2473
+ logger.removeSink(consoleLogSink.name);
2474
+ }
2475
+ })
2476
+ }
2477
+ };
2478
+ };
2479
+
2480
+ var objectDefineProperties = {};
2481
+
2482
+ var DESCRIPTORS$1 = descriptors;
2483
+ var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug;
2484
+ var definePropertyModule$2 = objectDefineProperty;
2485
+ var anObject$5 = anObject$e;
2486
+ var toIndexedObject$1 = toIndexedObject$5;
2487
+ var objectKeys = objectKeys$2;
2488
+
2489
+ // `Object.defineProperties` method
2490
+ // https://tc39.es/ecma262/#sec-object.defineproperties
2491
+ // eslint-disable-next-line es/no-object-defineproperties -- safe
2492
+ objectDefineProperties.f = DESCRIPTORS$1 && !V8_PROTOTYPE_DEFINE_BUG ? Object.defineProperties : function defineProperties(O, Properties) {
2493
+ anObject$5(O);
2494
+ var props = toIndexedObject$1(Properties);
2495
+ var keys = objectKeys(Properties);
2496
+ var length = keys.length;
2497
+ var index = 0;
2498
+ var key;
2499
+ while (length > index) definePropertyModule$2.f(O, key = keys[index++], props[key]);
2500
+ return O;
2501
+ };
2502
+
2503
+ /* global ActiveXObject -- old IE, WSH */
2504
+
2505
+ var anObject$4 = anObject$e;
2506
+ var definePropertiesModule = objectDefineProperties;
2507
+ var enumBugKeys = enumBugKeys$3;
2508
+ var hiddenKeys = hiddenKeys$4;
2509
+ var html = html$2;
2510
+ var documentCreateElement$1 = documentCreateElement$2;
2511
+ var sharedKey$1 = sharedKey$3;
2512
+
2513
+ var GT = '>';
2514
+ var LT = '<';
2515
+ var PROTOTYPE = 'prototype';
2516
+ var SCRIPT = 'script';
2517
+ var IE_PROTO$1 = sharedKey$1('IE_PROTO');
2518
+
2519
+ var EmptyConstructor = function () { /* empty */ };
2520
+
2521
+ var scriptTag = function (content) {
2522
+ return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
2523
+ };
2524
+
2525
+ // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
2526
+ var NullProtoObjectViaActiveX = function (activeXDocument) {
2527
+ activeXDocument.write(scriptTag(''));
2528
+ activeXDocument.close();
2529
+ var temp = activeXDocument.parentWindow.Object;
2530
+ activeXDocument = null; // avoid memory leak
2531
+ return temp;
2532
+ };
2533
+
2534
+ // Create object with fake `null` prototype: use iframe Object with cleared prototype
2535
+ var NullProtoObjectViaIFrame = function () {
2536
+ // Thrash, waste and sodomy: IE GC bug
2537
+ var iframe = documentCreateElement$1('iframe');
2538
+ var JS = 'java' + SCRIPT + ':';
2539
+ var iframeDocument;
2540
+ iframe.style.display = 'none';
2541
+ html.appendChild(iframe);
2542
+ // https://github.com/zloirock/core-js/issues/475
2543
+ iframe.src = String(JS);
2544
+ iframeDocument = iframe.contentWindow.document;
2545
+ iframeDocument.open();
2546
+ iframeDocument.write(scriptTag('document.F=Object'));
2547
+ iframeDocument.close();
2548
+ return iframeDocument.F;
2549
+ };
2550
+
2551
+ // Check for document.domain and active x support
2552
+ // No need to use active x approach when document.domain is not set
2553
+ // see https://github.com/es-shims/es5-shim/issues/150
2554
+ // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
2555
+ // avoid IE GC bug
2556
+ var activeXDocument;
2557
+ var NullProtoObject = function () {
2558
+ try {
2559
+ activeXDocument = new ActiveXObject('htmlfile');
2560
+ } catch (error) { /* ignore */ }
2561
+ NullProtoObject = typeof document != 'undefined'
2562
+ ? document.domain && activeXDocument
2563
+ ? NullProtoObjectViaActiveX(activeXDocument) // old IE
2564
+ : NullProtoObjectViaIFrame()
2565
+ : NullProtoObjectViaActiveX(activeXDocument); // WSH
2566
+ var length = enumBugKeys.length;
2567
+ while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
2568
+ return NullProtoObject();
2569
+ };
2570
+
2571
+ hiddenKeys[IE_PROTO$1] = true;
2394
2572
 
2395
2573
  // `Object.create` method
2396
2574
  // https://tc39.es/ecma262/#sec-object.create
@@ -2406,11 +2584,11 @@ var objectCreate = Object.create || function create(O, Properties) {
2406
2584
  return Properties === undefined ? result : definePropertiesModule.f(result, Properties);
2407
2585
  };
2408
2586
 
2409
- var wellKnownSymbol$7 = wellKnownSymbol$i;
2587
+ var wellKnownSymbol$5 = wellKnownSymbol$i;
2410
2588
  var create$2 = objectCreate;
2411
2589
  var definePropertyModule$1 = objectDefineProperty;
2412
2590
 
2413
- var UNSCOPABLES = wellKnownSymbol$7('unscopables');
2591
+ var UNSCOPABLES = wellKnownSymbol$5('unscopables');
2414
2592
  var ArrayPrototype = Array.prototype;
2415
2593
 
2416
2594
  // Array.prototype[@@unscopables]
@@ -2436,7 +2614,7 @@ var correctPrototypeGetter = !fails$9(function () {
2436
2614
  return Object.getPrototypeOf(new F()) !== F.prototype;
2437
2615
  });
2438
2616
 
2439
- var global$b = global$K;
2617
+ var global$9 = global$K;
2440
2618
  var hasOwn = hasOwnProperty_1;
2441
2619
  var isCallable$4 = isCallable$j;
2442
2620
  var toObject$2 = toObject$5;
@@ -2444,7 +2622,7 @@ var sharedKey = sharedKey$3;
2444
2622
  var CORRECT_PROTOTYPE_GETTER = correctPrototypeGetter;
2445
2623
 
2446
2624
  var IE_PROTO = sharedKey('IE_PROTO');
2447
- var Object$1 = global$b.Object;
2625
+ var Object$1 = global$9.Object;
2448
2626
  var ObjectPrototype = Object$1.prototype;
2449
2627
 
2450
2628
  // `Object.getPrototypeOf` method
@@ -2462,9 +2640,9 @@ var fails$8 = fails$k;
2462
2640
  var isCallable$3 = isCallable$j;
2463
2641
  var getPrototypeOf$1 = objectGetPrototypeOf;
2464
2642
  var redefine$2 = redefine$6.exports;
2465
- var wellKnownSymbol$6 = wellKnownSymbol$i;
2643
+ var wellKnownSymbol$4 = wellKnownSymbol$i;
2466
2644
 
2467
- var ITERATOR$3 = wellKnownSymbol$6('iterator');
2645
+ var ITERATOR$3 = wellKnownSymbol$4('iterator');
2468
2646
  var BUGGY_SAFARI_ITERATORS$1 = false;
2469
2647
 
2470
2648
  // `%IteratorPrototype%` object
@@ -2529,7 +2707,7 @@ var setPrototypeOf = objectSetPrototypeOf;
2529
2707
  var setToStringTag = setToStringTag$3;
2530
2708
  var createNonEnumerableProperty$2 = createNonEnumerableProperty$6;
2531
2709
  var redefine$1 = redefine$6.exports;
2532
- var wellKnownSymbol$5 = wellKnownSymbol$i;
2710
+ var wellKnownSymbol$3 = wellKnownSymbol$i;
2533
2711
  var Iterators$1 = iterators;
2534
2712
  var IteratorsCore = iteratorsCore;
2535
2713
 
@@ -2537,7 +2715,7 @@ var PROPER_FUNCTION_NAME = FunctionName.PROPER;
2537
2715
  var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
2538
2716
  var IteratorPrototype = IteratorsCore.IteratorPrototype;
2539
2717
  var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
2540
- var ITERATOR$2 = wellKnownSymbol$5('iterator');
2718
+ var ITERATOR$2 = wellKnownSymbol$3('iterator');
2541
2719
  var KEYS = 'keys';
2542
2720
  var VALUES = 'values';
2543
2721
  var ENTRIES = 'entries';
@@ -2720,15 +2898,15 @@ var DOMTokenListPrototype$1 = classList && classList.constructor && classList.co
2720
2898
 
2721
2899
  var domTokenListPrototype = DOMTokenListPrototype$1 === Object.prototype ? undefined : DOMTokenListPrototype$1;
2722
2900
 
2723
- var global$a = global$K;
2901
+ var global$8 = global$K;
2724
2902
  var DOMIterables = domIterables;
2725
2903
  var DOMTokenListPrototype = domTokenListPrototype;
2726
2904
  var ArrayIteratorMethods = es_array_iterator;
2727
2905
  var createNonEnumerableProperty$1 = createNonEnumerableProperty$6;
2728
- var wellKnownSymbol$4 = wellKnownSymbol$i;
2906
+ var wellKnownSymbol$2 = wellKnownSymbol$i;
2729
2907
 
2730
- var ITERATOR$1 = wellKnownSymbol$4('iterator');
2731
- var TO_STRING_TAG = wellKnownSymbol$4('toStringTag');
2908
+ var ITERATOR$1 = wellKnownSymbol$2('iterator');
2909
+ var TO_STRING_TAG = wellKnownSymbol$2('toStringTag');
2732
2910
  var ArrayValues = ArrayIteratorMethods.values;
2733
2911
 
2734
2912
  var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
@@ -2754,401 +2932,11 @@ var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
2754
2932
  };
2755
2933
 
2756
2934
  for (var COLLECTION_NAME in DOMIterables) {
2757
- handlePrototype(global$a[COLLECTION_NAME] && global$a[COLLECTION_NAME].prototype, COLLECTION_NAME);
2935
+ handlePrototype(global$8[COLLECTION_NAME] && global$8[COLLECTION_NAME].prototype, COLLECTION_NAME);
2758
2936
  }
2759
2937
 
2760
2938
  handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
2761
2939
 
2762
- class Logger {
2763
- constructor() {
2764
- this.name = '@ninetailed/experience.js';
2765
- this.sinks = [];
2766
- this.diary = diary(this.name, this.onLogEvent.bind(this));
2767
- enable(this.name);
2768
- }
2769
-
2770
- addSink(sink) {
2771
- this.sinks = [...this.sinks.filter(existingSink => existingSink.name !== sink.name), sink];
2772
- }
2773
-
2774
- removeSink(name) {
2775
- this.sinks = this.sinks.filter(sink => sink.name !== name);
2776
- }
2777
-
2778
- debug(message, ...args) {
2779
- this.diary.debug(message, ...args);
2780
- }
2781
-
2782
- info(message, ...args) {
2783
- this.diary.info(message, ...args);
2784
- }
2785
-
2786
- log(message, ...args) {
2787
- this.diary.log(message, ...args);
2788
- }
2789
-
2790
- warn(message, ...args) {
2791
- this.diary.warn(message, ...args);
2792
- }
2793
-
2794
- error(message, ...args) {
2795
- this.diary.error(message, ...args);
2796
- }
2797
-
2798
- fatal(message, ...args) {
2799
- this.diary.fatal(message, ...args);
2800
- }
2801
-
2802
- onLogEvent(event) {
2803
- this.sinks.forEach(sink => {
2804
- if (sink[event.level]) {
2805
- sink[event.level](event.message, ...event.extra);
2806
- }
2807
- });
2808
- }
2809
-
2810
- }
2811
- const logger = new Logger();
2812
-
2813
- class ConsoleLogSink {
2814
- constructor() {
2815
- this.name = "ConsoleLogSink";
2816
- }
2817
-
2818
- debug(message, ...args) {
2819
- console.debug(message, ...args);
2820
- }
2821
-
2822
- info(message, ...args) {
2823
- console.info(message, ...args);
2824
- }
2825
-
2826
- log(message, ...args) {
2827
- console.log(message, ...args);
2828
- }
2829
-
2830
- warn(message, ...args) {
2831
- console.warn(message, ...args);
2832
- }
2833
-
2834
- error(message, ...args) {
2835
- console.error(message, ...args);
2836
- }
2837
-
2838
- fatal(message, ...args) {
2839
- console.error(message, ...args);
2840
- }
2841
-
2842
- }
2843
-
2844
- class OnLogLogSink {
2845
- constructor(onLog) {
2846
- this.onLog = onLog;
2847
- this.name = 'OnLogLogSink';
2848
- }
2849
-
2850
- debug(message, ...args) {
2851
- this.onLog(message, ...args);
2852
- }
2853
-
2854
- info(message, ...args) {
2855
- this.onLog(message, ...args);
2856
- }
2857
-
2858
- log(message, ...args) {
2859
- this.onLog(message, ...args);
2860
- }
2861
-
2862
- warn(message, ...args) {
2863
- this.onLog(message, ...args);
2864
- }
2865
-
2866
- }
2867
-
2868
- class OnErrorLogSink {
2869
- constructor(onError) {
2870
- this.onError = onError;
2871
- this.name = 'OnErrorLogSink';
2872
- }
2873
-
2874
- error(message, ...args) {
2875
- this.onError(message, ...args);
2876
- }
2877
-
2878
- fatal(message, ...args) {
2879
- this.onError(message, ...args);
2880
- }
2881
-
2882
- }
2883
-
2884
- const NINETAILED_TRACKER_EVENTS = {
2885
- /**
2886
- * `profile` - Fires when the profile is returned by the cdp API.
2887
- */
2888
- profile: 'profile'
2889
- };
2890
- const PLUGIN_NAME = 'ninetailed';
2891
- const DEBUG_FLAG_KEY = 'nt-debug';
2892
-
2893
- const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
2894
- /**
2895
- * Similar to _.throttle but waits for the promise to resolve. There is no
2896
- * wait time because you can simply await `Promise.timeout` inside `fn`
2897
- * to wait some time before the next call.
2898
- */
2899
-
2900
-
2901
- function asyncThrottle(fn) {
2902
- let runningPromise;
2903
- let queuedPromise;
2904
- let nextArgs;
2905
- return args => __awaiter(this, void 0, void 0, function* () {
2906
- if (runningPromise) {
2907
- nextArgs = args;
2908
-
2909
- if (queuedPromise) {
2910
- return queuedPromise;
2911
- } else {
2912
- queuedPromise = runningPromise.then(() => {
2913
- queuedPromise = undefined;
2914
- runningPromise = fn(nextArgs);
2915
- return runningPromise;
2916
- });
2917
- return queuedPromise;
2918
- }
2919
- } else {
2920
- runningPromise = fn(args);
2921
- return runningPromise;
2922
- }
2923
- });
2924
- }
2925
- const ninetailedPlugin = ({
2926
- clientId,
2927
- environment,
2928
- preview: _preview = false,
2929
- url,
2930
- profile,
2931
- locale
2932
- }) => {
2933
- let isInitialized = false;
2934
- const apiClient = new NinetailedApiClient({
2935
- clientId,
2936
- environment,
2937
- url
2938
- });
2939
- let queue = [];
2940
- let localOnly = false;
2941
-
2942
- const flush = instance => __awaiter(void 0, void 0, void 0, function* () {
2943
- const events = Object.assign([], queue);
2944
- logger.info('Start flushing events.');
2945
- queue = [];
2946
-
2947
- if (!events.length) {
2948
- return;
2949
- }
2950
-
2951
- const cache = get({
2952
- instance
2953
- });
2954
-
2955
- try {
2956
- logger.debug('Cache: ', cache);
2957
- const {
2958
- profile,
2959
- signals,
2960
- traitsUpdatedAt,
2961
- sessions
2962
- } = yield apiClient.profile({
2963
- events,
2964
- signals: get$2(cache, 'signals', {}),
2965
- traits: get$2(cache, 'traits', {}),
2966
- traitsUpdatedAt: get$2(cache, 'traitsUpdatedAt', new Date().toISOString()),
2967
- localOnly,
2968
- preview: _preview,
2969
- options: {
2970
- locale: locale || 'en'
2971
- },
2972
- sessions: get$2(cache, 'sessions', [])
2973
- });
2974
- logger.debug('Profile from api: ', profile);
2975
- const updatedCache = set({
2976
- id: profile.id,
2977
- random: profile.random,
2978
- audiences: profile.audiences,
2979
- traits: profile.traits,
2980
- location: profile.location,
2981
- signals,
2982
- traitsUpdatedAt,
2983
- sessions,
2984
- session: profile.session
2985
- }, {
2986
- instance
2987
- });
2988
- instance.dispatch({
2989
- type: NINETAILED_TRACKER_EVENTS.profile,
2990
- profile,
2991
- cache: updatedCache
2992
- });
2993
- } catch (error) {
2994
- logger.debug('An error occurred during flushing the events: ', error);
2995
- instance.dispatch({
2996
- type: NINETAILED_TRACKER_EVENTS.profile,
2997
- profile: {
2998
- id: cache.id,
2999
- random: cache.random,
3000
- audiences: cache.audiences,
3001
- traits: cache.traits,
3002
- location: cache.location,
3003
- session: cache.session
3004
- },
3005
- cache
3006
- });
3007
- } // This is necessary to make sure that the cache is updated before the next flush is performed
3008
-
3009
-
3010
- yield delay(20);
3011
- }); // const throttledFlush = throttle(flush, 200, {
3012
- // leading: false,
3013
- // trailing: true,
3014
- // });
3015
-
3016
-
3017
- const throttledFlush = asyncThrottle(flush);
3018
-
3019
- const createEvent = (event, instance) => __awaiter(void 0, void 0, void 0, function* () {
3020
- queue = unionBy([event], queue, 'messageId');
3021
- throttledFlush(instance);
3022
- });
3023
-
3024
- return {
3025
- name: 'ninetailed',
3026
- config: {},
3027
- initialize: ({
3028
- instance
3029
- }) => {
3030
- if (instance.storage.getItem(DEBUG_FLAG_KEY)) {
3031
- logger.addSink(new ConsoleLogSink());
3032
- logger.info('Ninetailed Debug Mode is enabled.');
3033
- }
3034
-
3035
- const cache = get({
3036
- instance
3037
- });
3038
-
3039
- if (profile) {
3040
- instance.storage.setItem('__anon_id', profile.id);
3041
- initialize({
3042
- instance
3043
- }, Object.assign(Object.assign({}, cache), {
3044
- id: profile.id
3045
- }));
3046
- } else {
3047
- const anonymousId = instance.storage.getItem('__anon_id');
3048
- initialize({
3049
- instance
3050
- }, Object.assign(Object.assign({}, cache), {
3051
- id: anonymousId
3052
- }));
3053
- }
3054
-
3055
- isInitialized = true;
3056
- logger.debug('Ninetailed Core plugin initialized.');
3057
- },
3058
- page: ({
3059
- payload,
3060
- instance
3061
- }) => __awaiter(void 0, void 0, void 0, function* () {
3062
- logger.info('Sending Page event.');
3063
- const ctx = buildClientNinetailedRequestContext();
3064
- localOnly = payload.localOnly;
3065
- yield createEvent(buildPageEvent({
3066
- // doing this here as the anonymous id is set to late from init
3067
- anonymousId: (profile === null || profile === void 0 ? void 0 : profile.id) || payload.anonymousId,
3068
- messageId: payload.meta.rid,
3069
- timestamp: payload.meta.ts,
3070
- properties: payload.properties,
3071
- ctx
3072
- }), instance);
3073
- }),
3074
- track: ({
3075
- payload,
3076
- instance
3077
- }) => __awaiter(void 0, void 0, void 0, function* () {
3078
- logger.info('Sending Track event.');
3079
- const ctx = buildClientNinetailedRequestContext();
3080
- localOnly = payload.localOnly;
3081
- yield createEvent(buildTrackEvent({
3082
- // doing this here as the anonymous id is set to late from init
3083
- anonymousId: (profile === null || profile === void 0 ? void 0 : profile.id) || payload.anonymousId,
3084
- messageId: payload.meta.rid,
3085
- timestamp: payload.meta.ts,
3086
- event: payload.event,
3087
- properties: payload.properties,
3088
- ctx
3089
- }), instance);
3090
- }),
3091
- identify: ({
3092
- payload,
3093
- instance
3094
- }) => __awaiter(void 0, void 0, void 0, function* () {
3095
- logger.info('Sending Identify event.');
3096
- localOnly = payload.localOnly;
3097
- const ctx = buildClientNinetailedRequestContext();
3098
- yield createEvent(buildIdentifyEvent({
3099
- // doing this here as the anonymous id is set to late from init
3100
- anonymousId: (profile === null || profile === void 0 ? void 0 : profile.id) || payload.anonymousId,
3101
- messageId: payload.meta.rid,
3102
- timestamp: payload.meta.ts,
3103
- traits: payload.traits,
3104
- userId: payload.userId,
3105
- ctx
3106
- }), instance);
3107
- }),
3108
- loaded: () => {
3109
- return isInitialized;
3110
- },
3111
- methods: {
3112
- reset: (...args) => __awaiter(void 0, void 0, void 0, function* () {
3113
- const instance = args[args.length - 1];
3114
- const cache = reset({
3115
- instance
3116
- });
3117
- yield instance.storage.setItem('__anon_id', cache.id);
3118
- instance.dispatch({
3119
- type: NINETAILED_TRACKER_EVENTS.profile,
3120
- profile: {
3121
- id: cache.id,
3122
- random: 0,
3123
- audiences: [],
3124
- traits: {},
3125
- location: {}
3126
- },
3127
- cache: cache
3128
- });
3129
- yield delay(10);
3130
- }),
3131
- debug: (...args) => __awaiter(void 0, void 0, void 0, function* () {
3132
- const enabled = args[0];
3133
- const instance = args[args.length - 1];
3134
- const consoleLogSink = new ConsoleLogSink();
3135
-
3136
- if (enabled) {
3137
- yield instance.storage.setItem(DEBUG_FLAG_KEY, true); // cleanup other console log sinks if there are already some.
3138
-
3139
- logger.removeSink(consoleLogSink.name);
3140
- logger.addSink(consoleLogSink);
3141
- logger.info('Debug mode enabled.');
3142
- } else {
3143
- yield instance.storage.removeItem(DEBUG_FLAG_KEY);
3144
- logger.info('Debug mode disabled.');
3145
- logger.removeSink(consoleLogSink.name);
3146
- }
3147
- })
3148
- }
3149
- };
3150
- };
3151
-
3152
2940
  class Ninetailed {
3153
2941
  constructor({
3154
2942
  clientId,
@@ -3195,18 +2983,26 @@ class Ninetailed {
3195
2983
 
3196
2984
  this.identify = (uid, traits, options) => __awaiter(this, void 0, void 0, function* () {
3197
2985
  yield this.waitUntilInitialized();
2986
+ /*console.log("Identify triggered");*/
2987
+
3198
2988
  return this.instance.identify(uid, traits, this.buildOptions(options));
3199
2989
  });
3200
2990
 
3201
- this.reset = () => __awaiter(this, void 0, void 0, function* () {
3202
- yield this.waitUntilInitialized();
3203
- this.instance.plugins[PLUGIN_NAME].reset();
3204
- });
2991
+ this.reset = () => {
2992
+ this.onIsInitialized(() => {
2993
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2994
+ // @ts-ignore
2995
+ this.instance.plugins[PLUGIN_NAME].reset();
2996
+ });
2997
+ };
3205
2998
 
3206
- this.debug = enabled => __awaiter(this, void 0, void 0, function* () {
3207
- yield this.waitUntilInitialized();
3208
- this.instance.plugins[PLUGIN_NAME].debug(enabled);
3209
- });
2999
+ this.debug = enabled => {
3000
+ this.onIsInitialized(() => {
3001
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3002
+ // @ts-ignore
3003
+ this.instance.plugins[PLUGIN_NAME].debug(enabled);
3004
+ });
3005
+ };
3210
3006
 
3211
3007
  this.onProfileChange = cb => {
3212
3008
  cb(this.profileState);
@@ -3216,7 +3012,7 @@ class Ninetailed {
3216
3012
  cb(Object.assign(Object.assign({}, this._profileState), {
3217
3013
  status: 'success',
3218
3014
  profile: payload.profile,
3219
- error: undefined
3015
+ error: null
3220
3016
  }));
3221
3017
  });
3222
3018
  };
@@ -3227,7 +3023,6 @@ class Ninetailed {
3227
3023
  onIsInitialized();
3228
3024
  } else {
3229
3025
  const detachOnReadyListener = this.instance.on('ready', () => {
3230
- this.isInitialized = true;
3231
3026
  onIsInitialized();
3232
3027
  detachOnReadyListener();
3233
3028
  });
@@ -3247,14 +3042,14 @@ class Ninetailed {
3247
3042
  this._profileState = {
3248
3043
  status: 'success',
3249
3044
  profile,
3250
- error: undefined,
3045
+ error: null,
3251
3046
  from: 'hydrated'
3252
3047
  };
3253
3048
  } else {
3254
3049
  this._profileState = {
3255
3050
  status: 'loading',
3256
3051
  profile: null,
3257
- error: undefined,
3052
+ error: null,
3258
3053
  from: 'api'
3259
3054
  };
3260
3055
  }
@@ -3280,8 +3075,10 @@ class Ninetailed {
3280
3075
  preview
3281
3076
  })]
3282
3077
  });
3283
- this.onIsInitialized(() => {
3078
+ const detachOnReadyListener = this.instance.on('ready', () => {
3079
+ this.isInitialized = true;
3284
3080
  logger.info('Ninetailed Experience.js SDK is completely initialized.');
3081
+ detachOnReadyListener();
3285
3082
  }); // put in private method
3286
3083
 
3287
3084
  this.onProfileChange(profileState => {
@@ -3323,12 +3120,12 @@ const selectVariant$1 = (baseline, variants, {
3323
3120
  if (status === 'loading') {
3324
3121
  return {
3325
3122
  loading: true,
3326
- variant: Object.assign({
3123
+ variant: Object.assign(Object.assign({}, baseline), {
3327
3124
  id: 'baseline',
3328
3125
  audience: {
3329
3126
  id: 'baseline'
3330
3127
  }
3331
- }, baseline),
3128
+ }),
3332
3129
  audience: {
3333
3130
  id: 'baseline'
3334
3131
  },
@@ -3340,12 +3137,12 @@ const selectVariant$1 = (baseline, variants, {
3340
3137
  if (status === 'error') {
3341
3138
  return {
3342
3139
  loading: false,
3343
- variant: Object.assign({
3140
+ variant: Object.assign(Object.assign({}, baseline), {
3344
3141
  id: 'baseline',
3345
3142
  audience: {
3346
3143
  id: 'baseline'
3347
3144
  }
3348
- }, baseline),
3145
+ }),
3349
3146
  audience: {
3350
3147
  id: 'baseline'
3351
3148
  },
@@ -3361,15 +3158,16 @@ const selectVariant$1 = (baseline, variants, {
3361
3158
  });
3362
3159
 
3363
3160
  if (variant) {
3364
- if (options.holdout > profile.random) {
3161
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3162
+ // @ts-ignore
3163
+ if ((options === null || options === void 0 ? void 0 : options.holdout) || -1 > (profile === null || profile === void 0 ? void 0 : profile.random)) {
3365
3164
  return {
3366
3165
  loading: false,
3367
- variant: Object.assign({
3368
- id: baseline.id,
3166
+ variant: Object.assign(Object.assign({}, baseline), {
3369
3167
  audience: {
3370
3168
  id: 'baseline'
3371
3169
  }
3372
- }, baseline),
3170
+ }),
3373
3171
  audience: Object.assign(Object.assign({}, variant.audience), {
3374
3172
  id: variant.audience.id
3375
3173
  }),
@@ -3395,12 +3193,12 @@ const selectVariant$1 = (baseline, variants, {
3395
3193
 
3396
3194
  return {
3397
3195
  loading: false,
3398
- variant: Object.assign({
3196
+ variant: Object.assign(Object.assign({}, baseline), {
3399
3197
  id: 'baseline',
3400
3198
  audience: {
3401
3199
  id: 'baseline'
3402
3200
  }
3403
- }, baseline),
3201
+ }),
3404
3202
  audience: {
3405
3203
  id: 'baseline'
3406
3204
  },
@@ -3412,7 +3210,9 @@ const selectVariant$1 = (baseline, variants, {
3412
3210
  const EXPERIENCE_TRAIT_PREFIX = 'nt_experiment_';
3413
3211
 
3414
3212
  const selectBaselineWithVariants = (experience, baseline) => {
3415
- return experience.components.find(baselineWithVariants => baselineWithVariants.baseline.id === baseline.id);
3213
+ var _a;
3214
+
3215
+ return (_a = experience.components.find(baselineWithVariants => baselineWithVariants.baseline.id === baseline.id)) !== null && _a !== void 0 ? _a : null;
3416
3216
  };
3417
3217
 
3418
3218
  const selectVariants = (experience, baseline) => {
@@ -3430,63 +3230,13 @@ const selectHasVariants = (experience, baseline) => {
3430
3230
  return variants.length > 0;
3431
3231
  };
3432
3232
 
3433
- var global$9 = global$K;
3434
- var classof$2 = classof$6;
3435
-
3436
- var String$1 = global$9.String;
3437
-
3438
- var toString$7 = function (argument) {
3439
- if (classof$2(argument) === 'Symbol') throw TypeError('Cannot convert a Symbol value to a string');
3440
- return String$1(argument);
3441
- };
3442
-
3443
- var isObject = isObject$8;
3444
- var classof$1 = classofRaw$1;
3445
- var wellKnownSymbol$3 = wellKnownSymbol$i;
3446
-
3447
- var MATCH$1 = wellKnownSymbol$3('match');
3448
-
3449
- // `IsRegExp` abstract operation
3450
- // https://tc39.es/ecma262/#sec-isregexp
3451
- var isRegexp = function (it) {
3452
- var isRegExp;
3453
- return isObject(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classof$1(it) == 'RegExp');
3454
- };
3455
-
3456
- var global$8 = global$K;
3457
- var isRegExp$1 = isRegexp;
3458
-
3459
- var TypeError$3 = global$8.TypeError;
3460
-
3461
- var notARegexp = function (it) {
3462
- if (isRegExp$1(it)) {
3463
- throw TypeError$3("The method doesn't accept regular expressions");
3464
- } return it;
3465
- };
3466
-
3467
- var wellKnownSymbol$2 = wellKnownSymbol$i;
3468
-
3469
- var MATCH = wellKnownSymbol$2('match');
3470
-
3471
- var correctIsRegexpLogic = function (METHOD_NAME) {
3472
- var regexp = /./;
3473
- try {
3474
- '/./'[METHOD_NAME](regexp);
3475
- } catch (error1) {
3476
- try {
3477
- regexp[MATCH] = false;
3478
- return '/./'[METHOD_NAME](regexp);
3479
- } catch (error2) { /* empty */ }
3480
- } return false;
3481
- };
3482
-
3483
3233
  var $$3 = _export;
3484
3234
  var uncurryThis$8 = functionUncurryThis;
3485
3235
  var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
3486
3236
  var toLength$2 = toLength$4;
3487
- var toString$6 = toString$7;
3237
+ var toString$6 = toString$8;
3488
3238
  var notARegExp = notARegexp;
3489
- var requireObjectCoercible$4 = requireObjectCoercible$7;
3239
+ var requireObjectCoercible$4 = requireObjectCoercible$8;
3490
3240
  var correctIsRegExpLogic = correctIsRegexpLogic;
3491
3241
 
3492
3242
  // eslint-disable-next-line es/no-string-prototype-startswith -- safe
@@ -3589,7 +3339,7 @@ var regexpUnsupportedNcg = fails$5(function () {
3589
3339
  /* eslint-disable regexp/no-useless-quantifier -- testing */
3590
3340
  var call$3 = functionCall;
3591
3341
  var uncurryThis$7 = functionUncurryThis;
3592
- var toString$5 = toString$7;
3342
+ var toString$5 = toString$8;
3593
3343
  var regexpFlags = regexpFlags$1;
3594
3344
  var stickyHelpers$1 = regexpStickyHelpers;
3595
3345
  var shared = shared$4.exports;
@@ -3787,8 +3537,8 @@ var fixRegexpWellKnownSymbolLogic = function (KEY, exec, FORCED, SHAM) {
3787
3537
 
3788
3538
  var uncurryThis$5 = functionUncurryThis;
3789
3539
  var toIntegerOrInfinity$1 = toIntegerOrInfinity$4;
3790
- var toString$4 = toString$7;
3791
- var requireObjectCoercible$3 = requireObjectCoercible$7;
3540
+ var toString$4 = toString$8;
3541
+ var requireObjectCoercible$3 = requireObjectCoercible$8;
3792
3542
 
3793
3543
  var charAt$2 = uncurryThis$5(''.charAt);
3794
3544
  var charCodeAt = uncurryThis$5(''.charCodeAt);
@@ -3906,8 +3656,8 @@ var anObject$1 = anObject$e;
3906
3656
  var isCallable = isCallable$j;
3907
3657
  var toIntegerOrInfinity = toIntegerOrInfinity$4;
3908
3658
  var toLength$1 = toLength$4;
3909
- var toString$3 = toString$7;
3910
- var requireObjectCoercible$2 = requireObjectCoercible$7;
3659
+ var toString$3 = toString$8;
3660
+ var requireObjectCoercible$2 = requireObjectCoercible$8;
3911
3661
  var advanceStringIndex$1 = advanceStringIndex$2;
3912
3662
  var getMethod$1 = getMethod$5;
3913
3663
  var getSubstitution = getSubstitution$1;
@@ -4103,7 +3853,7 @@ const selectExperience = ({
4103
3853
  activeExperiments,
4104
3854
  profile
4105
3855
  }));
4106
- return selectedExperience;
3856
+ return selectedExperience !== null && selectedExperience !== void 0 ? selectedExperience : null;
4107
3857
  };
4108
3858
 
4109
3859
  const selectDistribution = ({
@@ -4117,6 +3867,16 @@ const selectDistribution = ({
4117
3867
  end
4118
3868
  }) => distributionRandom >= start && distributionRandom <= end // this overlaps on one value for each boundary but we just find the first match
4119
3869
  );
3870
+
3871
+ if (!distribution) {
3872
+ // This should never happen. If it happens then the distribution is not configured correctly. So we just return the baseline.
3873
+ return {
3874
+ index: 0,
3875
+ start: 0,
3876
+ end: 1
3877
+ };
3878
+ }
3879
+
4120
3880
  return distribution;
4121
3881
  };
4122
3882
 
@@ -4271,11 +4031,11 @@ var uncurryThis$2 = functionUncurryThis;
4271
4031
  var fixRegExpWellKnownSymbolLogic = fixRegexpWellKnownSymbolLogic;
4272
4032
  var isRegExp = isRegexp;
4273
4033
  var anObject = anObject$e;
4274
- var requireObjectCoercible$1 = requireObjectCoercible$7;
4034
+ var requireObjectCoercible$1 = requireObjectCoercible$8;
4275
4035
  var speciesConstructor = speciesConstructor$2;
4276
4036
  var advanceStringIndex = advanceStringIndex$2;
4277
4037
  var toLength = toLength$4;
4278
- var toString$2 = toString$7;
4038
+ var toString$2 = toString$8;
4279
4039
  var getMethod = getMethod$5;
4280
4040
  var arraySlice = arraySliceSimple;
4281
4041
  var callRegExpExec = regexpExecAbstract;
@@ -4426,8 +4186,8 @@ var whitespaces$2 = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u200
4426
4186
  '\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
4427
4187
 
4428
4188
  var uncurryThis$1 = functionUncurryThis;
4429
- var requireObjectCoercible = requireObjectCoercible$7;
4430
- var toString$1 = toString$7;
4189
+ var requireObjectCoercible = requireObjectCoercible$8;
4190
+ var toString$1 = toString$8;
4431
4191
  var whitespaces$1 = whitespaces$2;
4432
4192
 
4433
4193
  var replace = uncurryThis$1(''.replace);
@@ -4460,7 +4220,7 @@ var stringTrim = {
4460
4220
  var global$1 = global$K;
4461
4221
  var fails = fails$k;
4462
4222
  var uncurryThis = functionUncurryThis;
4463
- var toString = toString$7;
4223
+ var toString = toString$8;
4464
4224
  var trim = stringTrim.trim;
4465
4225
  var whitespaces = whitespaces$2;
4466
4226
 
@@ -4502,9 +4262,9 @@ const decodeExperienceVariantsMap = encodedExperienceVariantsMap => {
4502
4262
  experienceId,
4503
4263
  variantIndex
4504
4264
  };
4505
- }).filter(x => x).reduce((acc, curr) => Object.assign(Object.assign({}, acc), {
4265
+ }).filter(x => !!x).reduce((acc, curr) => Object.assign(Object.assign({}, acc), {
4506
4266
  [curr.experienceId]: curr.variantIndex
4507
4267
  }), {});
4508
4268
  };
4509
4269
 
4510
- export { index as Cache, EXPERIENCE_TRAIT_PREFIX, NINETAILED_TRACKER_EVENTS, Ninetailed, PLUGIN_NAME, decodeExperienceVariantsMap, isExperienceMatch, logger, ninetailedPlugin, selectActiveExperiments, selectDistribution, selectEligibleExperiences, selectExperience, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectVariant as selectExperienceVariant, selectVariants as selectExperienceVariants, selectHasVariants as selectHasExperienceVariants, selectVariant$1 as selectVariant };
4270
+ export { ANONYMOUS_ID, DEBUG_FLAG, EXPERIENCE_TRAIT_PREFIX, LEGACY_ANONYMOUS_ID, NINETAILED_TRACKER_EVENTS, Ninetailed, PLUGIN_NAME, PROFILE_FALLBACK_CACHE, decodeExperienceVariantsMap, isExperienceMatch, ninetailedPlugin, selectActiveExperiments, selectDistribution, selectEligibleExperiences, selectExperience, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectVariant as selectExperienceVariant, selectVariants as selectExperienceVariants, selectHasVariants as selectHasExperienceVariants, selectVariant$1 as selectVariant };