@ninetailed/experience.js 2.2.11 → 3.0.0-beta.13

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,158 +2263,328 @@ 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 = {};
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__';
2303
2301
 
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;
2302
+ const NINETAILED_TRACKER_EVENTS = {
2303
+ /**
2304
+ * `profile` - Fires when the profile is returned by the cdp API.
2305
+ */
2306
+ profile: 'profile',
2310
2307
 
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;
2308
+ /**
2309
+ * `reset` - gets fired when the profile gets reset, so other plugins can react.
2310
+ */
2311
+ reset: 'reset'
2323
2312
  };
2313
+ const PLUGIN_NAME = 'ninetailed';
2324
2314
 
2325
- /* global ActiveXObject -- old IE, WSH */
2315
+ const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
2326
2316
 
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;
2317
+ const ninetailedPlugin = ({
2318
+ clientId,
2319
+ environment,
2320
+ preview: _preview = false,
2321
+ url,
2322
+ profile,
2323
+ locale
2324
+ }) => {
2325
+ const apiClient = new NinetailedApiClient({
2326
+ clientId,
2327
+ environment,
2328
+ url
2329
+ });
2330
+ let queue = [];
2334
2331
 
2335
- var GT = '>';
2336
- var LT = '<';
2337
- var PROTOTYPE = 'prototype';
2338
- var SCRIPT = 'script';
2339
- var IE_PROTO$1 = sharedKey$1('IE_PROTO');
2332
+ const flush = instance => __awaiter(void 0, void 0, void 0, function* () {
2333
+ const events = Object.assign([], queue);
2334
+ logger.info('Start flushing events.');
2335
+ queue = [];
2340
2336
 
2341
- var EmptyConstructor = function () { /* empty */ };
2337
+ if (!events.length) {
2338
+ return;
2339
+ }
2342
2340
 
2343
- var scriptTag = function (content) {
2344
- return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
2345
- };
2341
+ try {
2342
+ const anonymousId = instance.storage.getItem(ANONYMOUS_ID);
2343
+ const profile = yield apiClient.upsertProfile({
2344
+ profileId: anonymousId,
2345
+ events
2346
+ }, {
2347
+ locale
2348
+ });
2349
+ instance.storage.setItem(ANONYMOUS_ID, profile.id);
2350
+ instance.storage.setItem(PROFILE_FALLBACK_CACHE, profile);
2351
+ logger.debug('Profile from api: ', profile);
2352
+ instance.dispatch({
2353
+ type: NINETAILED_TRACKER_EVENTS.profile,
2354
+ profile
2355
+ });
2356
+ } catch (error) {
2357
+ logger.debug('An error occurred during flushing the events: ', error);
2358
+ const fallbackProfile = instance.storage.getItem(PROFILE_FALLBACK_CACHE);
2346
2359
 
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
- };
2360
+ if (fallbackProfile) {
2361
+ logger.debug('Found a fallback profile - will use this.');
2362
+ instance.dispatch({
2363
+ type: NINETAILED_TRACKER_EVENTS.profile,
2364
+ profile: fallbackProfile
2365
+ });
2366
+ } else {
2367
+ logger.debug('No fallback profile found - setting profile to null.');
2368
+ instance.dispatch({
2369
+ type: NINETAILED_TRACKER_EVENTS.profile,
2370
+ profile: null,
2371
+ error
2372
+ });
2373
+ }
2374
+ } // This is necessary to make sure that the cache is updated before the next flush is performed
2355
2375
 
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
- };
2372
2376
 
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();
2377
+ yield delay(20);
2378
+ });
2379
+
2380
+ const throttledFlush = asyncThrottle(flush);
2381
+
2382
+ const enqueueEvent = (event, instance) => __awaiter(void 0, void 0, void 0, function* () {
2383
+ queue = unionBy([event], queue, 'messageId');
2384
+ throttledFlush(instance);
2385
+ });
2386
+
2387
+ return {
2388
+ name: 'ninetailed',
2389
+ config: {},
2390
+ initialize: ({
2391
+ instance
2392
+ }) => {
2393
+ if (instance.storage.getItem(DEBUG_FLAG)) {
2394
+ logger.addSink(new ConsoleLogSink());
2395
+ logger.info('Ninetailed Debug Mode is enabled.');
2396
+ } // legacy support for the old anonymousId
2397
+
2398
+
2399
+ const legacyAnonymousId = instance.storage.getItem(LEGACY_ANONYMOUS_ID);
2400
+
2401
+ if (legacyAnonymousId) {
2402
+ logger.debug('Found legacy anonymousId, migrating to new one.', legacyAnonymousId);
2403
+ instance.storage.setItem(ANONYMOUS_ID, legacyAnonymousId);
2404
+ instance.storage.removeItem(LEGACY_ANONYMOUS_ID);
2405
+ }
2406
+
2407
+ if (profile) {
2408
+ instance.storage.setItem(ANONYMOUS_ID, profile.id);
2409
+ }
2410
+
2411
+ logger.debug('Ninetailed Core plugin initialized.');
2412
+ },
2413
+ page: ({
2414
+ payload,
2415
+ instance
2416
+ }) => __awaiter(void 0, void 0, void 0, function* () {
2417
+ logger.info('Sending Page event.');
2418
+ const ctx = buildClientNinetailedRequestContext();
2419
+ yield enqueueEvent(buildPageEvent({
2420
+ messageId: payload.meta.rid,
2421
+ timestamp: payload.meta.ts,
2422
+ properties: payload.properties,
2423
+ ctx
2424
+ }), instance);
2425
+ }),
2426
+ track: ({
2427
+ payload,
2428
+ instance
2429
+ }) => __awaiter(void 0, void 0, void 0, function* () {
2430
+ logger.info('Sending Track event.');
2431
+ const ctx = buildClientNinetailedRequestContext();
2432
+ yield enqueueEvent(buildTrackEvent({
2433
+ messageId: payload.meta.rid,
2434
+ timestamp: payload.meta.ts,
2435
+ event: payload.event,
2436
+ properties: payload.properties,
2437
+ ctx
2438
+ }), instance);
2439
+ }),
2440
+ identify: ({
2441
+ payload,
2442
+ instance
2443
+ }) => __awaiter(void 0, void 0, void 0, function* () {
2444
+ logger.info('Sending Identify event.');
2445
+ const ctx = buildClientNinetailedRequestContext();
2446
+ yield enqueueEvent(buildIdentifyEvent({
2447
+ // doing this here as the anonymous id is set to late from init
2448
+ messageId: payload.meta.rid,
2449
+ timestamp: payload.meta.ts,
2450
+ traits: payload.traits,
2451
+ userId: payload.userId,
2452
+ ctx
2453
+ }), instance);
2454
+ }),
2455
+ setItemStart: ({
2456
+ abort,
2457
+ payload
2458
+ }) => {
2459
+ if (![ANONYMOUS_ID, DEBUG_FLAG, PROFILE_FALLBACK_CACHE].includes(payload.key)) {
2460
+ return abort();
2461
+ }
2462
+
2463
+ return payload;
2464
+ },
2465
+ methods: {
2466
+ reset: (...args) => __awaiter(void 0, void 0, void 0, function* () {
2467
+ logger.debug('Resetting profile.');
2468
+ const instance = args[args.length - 1];
2469
+ instance.dispatch({
2470
+ type: NINETAILED_TRACKER_EVENTS.reset
2471
+ });
2472
+ yield instance.storage.removeItem(ANONYMOUS_ID);
2473
+ yield instance.storage.removeItem(PROFILE_FALLBACK_CACHE);
2474
+ logger.debug('Removed old profile data from localstorage.'); // sending a new page event, when no anonymousId is set will create a new profile.
2475
+
2476
+ yield instance.page();
2477
+ logger.info('Profile reset successful.');
2478
+ yield delay(10);
2479
+ }),
2480
+ debug: (...args) => __awaiter(void 0, void 0, void 0, function* () {
2481
+ const enabled = args[0];
2482
+ const instance = args[args.length - 1];
2483
+ const consoleLogSink = new ConsoleLogSink();
2484
+
2485
+ if (enabled) {
2486
+ yield instance.storage.setItem(DEBUG_FLAG, true);
2487
+ logger.addSink(consoleLogSink);
2488
+ logger.info('Debug mode enabled.');
2489
+ } else {
2490
+ yield instance.storage.removeItem(DEBUG_FLAG);
2491
+ logger.info('Debug mode disabled.');
2492
+ logger.removeSink(consoleLogSink.name);
2493
+ }
2494
+ })
2495
+ }
2496
+ };
2497
+ };
2498
+
2499
+ var objectDefineProperties = {};
2500
+
2501
+ var DESCRIPTORS$1 = descriptors;
2502
+ var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug;
2503
+ var definePropertyModule$2 = objectDefineProperty;
2504
+ var anObject$5 = anObject$e;
2505
+ var toIndexedObject$1 = toIndexedObject$5;
2506
+ var objectKeys = objectKeys$2;
2507
+
2508
+ // `Object.defineProperties` method
2509
+ // https://tc39.es/ecma262/#sec-object.defineproperties
2510
+ // eslint-disable-next-line es/no-object-defineproperties -- safe
2511
+ objectDefineProperties.f = DESCRIPTORS$1 && !V8_PROTOTYPE_DEFINE_BUG ? Object.defineProperties : function defineProperties(O, Properties) {
2512
+ anObject$5(O);
2513
+ var props = toIndexedObject$1(Properties);
2514
+ var keys = objectKeys(Properties);
2515
+ var length = keys.length;
2516
+ var index = 0;
2517
+ var key;
2518
+ while (length > index) definePropertyModule$2.f(O, key = keys[index++], props[key]);
2519
+ return O;
2520
+ };
2521
+
2522
+ /* global ActiveXObject -- old IE, WSH */
2523
+
2524
+ var anObject$4 = anObject$e;
2525
+ var definePropertiesModule = objectDefineProperties;
2526
+ var enumBugKeys = enumBugKeys$3;
2527
+ var hiddenKeys = hiddenKeys$4;
2528
+ var html = html$2;
2529
+ var documentCreateElement$1 = documentCreateElement$2;
2530
+ var sharedKey$1 = sharedKey$3;
2531
+
2532
+ var GT = '>';
2533
+ var LT = '<';
2534
+ var PROTOTYPE = 'prototype';
2535
+ var SCRIPT = 'script';
2536
+ var IE_PROTO$1 = sharedKey$1('IE_PROTO');
2537
+
2538
+ var EmptyConstructor = function () { /* empty */ };
2539
+
2540
+ var scriptTag = function (content) {
2541
+ return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
2542
+ };
2543
+
2544
+ // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
2545
+ var NullProtoObjectViaActiveX = function (activeXDocument) {
2546
+ activeXDocument.write(scriptTag(''));
2547
+ activeXDocument.close();
2548
+ var temp = activeXDocument.parentWindow.Object;
2549
+ activeXDocument = null; // avoid memory leak
2550
+ return temp;
2551
+ };
2552
+
2553
+ // Create object with fake `null` prototype: use iframe Object with cleared prototype
2554
+ var NullProtoObjectViaIFrame = function () {
2555
+ // Thrash, waste and sodomy: IE GC bug
2556
+ var iframe = documentCreateElement$1('iframe');
2557
+ var JS = 'java' + SCRIPT + ':';
2558
+ var iframeDocument;
2559
+ iframe.style.display = 'none';
2560
+ html.appendChild(iframe);
2561
+ // https://github.com/zloirock/core-js/issues/475
2562
+ iframe.src = String(JS);
2563
+ iframeDocument = iframe.contentWindow.document;
2564
+ iframeDocument.open();
2565
+ iframeDocument.write(scriptTag('document.F=Object'));
2566
+ iframeDocument.close();
2567
+ return iframeDocument.F;
2568
+ };
2569
+
2570
+ // Check for document.domain and active x support
2571
+ // No need to use active x approach when document.domain is not set
2572
+ // see https://github.com/es-shims/es5-shim/issues/150
2573
+ // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
2574
+ // avoid IE GC bug
2575
+ var activeXDocument;
2576
+ var NullProtoObject = function () {
2577
+ try {
2578
+ activeXDocument = new ActiveXObject('htmlfile');
2579
+ } catch (error) { /* ignore */ }
2580
+ NullProtoObject = typeof document != 'undefined'
2581
+ ? document.domain && activeXDocument
2582
+ ? NullProtoObjectViaActiveX(activeXDocument) // old IE
2583
+ : NullProtoObjectViaIFrame()
2584
+ : NullProtoObjectViaActiveX(activeXDocument); // WSH
2585
+ var length = enumBugKeys.length;
2586
+ while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
2587
+ return NullProtoObject();
2391
2588
  };
