@ninetailed/experience.js 2.0.0-beta.11 → 2.0.0-beta.12

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,6 +1,7 @@
1
1
  import get$2 from 'lodash/get';
2
2
  import unionBy from 'lodash/unionBy';
3
3
  import { buildEmptyCache, buildTrackEvent, buildIdentifyEvent, buildPageEvent } from '@ninetailed/experience.js-shared';
4
+ import * as loglevel from 'loglevel';
4
5
  import Analytics from 'analytics';
5
6
  import flatten from 'lodash/flatten';
6
7
  import find from 'lodash/find';
@@ -178,9 +179,9 @@ var engineUserAgent = getBuiltIn$6('navigator', 'userAgent') || '';
178
179
  var global$D = global$H;
179
180
  var userAgent$3 = engineUserAgent;
180
181
 
181
- var process$4 = global$D.process;
182
+ var process$3 = global$D.process;
182
183
  var Deno = global$D.Deno;
183
- var versions = process$4 && process$4.versions || Deno && Deno.version;
184
+ var versions = process$3 && process$3.versions || Deno && Deno.version;
184
185
  var v8 = versions && versions.v8;
185
186
  var match, version;
186
187
 
@@ -1406,7 +1407,7 @@ var IS_NODE$2 = engineIsNode;
1406
1407
 
1407
1408
  var set$1 = global$d.setImmediate;
1408
1409
  var clear = global$d.clearImmediate;
1409
- var process$3 = global$d.process;
1410
+ var process$2 = global$d.process;
1410
1411
  var Dispatch = global$d.Dispatch;
1411
1412
  var Function$1 = global$d.Function;
1412
1413
  var MessageChannel = global$d.MessageChannel;