2392
2589
 
2393
2590
  hiddenKeys[IE_PROTO$1] = true;
@@ -2406,11 +2603,11 @@ var objectCreate = Object.create || function create(O, Properties) {
2406
2603
  return Properties === undefined ? result : definePropertiesModule.f(result, Properties);
2407
2604
  };
2408
2605
 
2409
- var wellKnownSymbol$7 = wellKnownSymbol$i;
2606
+ var wellKnownSymbol$5 = wellKnownSymbol$i;
2410
2607
  var create$2 = objectCreate;
2411
2608
  var definePropertyModule$1 = objectDefineProperty;
2412
2609
 
2413
- var UNSCOPABLES = wellKnownSymbol$7('unscopables');
2610
+ var UNSCOPABLES = wellKnownSymbol$5('unscopables');
2414
2611
  var ArrayPrototype = Array.prototype;
2415
2612
 
2416
2613
  // Array.prototype[@@unscopables]
@@ -2436,7 +2633,7 @@ var correctPrototypeGetter = !fails$9(function () {
2436
2633
  return Object.getPrototypeOf(new F()) !== F.prototype;
2437
2634
  });
2438
2635
 
2439
- var global$b = global$K;
2636
+ var global$9 = global$K;
2440
2637
  var hasOwn = hasOwnProperty_1;
2441
2638
  var isCallable$4 = isCallable$j;
2442
2639
  var toObject$2 = toObject$5;
@@ -2444,7 +2641,7 @@ var sharedKey = sharedKey$3;
2444
2641
  var CORRECT_PROTOTYPE_GETTER = correctPrototypeGetter;
2445
2642
 
2446
2643
  var IE_PROTO = sharedKey('IE_PROTO');
2447
- var Object$1 = global$b.Object;
2644
+ var Object$1 = global$9.Object;
2448
2645
  var ObjectPrototype = Object$1.prototype;
2449
2646
 
2450
2647
  // `Object.getPrototypeOf` method
@@ -2462,9 +2659,9 @@ var fails$8 = fails$k;
2462
2659
  var isCallable$3 = isCallable$j;
2463
2660
  var getPrototypeOf$1 = objectGetPrototypeOf;
2464
2661
  var redefine$2 = redefine$6.exports;
2465
- var wellKnownSymbol$6 = wellKnownSymbol$i;
2662
+ var wellKnownSymbol$4 = wellKnownSymbol$i;
2466
2663
 
2467
- var ITERATOR$3 = wellKnownSymbol$6('iterator');
2664
+ var ITERATOR$3 = wellKnownSymbol$4('iterator');
2468
2665
  var BUGGY_SAFARI_ITERATORS$1 = false;