@@ -1462,7 +1463,7 @@ if (!set$1 || !clear) {
1462
1463
  // Node.js 0.8-
1463
1464
  if (IS_NODE$2) {
1464
1465
  defer = function (id) {
1465
- process$3.nextTick(runner(id));
1466
+ process$2.nextTick(runner(id));
1466
1467
  };
1467
1468
  // Sphere (JS game engine) Dispatch API
1468
1469
  } else if (Dispatch && Dispatch.now) {
@@ -1528,7 +1529,7 @@ var IS_NODE$1 = engineIsNode;
1528
1529
 
1529
1530
  var MutationObserver = global$b.MutationObserver || global$b.WebKitMutationObserver;
1530
1531
  var document$2 = global$b.document;
1531
- var process$2 = global$b.process;
1532
+ var process$1 = global$b.process;
1532
1533
  var Promise$1 = global$b.Promise;
1533
1534
  // Node.js 11 shows ExperimentalWarning on getting `queueMicrotask`
1534
1535
  var queueMicrotaskDescriptor = getOwnPropertyDescriptor$1(global$b, 'queueMicrotask');
@@ -1540,7 +1541,7 @@ var flush, head, last, notify$1, toggle, node, promise, then;
1540
1541
  if (!queueMicrotask) {
1541
1542
  flush = function () {
1542
1543
  var parent, fn;
1543
- if (IS_NODE$1 && (parent = process$2.domain)) parent.exit();
1544
+ if (IS_NODE$1 && (parent = process$1.domain)) parent.exit();
1544
1545
  while (head) {
1545
1546
  fn = head.fn;
1546
1547
  head = head.next;
@@ -1577,7 +1578,7 @@ if (!queueMicrotask) {
1577
1578
  // Node.js without promises
1578
1579
  } else if (IS_NODE$1) {
1579
1580
  notify$1 = function () {
1580
- process$2.nextTick(flush);
1581
+ process$1.nextTick(flush);
1581
1582
  };
1582
1583
  // for other environments - macrotask based on:
1583
1584
  // - setImmediate
@@ -1723,7 +1724,7 @@ var PromiseConstructor = NativePromise;
1723
1724
  var PromisePrototype = NativePromisePrototype;
1724
1725
  var TypeError$3 = global$9.TypeError;
1725
1726
  var document$1 = global$9.document;
1726
- var process$1 = global$9.process;
1727
+ var process = global$9.process;
1727
1728
  var newPromiseCapability = newPromiseCapabilityModule.f;
1728
1729
  var newGenericPromiseCapability = newPromiseCapability;
1729
1730
 
@@ -1845,7 +1846,7 @@ var onUnhandled = function (state) {
1845
1846
  if (IS_UNHANDLED) {
1846
1847
  result = perform(function () {
1847
1848
  if (IS_NODE) {
1848
- process$1.emit('unhandledRejection', value, promise);
1849
+ process.emit('unhandledRejection', value, promise);
1849
1850
  } else dispatchEvent(UNHANDLED_REJECTION, promise, value);
1850
1851
  });
1851
1852
  // Browsers should not trigger `rejectionHandled` event if it was handled here, NodeJS - should
@@ -1863,7 +1864,7 @@ var onHandleUnhandled = function (state) {
1863
1864
  call$5(task, global$9, function () {
1864
1865
  var promise = state.facade;
1865
1866
  if (IS_NODE) {
1866
- process$1.emit('rejectionHandled', promise);
1867
+ process.emit('rejectionHandled', promise);
1867
1868
  } else dispatchEvent(REJECTION_HANDLED, promise, state.value);
1868
1869
  });
1869
1870
  };
@@ -1950,7 +1951,7 @@ if (FORCED) {
1950
1951
  state.parent = true;
1951
1952
  reaction.ok = isCallable$5(onFulfilled) ? onFulfilled : true;
1952
1953
  reaction.fail = isCallable$5(onRejected) && onRejected;
1953
- reaction.domain = IS_NODE ? process$1.domain : undefined;
1954
+ reaction.domain = IS_NODE ? process.domain : undefined;
1954
1955
  if (state.state == PENDING) state.reactions.add(reaction);
1955
1956
  else microtask(function () {
1956
1957
  callReaction(reaction, state);
@@ -2221,724 +2222,14 @@ const buildClientNinetailedRequestContext = () => ({
2221
2222
  }
2222
2223
  });
2223
2224
 
2224
- var browser = {exports: {}};
2225
-
2226
- /**
2227
- * Helpers.
2228
- */
2229
-
2230
- var s = 1000;
2231
- var m = s * 60;
2232
- var h = m * 60;
2233
- var d = h * 24;
2234
- var w = d * 7;
2235
- var y = d * 365.25;
2236
-
2237
- /**
2238
- * Parse or format the given `val`.
2239
- *
2240
- * Options:
2241
- *
2242
- * - `long` verbose formatting [false]
2243
- *
2244
- * @param {String|Number} val
2245
- * @param {Object} [options]
2246
- * @throws {Error} throw an error if val is not a non-empty string or a number
2247
- * @return {String|Number}
2248
- * @api public
2249
- */
2250
-
2251
- var ms = function(val, options) {
2252
- options = options || {};
2253
- var type = typeof val;
2254
- if (type === 'string' && val.length > 0) {
2255
- return parse(val);
2256
- } else if (type === 'number' && isFinite(val)) {
2257
- return options.long ? fmtLong(val) : fmtShort(val);
2258
- }
2259
- throw new Error(
2260
- 'val is not a non-empty string or a valid number. val=' +
2261
- JSON.stringify(val)
2262
- );
2263
- };
2264
-
2265
- /**
2266
- * Parse the given `str` and return milliseconds.
2267
- *
2268
- * @param {String} str
2269
- * @return {Number}
2270
- * @api private
2271
- */
2272
-
2273
- function parse(str) {
2274
- str = String(str);
2275
- if (str.length > 100) {
2276
- return;
2277
- }
2278
- var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
2279
- str
2280
- );
2281
- if (!match) {
2282
- return;
2283
- }
2284
- var n = parseFloat(match[1]);
2285
- var type = (match[2] || 'ms').toLowerCase();
2286
- switch (type) {
2287
- case 'years':
2288
- case 'year':
2289
- case 'yrs':
2290
- case 'yr':
2291
- case 'y':
2292
- return n * y;
2293
- case 'weeks':
2294
- case 'week':
2295
- case 'w':
2296
- return n * w;
2297
- case 'days':
2298
- case 'day':
2299
- case 'd':
2300
- return n * d;
2301
- case 'hours':
2302
- case 'hour':
2303
- case 'hrs':
2304
- case 'hr':
2305
- case 'h':
2306
- return n * h;
2307
- case 'minutes':
2308
- case 'minute':
2309
- case 'mins':
2310
- case 'min':
2311
- case 'm':
2312
- return n * m;
2313
- case 'seconds':
2314
- case 'second':
2315
- case 'secs':
2316
- case 'sec':
2317
- case 's':
2318
- return n * s;
2319
- case 'milliseconds':
2320
- case 'millisecond':
2321
- case 'msecs':
2322
- case 'msec':
2323
- case 'ms':
2324
- return n;
2325
- default:
2326
- return undefined;
2327
- }
2328
- }
2329
-
2330
- /**
2331
- * Short format for `ms`.
2332
- *
2333
- * @param {Number} ms
2334
- * @return {String}
2335
- * @api private
2336
- */
2337
-
2338
- function fmtShort(ms) {
2339
- var msAbs = Math.abs(ms);
2340
- if (msAbs >= d) {
2341
- return Math.round(ms / d) + 'd';
2342
- }
2343
- if (msAbs >= h) {
2344
- return Math.round(ms / h) + 'h';
2345
- }
2346
- if (msAbs >= m) {
2347
- return Math.round(ms / m) + 'm';
2348
- }
2349
- if (msAbs >= s) {
2350
- return Math.round(ms / s) + 's';
2351
- }
2352
- return ms + 'ms';
2353
- }
2354
-
2355
- /**
2356
- * Long format for `ms`.
2357
- *
2358
- * @param {Number} ms
2359
- * @return {String}
2360
- * @api private
2361
- */
2362
-
2363
- function fmtLong(ms) {
2364
- var msAbs = Math.abs(ms);
2365
- if (msAbs >= d) {
2366
- return plural(ms, msAbs, d, 'day');
2367
- }
2368
- if (msAbs >= h) {
2369
- return plural(ms, msAbs, h, 'hour');
2370
- }
2371
- if (msAbs >= m) {
2372
- return plural(ms, msAbs, m, 'minute');
2373
- }
2374
- if (msAbs >= s) {
2375
- return plural(ms, msAbs, s, 'second');
2376
- }
2377
- return ms + ' ms';
2378
- }
2379
-
2380
- /**
2381
- * Pluralization helper.
2382
- */
2383
-
2384
- function plural(ms, msAbs, n, name) {
2385
- var isPlural = msAbs >= n * 1.5;
2386
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
2387
- }
2388
-
2389
- /**
2390
- * This is the common logic for both the Node.js and web browser
2391
- * implementations of `debug()`.
2392
- */
2393
-
2394
- function setup(env) {
2395
- createDebug.debug = createDebug;
2396
- createDebug.default = createDebug;
2397
- createDebug.coerce = coerce;
2398
- createDebug.disable = disable;
2399
- createDebug.enable = enable;
2400
- createDebug.enabled = enabled;
2401
- createDebug.humanize = ms;
2402
- createDebug.destroy = destroy;
2403
-
2404
- Object.keys(env).forEach(key => {
2405
- createDebug[key] = env[key];
2406
- });
2407
-
2408
- /**
2409
- * The currently active debug mode names, and names to skip.
2410
- */
2411
-
2412
- createDebug.names = [];
2413
- createDebug.skips = [];
2414
-
2415
- /**
2416
- * Map of special "%n" handling functions, for the debug "format" argument.
2417
- *
2418
- * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
2419
- */
2420
- createDebug.formatters = {};
2421
-
2422
- /**
2423
- * Selects a color for a debug namespace
2424
- * @param {String} namespace The namespace string for the debug instance to be colored
2425
- * @return {Number|String} An ANSI color code for the given namespace
2426
- * @api private
2427
- */
2428
- function selectColor(namespace) {
2429
- let hash = 0;
2430
-
2431
- for (let i = 0; i < namespace.length; i++) {
2432
- hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
2433
- hash |= 0; // Convert to 32bit integer
2434
- }
2435
-
2436
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
2437
- }
2438
- createDebug.selectColor = selectColor;
2439
-
2440
- /**
2441
- * Create a debugger with the given `namespace`.
2442
- *
2443
- * @param {String} namespace
2444
- * @return {Function}
2445
- * @api public
2446
- */
2447
- function createDebug(namespace) {
2448
- let prevTime;
2449
- let enableOverride = null;
2450
- let namespacesCache;
2451
- let enabledCache;
2452
-
2453
- function debug(...args) {
2454
- // Disabled?
2455
- if (!debug.enabled) {
2456
- return;
2457
- }
2458
-
2459
- const self = debug;
2460
-
2461
- // Set `diff` timestamp
2462
- const curr = Number(new Date());
2463
- const ms = curr - (prevTime || curr);
2464
- self.diff = ms;
2465
- self.prev = prevTime;
2466
- self.curr = curr;
2467
- prevTime = curr;
2468
-
2469
- args[0] = createDebug.coerce(args[0]);
2470
-
2471
- if (typeof args[0] !== 'string') {
2472
- // Anything else let's inspect with %O
2473
- args.unshift('%O');
2474
- }
2475
-
2476
- // Apply any `formatters` transformations
2477
- let index = 0;
2478
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
2479
- // If we encounter an escaped % then don't increase the array index
2480
- if (match === '%%') {
2481
- return '%';
2482
- }
2483
- index++;
2484
- const formatter = createDebug.formatters[format];
2485
- if (typeof formatter === 'function') {
2486
- const val = args[index];
2487
- match = formatter.call(self, val);
2488
-
2489
- // Now we need to remove `args[index]` since it's inlined in the `format`
2490
- args.splice(index, 1);
2491
- index--;
2492
- }
2493
- return match;
2494
- });
2495
-
2496
- // Apply env-specific formatting (colors, etc.)
2497
- createDebug.formatArgs.call(self, args);
2498
-
2499
- const logFn = self.log || createDebug.log;
2500
- logFn.apply(self, args);
2501
- }
2502
-
2503
- debug.namespace = namespace;
2504
- debug.useColors = createDebug.useColors();
2505
- debug.color = createDebug.selectColor(namespace);
2506
- debug.extend = extend;
2507
- debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
2508
-
2509
- Object.defineProperty(debug, 'enabled', {
2510
- enumerable: true,
2511
- configurable: false,
2512
- get: () => {
2513
- if (enableOverride !== null) {
2514
- return enableOverride;
2515
- }
2516
- if (namespacesCache !== createDebug.namespaces) {
2517
- namespacesCache = createDebug.namespaces;
2518
- enabledCache = createDebug.enabled(namespace);
2519
- }
2520
-
2521
- return enabledCache;
2522
- },
2523
- set: v => {
2524
- enableOverride = v;
2525
- }
2526
- });
2527
-
2528
- // Env-specific initialization logic for debug instances
2529
- if (typeof createDebug.init === 'function') {
2530
- createDebug.init(debug);
2531
- }
2532
-
2533
- return debug;
2534
- }
2535
-
2536
- function extend(namespace, delimiter) {
2537
- const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
2538
- newDebug.log = this.log;
2539
- return newDebug;
2540
- }
2541
-
2542
- /**
2543
- * Enables a debug mode by namespaces. This can include modes
2544
- * separated by a colon and wildcards.
2545
- *
2546
- * @param {String} namespaces
2547
- * @api public
2548
- */
2549
- function enable(namespaces) {
2550
- createDebug.save(namespaces);
2551
- createDebug.namespaces = namespaces;
2552
-
2553
- createDebug.names = [];
2554
- createDebug.skips = [];
2555
-
2556
- let i;
2557
- const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
2558
- const len = split.length;
2559
-
2560
- for (i = 0; i < len; i++) {
2561
- if (!split[i]) {
2562
- // ignore empty strings
2563
- continue;
2564
- }
2565
-
2566
- namespaces = split[i].replace(/\*/g, '.*?');
2567
-
2568
- if (namespaces[0] === '-') {
2569
- createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
2570
- } else {
2571
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
2572
- }
2573
- }
2574
- }
2575
-
2576
- /**
2577
- * Disable debug output.
2578
- *
2579
- * @return {String} namespaces
2580
- * @api public
2581
- */
2582
- function disable() {
2583
- const namespaces = [
2584
- ...createDebug.names.map(toNamespace),
2585
- ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
2586
- ].join(',');
2587
- createDebug.enable('');
2588
- return namespaces;
2589
- }
2590
-
2591
- /**
2592
- * Returns true if the given mode name is enabled, false otherwise.
2593
- *
2594
- * @param {String} name
2595
- * @return {Boolean}
2596
- * @api public
2597
- */
2598
- function enabled(name) {
2599
- if (name[name.length - 1] === '*') {
2600
- return true;
2601
- }
2602
-
2603
- let i;
2604
- let len;
2605
-
2606
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
2607
- if (createDebug.skips[i].test(name)) {
2608
- return false;
2609
- }
2610
- }
2611
-
2612
- for (i = 0, len = createDebug.names.length; i < len; i++) {
2613
- if (createDebug.names[i].test(name)) {
2614
- return true;
2615
- }
2616
- }
2617
-
2618
- return false;
2619
- }
2620
-
2621
- /**
2622
- * Convert regexp to namespace
2623
- *
2624
- * @param {RegExp} regxep
2625
- * @return {String} namespace
2626
- * @api private
2627
- */
2628
- function toNamespace(regexp) {
2629
- return regexp.toString()
2630
- .substring(2, regexp.toString().length - 2)
2631
- .replace(/\.\*\?$/, '*');
2632
- }
2633
-
2634
- /**
2635
- * Coerce `val`.
2636
- *
2637
- * @param {Mixed} val
2638
- * @return {Mixed}
2639
- * @api private
2640
- */
2641
- function coerce(val) {
2642
- if (val instanceof Error) {
2643
- return val.stack || val.message;
2644
- }
2645
- return val;
2646
- }
2647
-
2648
- /**
2649
- * XXX DO NOT USE. This is a temporary stub function.
2650
- * XXX It WILL be removed in the next major release.
2651
- */
2652
- function destroy() {
2653
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
2654
- }
2655
-
2656
- createDebug.enable(createDebug.load());
2657
-
2658
- return createDebug;
2659
- }
2660
-
2661
- var common = setup;
2662
-
2663
- /* eslint-env browser */
2664
-
2665
- (function (module, exports) {
2666
- /**
2667
- * This is the web browser implementation of `debug()`.
2668
- */
2669
-
2670
- exports.formatArgs = formatArgs;
2671
- exports.save = save;
2672
- exports.load = load;
2673
- exports.useColors = useColors;
2674
- exports.storage = localstorage();
2675
- exports.destroy = (() => {
2676
- let warned = false;
2677
-
2678
- return () => {
2679
- if (!warned) {
2680
- warned = true;
2681
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
2682
- }
2683
- };
2684
- })();
2685
-
2686
- /**
2687
- * Colors.
2688
- */
2689
-
2690
- exports.colors = [
2691
- '#0000CC',
2692
- '#0000FF',
2693
- '#0033CC',
2694
- '#0033FF',
2695
- '#0066CC',
2696
- '#0066FF',
2697
- '#0099CC',
2698
- '#0099FF',
2699
- '#00CC00',
2700
- '#00CC33',
2701
- '#00CC66',
2702
- '#00CC99',
2703
- '#00CCCC',
2704
- '#00CCFF',
2705
- '#3300CC',
2706
- '#3300FF',
2707
- '#3333CC',
2708
- '#3333FF',
2709
- '#3366CC',
2710
- '#3366FF',
2711
- '#3399CC',
2712
- '#3399FF',
2713
- '#33CC00',
2714
- '#33CC33',
2715
- '#33CC66',
2716
- '#33CC99',
2717
- '#33CCCC',
2718
- '#33CCFF',
2719
- '#6600CC',
2720
- '#6600FF',
2721
- '#6633CC',
2722
- '#6633FF',
2723
- '#66CC00',
2724
- '#66CC33',
2725
- '#9900CC',
2726
- '#9900FF',
2727
- '#9933CC',
2728
- '#9933FF',
2729
- '#99CC00',
2730
- '#99CC33',
2731
- '#CC0000',
2732
- '#CC0033',
2733
- '#CC0066',
2734
- '#CC0099',
2735
- '#CC00CC',
2736
- '#CC00FF',
2737
- '#CC3300',
2738
- '#CC3333',
2739
- '#CC3366',
2740
- '#CC3399',
2741
- '#CC33CC',
2742
- '#CC33FF',
2743
- '#CC6600',
2744
- '#CC6633',
2745
- '#CC9900',
2746
- '#CC9933',
2747
- '#CCCC00',
2748
- '#CCCC33',
2749
- '#FF0000',
2750
- '#FF0033',
2751
- '#FF0066',
2752
- '#FF0099',
2753
- '#FF00CC',
2754
- '#FF00FF',
2755
- '#FF3300',
2756
- '#FF3333',
2757
- '#FF3366',
2758
- '#FF3399',
2759
- '#FF33CC',
2760
- '#FF33FF',
2761
- '#FF6600',
2762
- '#FF6633',
2763
- '#FF9900',
2764
- '#FF9933',
2765
- '#FFCC00',
2766
- '#FFCC33'
2767
- ];
2768
-
2769
- /**
2770
- * Currently only WebKit-based Web Inspectors, Firefox >= v31,
2771
- * and the Firebug extension (any Firefox version) are known
2772
- * to support "%c" CSS customizations.
2773
- *
2774
- * TODO: add a `localStorage` variable to explicitly enable/disable colors
2775
- */
2776
-
2777
- // eslint-disable-next-line complexity
2778
- function useColors() {
2779
- // NB: In an Electron preload script, document will be defined but not fully
2780
- // initialized. Since we know we're in Chrome, we'll just detect this case
2781
- // explicitly
2782
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
2783
- return true;
2784
- }
2785
-
2786
- // Internet Explorer and Edge do not support colors.
2787
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
2788
- return false;
2789
- }
2790
-
2791
- // Is webkit? http://stackoverflow.com/a/16459606/376773
2792
- // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
2793
- return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
2794
- // Is firebug? http://stackoverflow.com/a/398120/376773
2795
- (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
2796
- // Is firefox >= v31?
2797
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
2798
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
2799
- // Double check webkit in userAgent just in case we are in a worker
2800
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
2801
- }
2802
-
2803
- /**
2804
- * Colorize log arguments if enabled.
2805
- *
2806
- * @api public
2807
- */
2808
-
2809
- function formatArgs(args) {
2810
- args[0] = (this.useColors ? '%c' : '') +
2811
- this.namespace +
2812
- (this.useColors ? ' %c' : ' ') +
2813
- args[0] +
2814
- (this.useColors ? '%c ' : ' ') +
2815
- '+' + module.exports.humanize(this.diff);
2816
-
2817
- if (!this.useColors) {
2818
- return;
2819
- }
2820
-
2821
- const c = 'color: ' + this.color;
2822
- args.splice(1, 0, c, 'color: inherit');
2823
-
2824
- // The final "%c" is somewhat tricky, because there could be other
2825
- // arguments passed either before or after the %c, so we need to
2826
- // figure out the correct index to insert the CSS into
2827
- let index = 0;
2828
- let lastC = 0;
2829
- args[0].replace(/%[a-zA-Z%]/g, match => {
2830
- if (match === '%%') {
2831
- return;
2832
- }
2833
- index++;
2834
- if (match === '%c') {
2835
- // We only are interested in the *last* %c
2836
- // (the user may have provided their own)
2837
- lastC = index;
2838
- }
2839
- });
2840
-
2841
- args.splice(lastC, 0, c);
2842
- }
2843
-
2844
- /**
2845
- * Invokes `console.debug()` when available.
2846
- * No-op when `console.debug` is not a "function".
2847
- * If `console.debug` is not available, falls back
2848
- * to `console.log`.
2849
- *
2850
- * @api public
2851
- */
2852
- exports.log = console.debug || console.log || (() => {});
2853
-
2854
- /**
2855
- * Save `namespaces`.
2856
- *
2857
- * @param {String} namespaces
2858
- * @api private
2859
- */
2860
- function save(namespaces) {
2861
- try {
2862
- if (namespaces) {
2863
- exports.storage.setItem('debug', namespaces);
2864
- } else {
2865
- exports.storage.removeItem('debug');
2866
- }
2867
- } catch (error) {
2868
- // Swallow
2869
- // XXX (@Qix-) should we be logging these?
2870
- }
2871
- }
2872
-
2873
- /**
2874
- * Load `namespaces`.
2875
- *
2876
- * @return {String} returns the previously persisted debug modes
2877
- * @api private
2878
- */
2879
- function load() {
2880
- let r;
2881
- try {
2882
- r = exports.storage.getItem('debug');
2883
- } catch (error) {
2884
- // Swallow
2885
- // XXX (@Qix-) should we be logging these?
2886
- }
2887
-
2888
- // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
2889
- if (!r && typeof process !== 'undefined' && 'env' in process) {
2890
- r = process.env.DEBUG;
2891
- }
2892
-
2893
- return r;
2894
- }
2895
-
2896
- /**
2897
- * Localstorage attempts to return the localstorage.
2898
- *
2899
- * This is necessary because safari throws
2900
- * when a user disables cookies/localstorage
2901
- * and you attempt to access it.
2902
- *
2903
- * @return {LocalStorage}
2904
- * @api private
2905
- */
2906
-
2907
- function localstorage() {
2908
- try {
2909
- // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
2910
- // The Browser also has localStorage in the global context.
2911
- return localStorage;
2912
- } catch (error) {
2913
- // Swallow
2914
- // XXX (@Qix-) should we be logging these?
2915
- }
2916
- }
2917
-
2918
- module.exports = common(exports);
2919
-
2920
- const {formatters} = module.exports;
2921
-
2922
- /**
2923
- * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
2924
- */
2925
-
2926
- formatters.j = function (v) {
2927
- try {
2928
- return JSON.stringify(v);
2929
- } catch (error) {
2930
- return '[UnexpectedJSONParseError]: ' + error.message;
2931
- }
2932
- };
2933
- }(browser, browser.exports));
2934
-
2935
- var Debug = browser.exports;
2936
-
2937
- const log = Debug('ninetailed:experience-sdk');
2938
2225
  const enable = () => {
2939
- Debug.enable('ninetailed:experience-sdk');
2226
+ loglevel.enableAll();
2227
+ };
2228
+ const disable = () => {
2229
+ loglevel.disableAll();
2940
2230
  };
2941
- const disable = () => Debug.disable();
2231
+ const Logger = loglevel.getLogger('ninetailed:experience.js');
2232
+ const log = Logger.log;
2942
2233
 
2943
2234
  const BASE_URL = 'https://api.ninetailed.co';
2944
2235
 
@@ -4598,6 +3889,7 @@ const selectExperience = ({
4598
3889
  });
4599
3890
  const selectedExperience = eglibleExperiences.find(experience => {
4600
3891
  const trafficRandom = getTrafficRandom(profile, experience);
3892
+ log(`The traffic random factor for experience ${experience.id} is ${trafficRandom}. It's traffic allocation is set to ${experience.trafficAllocation}.`);
4601
3893
  return experience.trafficAllocation > trafficRandom && (includes(profile.audiences, experience.audience.id) || // if the expriment is active already then it's selectible without further contraints to be fullfilled
4602
3894
  find(activeExperiments, {
4603
3895
  id: experience.id
@@ -4622,7 +3914,8 @@ const selectVariant = ({
4622
3914
  return variants[0];
4623
3915
  }
4624
3916
 
4625
- const distributionRandom = getDistributionRandom(profile, experience); // Experiment
3917
+ const distributionRandom = getDistributionRandom(profile, experience);
3918
+ log(`The distribution random factor for experience ${experience.id} is ${distributionRandom}. It's distribution is set to ${JSON.stringify(experience.distribution, null, 2)}.`); // Experiment
4626
3919
 
4627
3920
  const distribution = find(experience.distribution, ({
4628
3921
  start,