2469
2666
 
2470
2667
  // `%IteratorPrototype%` object
@@ -2529,7 +2726,7 @@ var setPrototypeOf = objectSetPrototypeOf;
2529
2726
  var setToStringTag = setToStringTag$3;
2530
2727
  var createNonEnumerableProperty$2 = createNonEnumerableProperty$6;
2531
2728
  var redefine$1 = redefine$6.exports;
2532
- var wellKnownSymbol$5 = wellKnownSymbol$i;
2729
+ var wellKnownSymbol$3 = wellKnownSymbol$i;
2533
2730
  var Iterators$1 = iterators;
2534
2731
  var IteratorsCore = iteratorsCore;
2535
2732
 
@@ -2537,7 +2734,7 @@ var PROPER_FUNCTION_NAME = FunctionName.PROPER;
2537
2734
  var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
2538
2735
  var IteratorPrototype = IteratorsCore.IteratorPrototype;
2539
2736
  var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
2540
- var ITERATOR$2 = wellKnownSymbol$5('iterator');
2737
+ var ITERATOR$2 = wellKnownSymbol$3('iterator');
2541
2738
  var KEYS = 'keys';
2542
2739
  var VALUES = 'values';
2543
2740
  var ENTRIES = 'entries';
@@ -2720,15 +2917,15 @@ var DOMTokenListPrototype$1 = classList && classList.constructor && classList.co
2720
2917
 
2721
2918
  var domTokenListPrototype = DOMTokenListPrototype$1 === Object.prototype ? undefined : DOMTokenListPrototype$1;
2722
2919
 
2723
- var global$a = global$K;
2920
+ var global$8 = global$K;
2724
2921
  var DOMIterables = domIterables;
2725
2922
  var DOMTokenListPrototype = domTokenListPrototype;
2726
2923
  var ArrayIteratorMethods = es_array_iterator;
2727
2924
  var createNonEnumerableProperty$1 = createNonEnumerableProperty$6;
2728
- var wellKnownSymbol$4 = wellKnownSymbol$i;
2925
+ var wellKnownSymbol$2 = wellKnownSymbol$i;
2729
2926
 
2730
- var ITERATOR$1 = wellKnownSymbol$4('iterator');
2731
- var TO_STRING_TAG = wellKnownSymbol$4('toStringTag');
2927
+ var ITERATOR$1 = wellKnownSymbol$2('iterator');
2928
+ var TO_STRING_TAG = wellKnownSymbol$2('toStringTag');
2732
2929
  var ArrayValues = ArrayIteratorMethods.values;
2733
2930
 
2734
2931
  var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
@@ -2754,401 +2951,11 @@ var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
2754
2951
  };
2755
2952
 
2756
2953
  for (var COLLECTION_NAME in DOMIterables) {
2757
- handlePrototype(global$a[COLLECTION_NAME] && global$a[COLLECTION_NAME].prototype, COLLECTION_NAME);
2954
+ handlePrototype(global$8[COLLECTION_NAME] && global$8[COLLECTION_NAME].prototype, COLLECTION_NAME);
2758
2955
  }
2759
2956
 
2760
2957
  handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
2761
2958
 
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
2959
  class Ninetailed {
3153
2960
  constructor({
3154
2961
  clientId,
@@ -3195,29 +3002,45 @@ class Ninetailed {
3195
3002
 
3196
3003
  this.identify = (uid, traits, options) => __awaiter(this, void 0, void 0, function* () {
3197
3004
  yield this.waitUntilInitialized();
3005
+ /*console.log("Identify triggered");*/
3006
+
3198
3007
  return this.instance.identify(uid, traits, this.buildOptions(options));
3199
3008
  });
3200
3009
 
3201
- this.reset = () => __awaiter(this, void 0, void 0, function* () {
3202
- yield this.waitUntilInitialized();
3203
- this.instance.plugins[PLUGIN_NAME].reset();
3204
- });
3010
+ this.reset = () => {
3011
+ this.onIsInitialized(() => {
3012
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3013
+ // @ts-ignore
3014
+ this.instance.plugins[PLUGIN_NAME].reset();
3015
+ });
3016
+ };
3205
3017
 
3206
- this.debug = enabled => __awaiter(this, void 0, void 0, function* () {
3207
- yield this.waitUntilInitialized();
3208
- this.instance.plugins[PLUGIN_NAME].debug(enabled);
3209
- });
3018
+ this.debug = enabled => {
3019
+ this.onIsInitialized(() => {
3020
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3021
+ // @ts-ignore
3022
+ this.instance.plugins[PLUGIN_NAME].debug(enabled);
3023
+ });
3024
+ };
3210
3025
 
3211
3026
  this.onProfileChange = cb => {
3212
3027
  cb(this.profileState);
3213
3028
  return this.instance.on(NINETAILED_TRACKER_EVENTS.profile, ({
3214
3029
  payload
3215
3030
  }) => {
3216
- cb(Object.assign(Object.assign({}, this._profileState), {
3217
- status: 'success',
3218
- profile: payload.profile,
3219
- error: undefined
3220
- }));
3031
+ if (payload.error) {
3032
+ cb(Object.assign(Object.assign({}, this._profileState), {
3033
+ status: 'error',
3034
+ profile: payload.profile,
3035
+ error: payload.error
3036
+ }));
3037
+ } else {
3038
+ cb(Object.assign(Object.assign({}, this._profileState), {
3039
+ status: 'success',
3040
+ profile: payload.profile,
3041
+ error: null
3042
+ }));
3043
+ }
3221
3044
  });
3222
3045
  };
3223
3046
 
@@ -3227,7 +3050,6 @@ class Ninetailed {
3227
3050
  onIsInitialized();
3228
3051
  } else {
3229
3052
  const detachOnReadyListener = this.instance.on('ready', () => {
3230
- this.isInitialized = true;
3231
3053
  onIsInitialized();
3232
3054
  detachOnReadyListener();
3233
3055
  });
@@ -3247,14 +3069,14 @@ class Ninetailed {
3247
3069
  this._profileState = {
3248
3070
  status: 'success',
3249
3071
  profile,
3250
- error: undefined,
3072
+ error: null,
3251
3073
  from: 'hydrated'
3252
3074
  };
3253
3075
  } else {
3254
3076
  this._profileState = {
3255
3077
  status: 'loading',
3256
3078
  profile: null,
3257
- error: undefined,
3079
+ error: null,
3258
3080
  from: 'api'
3259
3081
  };
3260
3082
  }
@@ -3280,8 +3102,10 @@ class Ninetailed {
3280
3102
  preview
3281
3103
  })]
3282
3104
  });
3283
- this.onIsInitialized(() => {
3105
+ const detachOnReadyListener = this.instance.on('ready', () => {
3106
+ this.isInitialized = true;
3284
3107
  logger.info('Ninetailed Experience.js SDK is completely initialized.');
3108
+ detachOnReadyListener();
3285
3109
  }); // put in private method
3286
3110
 
3287
3111
  this.onProfileChange(profileState => {
@@ -3323,12 +3147,12 @@ const selectVariant$1 = (baseline, variants, {
3323
3147
  if (status === 'loading') {
3324
3148
  return {
3325
3149
  loading: true,
3326
- variant: Object.assign({
3150
+ variant: Object.assign(Object.assign({}, baseline), {
3327
3151
  id: 'baseline',
3328
3152
  audience: {
3329
3153
  id: 'baseline'
3330
3154
  }
3331
- }, baseline),
3155
+ }),
3332
3156
  audience: {
3333
3157
  id: 'baseline'
3334
3158
  },
@@ -3340,12 +3164,12 @@ const selectVariant$1 = (baseline, variants, {
3340
3164
  if (status === 'error') {
3341
3165
  return {
3342
3166
  loading: false,
3343
- variant: Object.assign({
3167
+ variant: Object.assign(Object.assign({}, baseline), {
3344
3168
  id: 'baseline',
3345
3169
  audience: {
3346
3170
  id: 'baseline'
3347
3171
  }
3348
- }, baseline),
3172
+ }),
3349
3173
  audience: {
3350
3174
  id: 'baseline'
3351
3175
  },
@@ -3361,15 +3185,16 @@ const selectVariant$1 = (baseline, variants, {
3361
3185
  });
3362
3186
 
3363
3187
  if (variant) {
3364
- if (options.holdout > profile.random) {
3188
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3189
+ // @ts-ignore
3190
+ if ((options === null || options === void 0 ? void 0 : options.holdout) || -1 > (profile === null || profile === void 0 ? void 0 : profile.random)) {
3365
3191
  return {
3366
3192
  loading: false,
3367
- variant: Object.assign({
3368
- id: baseline.id,
3193
+ variant: Object.assign(Object.assign({}, baseline), {
3369
3194
  audience: {
3370
3195
  id: 'baseline'
3371
3196
  }
3372
- }, baseline),
3197
+ }),
3373
3198
  audience: Object.assign(Object.assign({}, variant.audience), {
3374
3199
  id: variant.audience.id
3375
3200
  }),
@@ -3395,12 +3220,12 @@ const selectVariant$1 = (baseline, variants, {
3395
3220
 
3396
3221
  return {
3397
3222
  loading: false,
3398
- variant: Object.assign({
3223
+ variant: Object.assign(Object.assign({}, baseline), {
3399
3224
  id: 'baseline',
3400
3225
  audience: {
3401
3226
  id: 'baseline'
3402
3227
  }
3403
- }, baseline),
3228
+ }),
3404
3229
  audience: {
3405
3230
  id: 'baseline'
3406
3231
  },
@@ -3412,7 +3237,9 @@ const selectVariant$1 = (baseline, variants, {
3412
3237
  const EXPERIENCE_TRAIT_PREFIX = 'nt_experiment_';
3413
3238
 
3414
3239
  const selectBaselineWithVariants = (experience, baseline) => {
3415
- return experience.components.find(baselineWithVariants => baselineWithVariants.baseline.id === baseline.id);
3240
+ var _a;
3241
+
3242
+ return (_a = experience.components.find(baselineWithVariants => baselineWithVariants.baseline.id === baseline.id)) !== null && _a !== void 0 ? _a : null;
3416
3243
  };
3417
3244
 
3418
3245
  const selectVariants = (experience, baseline) => {
@@ -3430,63 +3257,13 @@ const selectHasVariants = (experience, baseline) => {
3430
3257
  return variants.length > 0;
3431
3258
  };
3432
3259
 
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
3260
  var $$3 = _export;
3484
3261
  var uncurryThis$8 = functionUncurryThis;
3485
3262
  var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
3486
3263
  var toLength$2 = toLength$4;
3487
- var toString$6 = toString$7;
3264
+ var toString$6 = toString$8;
3488
3265
  var notARegExp = notARegexp;
3489
- var requireObjectCoercible$4 = requireObjectCoercible$7;
3266
+ var requireObjectCoercible$4 = requireObjectCoercible$8;
3490
3267
  var correctIsRegExpLogic = correctIsRegexpLogic;
3491
3268
 
3492
3269
  // eslint-disable-next-line es/no-string-prototype-startswith -- safe
@@ -3589,7 +3366,7 @@ var regexpUnsupportedNcg = fails$5(function () {
3589
3366
  /* eslint-disable regexp/no-useless-quantifier -- testing */
3590
3367
  var call$3 = functionCall;
3591
3368
  var uncurryThis$7 = functionUncurryThis;
3592
- var toString$5 = toString$7;
3369
+ var toString$5 = toString$8;
3593
3370
  var regexpFlags = regexpFlags$1;
3594
3371
  var stickyHelpers$1 = regexpStickyHelpers;
3595
3372
  var shared = shared$4.exports;
@@ -3787,8 +3564,8 @@ var fixRegexpWellKnownSymbolLogic = function (KEY, exec, FORCED, SHAM) {
3787
3564
 
3788
3565
  var uncurryThis$5 = functionUncurryThis;
3789
3566
  var toIntegerOrInfinity$1 = toIntegerOrInfinity$4;
3790
- var toString$4 = toString$7;
3791
- var requireObjectCoercible$3 = requireObjectCoercible$7;
3567
+ var toString$4 = toString$8;
3568
+ var requireObjectCoercible$3 = requireObjectCoercible$8;
3792
3569
 
3793
3570
  var charAt$2 = uncurryThis$5(''.charAt);
3794
3571
  var charCodeAt = uncurryThis$5(''.charCodeAt);
@@ -3906,8 +3683,8 @@ var anObject$1 = anObject$e;
3906
3683
  var isCallable = isCallable$j;
3907
3684
  var toIntegerOrInfinity = toIntegerOrInfinity$4;
3908
3685
  var toLength$1 = toLength$4;
3909
- var toString$3 = toString$7;
3910
- var requireObjectCoercible$2 = requireObjectCoercible$7;
3686
+ var toString$3 = toString$8;
3687
+ var requireObjectCoercible$2 = requireObjectCoercible$8;
3911
3688
  var advanceStringIndex$1 = advanceStringIndex$2;
3912
3689
  var getMethod$1 = getMethod$5;
3913
3690
  var getSubstitution = getSubstitution$1;
@@ -4103,7 +3880,7 @@ const selectExperience = ({
4103
3880
  activeExperiments,
4104
3881
  profile
4105
3882
  }));
4106
- return selectedExperience;
3883
+ return selectedExperience !== null && selectedExperience !== void 0 ? selectedExperience : null;
4107
3884
  };
4108
3885
 
4109
3886
  const selectDistribution = ({
@@ -4117,6 +3894,16 @@ const selectDistribution = ({
4117
3894
  end
4118
3895
  }) => distributionRandom >= start && distributionRandom <= end // this overlaps on one value for each boundary but we just find the first match
4119
3896
  );
3897
+
3898
+ if (!distribution) {
3899
+ // This should never happen. If it happens then the distribution is not configured correctly. So we just return the baseline.
3900
+ return {
3901
+ index: 0,
3902
+ start: 0,
3903
+ end: 1
3904
+ };
3905
+ }
3906
+
4120
3907
  return distribution;
4121
3908
  };
4122
3909
 
@@ -4271,11 +4058,11 @@ var uncurryThis$2 = functionUncurryThis;
4271
4058
  var fixRegExpWellKnownSymbolLogic = fixRegexpWellKnownSymbolLogic;
4272
4059
  var isRegExp = isRegexp;
4273
4060
  var anObject = anObject$e;
4274
- var requireObjectCoercible$1 = requireObjectCoercible$7;
4061
+ var requireObjectCoercible$1 = requireObjectCoercible$8;
4275
4062
  var speciesConstructor = speciesConstructor$2;
4276
4063
  var advanceStringIndex = advanceStringIndex$2;
4277
4064
  var toLength = toLength$4;
4278
- var toString$2 = toString$7;
4065
+ var toString$2 = toString$8;
4279
4066
  var getMethod = getMethod$5;
4280
4067
  var arraySlice = arraySliceSimple;
4281
4068
  var callRegExpExec = regexpExecAbstract;
@@ -4426,8 +4213,8 @@ var whitespaces$2 = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u200
4426
4213
  '\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
4427
4214
 
4428
4215
  var uncurryThis$1 = functionUncurryThis;
4429
- var requireObjectCoercible = requireObjectCoercible$7;
4430
- var toString$1 = toString$7;
4216
+ var requireObjectCoercible = requireObjectCoercible$8;
4217
+ var toString$1 = toString$8;
4431
4218
  var whitespaces$1 = whitespaces$2;
4432
4219
 
4433
4220
  var replace = uncurryThis$1(''.replace);
@@ -4460,7 +4247,7 @@ var stringTrim = {
4460
4247
  var global$1 = global$K;
4461
4248
  var fails = fails$k;
4462
4249
  var uncurryThis = functionUncurryThis;
4463
- var toString = toString$7;
4250
+ var toString = toString$8;
4464
4251
  var trim = stringTrim.trim;
4465
4252
  var whitespaces = whitespaces$2;
4466
4253
 
@@ -4502,9 +4289,9 @@ const decodeExperienceVariantsMap = encodedExperienceVariantsMap => {
4502
4289
  experienceId,
4503
4290
  variantIndex
4504
4291
  };
4505
- }).filter(x => x).reduce((acc, curr) => Object.assign(Object.assign({}, acc), {
4292
+ }).filter(x => !!x).reduce((acc, curr) => Object.assign(Object.assign({}, acc), {
4506
4293
  [curr.experienceId]: curr.variantIndex
4507
4294
  }), {});
4508
4295
  };
4509
4296
 
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 };
4297
+ 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 };