clarity-js 0.7.4 → 0.7.6

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/build/clarity.js CHANGED
@@ -145,11 +145,11 @@ function time(event) {
145
145
  var ts = event && event.timeStamp > 0 ? event.timeStamp : performance.now();
146
146
  return Math.max(Math.round(ts - startTime), 0);
147
147
  }
148
- function stop$C() {
148
+ function stop$D() {
149
149
  startTime = 0;
150
150
  }
151
151
 
152
- var version$1 = "0.7.4";
152
+ var version$1 = "0.7.6";
153
153
 
154
154
  // tslint:disable: no-bitwise
155
155
  function hash (input, precision) {
@@ -199,6 +199,7 @@ function text$1(value, hint, privacy, mangle) {
199
199
  case 3 /* Privacy.TextImage */:
200
200
  switch (hint) {
201
201
  case "*T" /* Layout.Constant.TextTag */:
202
+ case "data-" /* Layout.Constant.DataAttribute */:
202
203
  return mangle ? mangleText(value) : mask(value);
203
204
  case "src":
204
205
  case "srcset":
@@ -217,6 +218,7 @@ function text$1(value, hint, privacy, mangle) {
217
218
  case 4 /* Privacy.Exclude */:
218
219
  switch (hint) {
219
220
  case "*T" /* Layout.Constant.TextTag */:
221
+ case "data-" /* Layout.Constant.DataAttribute */:
220
222
  return mangle ? mangleText(value) : mask(value);
221
223
  case "value":
222
224
  case "input":
@@ -226,6 +228,25 @@ function text$1(value, hint, privacy, mangle) {
226
228
  case "checksum":
227
229
  return "" /* Data.Constant.Empty */;
228
230
  }
231
+ break;
232
+ case 5 /* Privacy.Snapshot */:
233
+ switch (hint) {
234
+ case "*T" /* Layout.Constant.TextTag */:
235
+ case "data-" /* Layout.Constant.DataAttribute */:
236
+ return scrub(value);
237
+ case "value":
238
+ case "input":
239
+ case "click":
240
+ case "change":
241
+ return Array(5 /* Data.Setting.WordLength */).join("\u2022" /* Data.Constant.Mask */);
242
+ case "checksum":
243
+ case "src":
244
+ case "srcset":
245
+ case "alt":
246
+ case "title":
247
+ return "" /* Data.Constant.Empty */;
248
+ }
249
+ break;
229
250
  }
230
251
  }
231
252
  return value;
@@ -253,6 +274,10 @@ function mangleText(value) {
253
274
  function mask(value) {
254
275
  return value.replace(catchallRegex, "\u2022" /* Data.Constant.Mask */);
255
276
  }
277
+ function scrub(value) {
278
+ regex(); // Initialize regular expressions
279
+ return value.replace(letterRegex, "\u25AA" /* Data.Constant.Letter */).replace(digitRegex, "\u25AB" /* Data.Constant.Digit */);
280
+ }
256
281
  function mangleToken(value) {
257
282
  var length = ((Math.floor(value.length / 5 /* Data.Setting.WordLength */) + 1) * 5 /* Data.Setting.WordLength */);
258
283
  var output = "" /* Layout.Constant.Empty */;
@@ -261,13 +286,7 @@ function mangleToken(value) {
261
286
  }
262
287
  return output;
263
288
  }
264
- function redact(value) {
265
- var spaceIndex = -1;
266
- var gap = 0;
267
- var hasDigit = false;
268
- var hasEmail = false;
269
- var hasWhitespace = false;
270
- var array = null;
289
+ function regex() {
271
290
  // Initialize unicode regex, if supported by the browser
272
291
  // Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes
273
292
  if (unicodeRegex && digitRegex === null) {
@@ -280,6 +299,15 @@ function redact(value) {
280
299
  unicodeRegex = false;
281
300
  }
282
301
  }
302
+ }
303
+ function redact(value) {
304
+ var spaceIndex = -1;
305
+ var gap = 0;
306
+ var hasDigit = false;
307
+ var hasEmail = false;
308
+ var hasWhitespace = false;
309
+ var array = null;
310
+ regex(); // Initialize regular expressions
283
311
  for (var i = 0; i < value.length; i++) {
284
312
  var c = value.charCodeAt(i);
285
313
  hasDigit = hasDigit || (c >= 48 /* Data.Character.Zero */ && c <= 57 /* Data.Character.Nine */); // Check for digits in the current word
@@ -391,7 +419,7 @@ function compute$c() {
391
419
  encode$1(4 /* Event.Baseline */);
392
420
  }
393
421
  }
394
- function stop$B() {
422
+ function stop$C() {
395
423
  reset$q();
396
424
  }
397
425
 
@@ -402,7 +430,7 @@ var baseline = /*#__PURE__*/Object.freeze({
402
430
  reset: reset$q,
403
431
  start: start$F,
404
432
  get state () { return state$a; },
405
- stop: stop$B,
433
+ stop: stop$C,
406
434
  track: track$7,
407
435
  visibility: visibility
408
436
  });
@@ -428,7 +456,7 @@ function start$E() {
428
456
  updates$3 = {};
429
457
  count$1(5 /* Metric.InvokeCount */);
430
458
  }
431
- function stop$A() {
459
+ function stop$B() {
432
460
  data$i = {};
433
461
  updates$3 = {};
434
462
  }
@@ -506,7 +534,7 @@ function ping() {
506
534
  suspend();
507
535
  }
508
536
  }
509
- function stop$z() {
537
+ function stop$A() {
510
538
  clearTimeout(timeout$6);
511
539
  last = 0;
512
540
  interval = 0;
@@ -517,14 +545,14 @@ var ping$1 = /*#__PURE__*/Object.freeze({
517
545
  get data () { return data$h; },
518
546
  reset: reset$o,
519
547
  start: start$D,
520
- stop: stop$z
548
+ stop: stop$A
521
549
  });
522
550
 
523
551
  var data$g = null;
524
552
  function start$C() {
525
553
  data$g = {};
526
554
  }
527
- function stop$y() {
555
+ function stop$z() {
528
556
  data$g = {};
529
557
  }
530
558
  function track$6(event, time) {
@@ -557,7 +585,7 @@ var summary = /*#__PURE__*/Object.freeze({
557
585
  get data () { return data$g; },
558
586
  reset: reset$n,
559
587
  start: start$C,
560
- stop: stop$y,
588
+ stop: stop$z,
561
589
  track: track$6
562
590
  });
563
591
 
@@ -586,7 +614,7 @@ function upgrade(key) {
586
614
  encode$1(3 /* Event.Upgrade */);
587
615
  }
588
616
  }
589
- function stop$x() {
617
+ function stop$y() {
590
618
  data$f = null;
591
619
  }
592
620
 
@@ -594,7 +622,7 @@ var upgrade$1 = /*#__PURE__*/Object.freeze({
594
622
  __proto__: null,
595
623
  get data () { return data$f; },
596
624
  start: start$B,
597
- stop: stop$x,
625
+ stop: stop$y,
598
626
  upgrade: upgrade
599
627
  });
600
628
 
@@ -634,7 +662,7 @@ function compute$9() {
634
662
  function reset$m() {
635
663
  data$e = {};
636
664
  }
637
- function stop$w() {
665
+ function stop$x() {
638
666
  reset$m();
639
667
  }
640
668
 
@@ -646,7 +674,7 @@ var variable = /*#__PURE__*/Object.freeze({
646
674
  reset: reset$m,
647
675
  set: set,
648
676
  start: start$A,
649
- stop: stop$w
677
+ stop: stop$x
650
678
  });
651
679
 
652
680
  /******************************************************************************
@@ -766,13 +794,13 @@ function start$z() {
766
794
  start$E();
767
795
  modules$1.forEach(function (x) { return measure(x.start)(); });
768
796
  }
769
- function stop$v() {
797
+ function stop$w() {
770
798
  // Stop modules in the reverse order of their initialization
771
799
  // The ordering below should respect inter-module dependency.
772
800
  // E.g. if upgrade depends on upload, then upgrade needs to end before upload.
773
801
  // Similarly, if upload depends on metadata, upload needs to end before metadata.
774
802
  modules$1.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
775
- stop$A();
803
+ stop$B();
776
804
  }
777
805
  function compute$8() {
778
806
  compute$9();
@@ -922,7 +950,7 @@ function start$x() {
922
950
  reset$k();
923
951
  parse$1(document, true);
924
952
  }
925
- function stop$u() {
953
+ function stop$v() {
926
954
  reset$k();
927
955
  }
928
956
  function reset$k() {
@@ -1269,7 +1297,7 @@ var dom = /*#__PURE__*/Object.freeze({
1269
1297
  parse: parse$1,
1270
1298
  sameorigin: sameorigin,
1271
1299
  start: start$x,
1272
- stop: stop$u,
1300
+ stop: stop$v,
1273
1301
  update: update$1,
1274
1302
  updates: updates$2
1275
1303
  });
@@ -1380,7 +1408,7 @@ function restart$2(timer) {
1380
1408
  tracker[id].yield = y;
1381
1409
  }
1382
1410
  }
1383
- function stop$t(timer) {
1411
+ function stop$u(timer) {
1384
1412
  var end = performance.now();
1385
1413
  var id = key(timer);
1386
1414
  var duration = end - tracker[id].start;
@@ -1400,7 +1428,7 @@ function suspend$1(timer) {
1400
1428
  case 0:
1401
1429
  id = key(timer);
1402
1430
  if (!(id in tracker)) return [3 /*break*/, 2];
1403
- stop$t(timer);
1431
+ stop$u(timer);
1404
1432
  _a = tracker[id];
1405
1433
  return [4 /*yield*/, wait()];
1406
1434
  case 1:
@@ -1543,7 +1571,7 @@ function compute$7() {
1543
1571
  encode$4(8 /* Event.Document */);
1544
1572
  }
1545
1573
  }
1546
- function end() {
1574
+ function stop$t() {
1547
1575
  reset$i();
1548
1576
  }
1549
1577
 
@@ -1678,7 +1706,7 @@ function str$1(input) {
1678
1706
  return input.toString(36);
1679
1707
  }
1680
1708
  function attribute(key, value, privacy) {
1681
- return "".concat(key, "=").concat(text$1(value, key, privacy));
1709
+ return "".concat(key, "=").concat(text$1(value, key.indexOf("data-" /* Constant.DataAttribute */) === 0 ? "data-" /* Constant.DataAttribute */ : key, privacy));
1682
1710
  }
1683
1711
 
1684
1712
  var state$8 = [];
@@ -1851,7 +1879,7 @@ function stop$r() {
1851
1879
  reset$g();
1852
1880
  }
1853
1881
 
1854
- function offset (element) {
1882
+ function offset(element) {
1855
1883
  var output = { x: 0, y: 0 };
1856
1884
  // Walk up the chain to ensure we compute offset distance correctly
1857
1885
  // In case where we may have nested IFRAMEs, we keep walking up until we get to the top most parent page
@@ -1924,6 +1952,18 @@ function handler$2(event, root, evt) {
1924
1952
  schedule$1(encode$3.bind(this, event));
1925
1953
  }
1926
1954
  }
1955
+ function link(node) {
1956
+ while (node && node !== document) {
1957
+ if (node.nodeType === Node.ELEMENT_NODE) {
1958
+ var element = node;
1959
+ if (element.tagName === "A") {
1960
+ return element;
1961
+ }
1962
+ }
1963
+ node = node.parentNode;
1964
+ }
1965
+ return null;
1966
+ }
1927
1967
  function text(element) {
1928
1968
  var output = null;
1929
1969
  if (element) {
@@ -2563,7 +2603,7 @@ function processNode (node, source) {
2563
2603
  case "HEAD":
2564
2604
  var head = { tag: tag, attributes: attributes };
2565
2605
  var l = insideFrame && ((_a = node.ownerDocument) === null || _a === void 0 ? void 0 : _a.location) ? node.ownerDocument.location : location;
2566
- head.attributes["*B" /* Constant.Base */] = l.protocol + "//" + l.hostname + l.pathname;
2606
+ head.attributes["*B" /* Constant.Base */] = l.protocol + "//" + l.host + l.pathname;
2567
2607
  dom[call](node, parent, head, source);
2568
2608
  break;
2569
2609
  case "BASE":
@@ -2573,7 +2613,7 @@ function processNode (node, source) {
2573
2613
  // We create "a" element so we can generate protocol and hostname for relative paths like "/path/"
2574
2614
  var a = document.createElement("a");
2575
2615
  a.href = attributes["href"];
2576
- baseHead.data.attributes["*B" /* Constant.Base */] = a.protocol + "//" + a.hostname + a.pathname;
2616
+ baseHead.data.attributes["*B" /* Constant.Base */] = a.protocol + "//" + a.host + a.pathname;
2577
2617
  }
2578
2618
  break;
2579
2619
  case "STYLE":
@@ -2661,7 +2701,7 @@ function getAttributes(element) {
2661
2701
 
2662
2702
  function traverse (root, timer, source) {
2663
2703
  return __awaiter(this, void 0, void 0, function () {
2664
- var queue, node, next, state, subnode;
2704
+ var queue, entry, next, state, subnode;
2665
2705
  return __generator(this, function (_a) {
2666
2706
  switch (_a.label) {
2667
2707
  case 0:
@@ -2669,8 +2709,8 @@ function traverse (root, timer, source) {
2669
2709
  _a.label = 1;
2670
2710
  case 1:
2671
2711
  if (!(queue.length > 0)) return [3 /*break*/, 4];
2672
- node = queue.shift();
2673
- next = node.firstChild;
2712
+ entry = queue.shift();
2713
+ next = entry.firstChild;
2674
2714
  while (next) {
2675
2715
  queue.push(next);
2676
2716
  next = next.nextSibling;
@@ -2685,7 +2725,7 @@ function traverse (root, timer, source) {
2685
2725
  if (state === 2 /* Task.Stop */) {
2686
2726
  return [3 /*break*/, 4];
2687
2727
  }
2688
- subnode = processNode(node, source);
2728
+ subnode = processNode(entry, source);
2689
2729
  if (subnode) {
2690
2730
  queue.push(subnode);
2691
2731
  }
@@ -2868,7 +2908,7 @@ function process$1() {
2868
2908
  _b.sent();
2869
2909
  return [3 /*break*/, 1];
2870
2910
  case 8:
2871
- stop$t(timer);
2911
+ stop$u(timer);
2872
2912
  return [2 /*return*/];
2873
2913
  }
2874
2914
  });
@@ -3000,18 +3040,6 @@ function target(evt) {
3000
3040
  active$2(); // Mark active periods of time so mutations can continue uninterrupted
3001
3041
  return node.nodeType === Node.DOCUMENT_NODE ? node.documentElement : node;
3002
3042
  }
3003
- function link(node) {
3004
- while (node && node !== document) {
3005
- if (node.nodeType === Node.ELEMENT_NODE) {
3006
- var element = node;
3007
- if (element.tagName === "A") {
3008
- return element;
3009
- }
3010
- }
3011
- node = node.parentNode;
3012
- }
3013
- return null;
3014
- }
3015
3043
  function metadata$2(node, event, text) {
3016
3044
  if (text === void 0) { text = null; }
3017
3045
  // If the node is null, we return a reserved value for id: 0. Valid assignment of id begins from 1+.
@@ -3070,7 +3098,7 @@ function encode$3 (type, ts) {
3070
3098
  entry = _c[_b];
3071
3099
  cTarget = metadata$2(entry.data.target, entry.event, entry.data.text);
3072
3100
  tokens = [entry.time, entry.event];
3073
- cHash = cTarget.hash.join("." /* Constant.Dot */);
3101
+ cHash = cTarget.hash ? cTarget.hash.join("." /* Constant.Dot */) : "" /* Constant.Empty */;
3074
3102
  tokens.push(cTarget.id);
3075
3103
  tokens.push(entry.data.x);
3076
3104
  tokens.push(entry.data.y);
@@ -3290,6 +3318,7 @@ function queue(tokens, transmit) {
3290
3318
  discoverBytes += event_1.length;
3291
3319
  case 37 /* Event.Box */:
3292
3320
  case 6 /* Event.Mutation */:
3321
+ case 43 /* Event.Snapshot */:
3293
3322
  playbackBytes += event_1.length;
3294
3323
  playback.push(event_1);
3295
3324
  break;
@@ -3385,7 +3414,7 @@ function send(payload, zipped, sequence, beacon) {
3385
3414
  if (beacon === void 0) { beacon = false; }
3386
3415
  // Upload data if a valid URL is defined in the config
3387
3416
  if (typeof config$1.upload === "string" /* Constant.String */) {
3388
- var url = config$1.upload;
3417
+ var url_1 = config$1.upload;
3389
3418
  var dispatched = false;
3390
3419
  // If it's the last payload, attempt to upload using sendBeacon first.
3391
3420
  // The advantage to using sendBeacon is that browser can decide to upload asynchronously, improving chances of success
@@ -3394,7 +3423,7 @@ function send(payload, zipped, sequence, beacon) {
3394
3423
  if (beacon && "sendBeacon" in navigator) {
3395
3424
  try {
3396
3425
  // Navigator needs to be bound to sendBeacon before it is used to avoid errors in some browsers
3397
- dispatched = navigator.sendBeacon.bind(navigator)(url, payload);
3426
+ dispatched = navigator.sendBeacon.bind(navigator)(url_1, payload);
3398
3427
  if (dispatched) {
3399
3428
  done(sequence);
3400
3429
  }
@@ -3416,7 +3445,9 @@ function send(payload, zipped, sequence, beacon) {
3416
3445
  transit[sequence] = { data: payload, attempts: 1 };
3417
3446
  }
3418
3447
  var xhr_1 = new XMLHttpRequest();
3419
- xhr_1.open("POST", url);
3448
+ xhr_1.open("POST", url_1, true);
3449
+ xhr_1.timeout = 15000 /* Setting.UploadTimeout */;
3450
+ xhr_1.ontimeout = function () { report(new Error("".concat("Timeout" /* Constant.Timeout */, " : ").concat(url_1))); };
3420
3451
  if (sequence !== null) {
3421
3452
  xhr_1.onreadystatechange = function () { measure(check$3)(xhr_1, sequence); };
3422
3453
  }
@@ -4261,7 +4292,7 @@ function report(e) {
4261
4292
  // Using POST request instead of a GET request (img-src) to not violate existing CSP rules
4262
4293
  // Since, Clarity already uses XHR to upload data, we stick with similar POST mechanism for reporting too
4263
4294
  var xhr = new XMLHttpRequest();
4264
- xhr.open("POST", url);
4295
+ xhr.open("POST", url, true);
4265
4296
  xhr.send(JSON.stringify(payload));
4266
4297
  history$1.push(e.message);
4267
4298
  }
@@ -4383,7 +4414,7 @@ function stop$5() {
4383
4414
  reset$2();
4384
4415
  reset$1();
4385
4416
  reset$j();
4386
- stop$C();
4417
+ stop$D();
4387
4418
  status = false;
4388
4419
  }
4389
4420
  function active() {
@@ -4472,7 +4503,7 @@ function discover() {
4472
4503
  return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
4473
4504
  case 2:
4474
4505
  _a.sent();
4475
- stop$t(timer);
4506
+ stop$u(timer);
4476
4507
  return [2 /*return*/];
4477
4508
  }
4478
4509
  });
@@ -4490,9 +4521,9 @@ function start$3() {
4490
4521
  }
4491
4522
  function stop$3() {
4492
4523
  stop$s();
4493
- stop$u();
4524
+ stop$v();
4494
4525
  stop$f();
4495
- end();
4526
+ stop$t();
4496
4527
  }
4497
4528
 
4498
4529
  var layout = /*#__PURE__*/Object.freeze({
@@ -4661,7 +4692,7 @@ function stop$2() {
4661
4692
  function host(url) {
4662
4693
  var a = document.createElement("a");
4663
4694
  a.href = url;
4664
- return a.hostname;
4695
+ return a.host;
4665
4696
  }
4666
4697
 
4667
4698
  function start$1() {
@@ -4717,7 +4748,7 @@ function stop() {
4717
4748
  if (active()) {
4718
4749
  // Stop modules in the reverse order of their initialization and start queuing up items again
4719
4750
  modules.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
4720
- stop$v();
4751
+ stop$w();
4721
4752
  stop$5();
4722
4753
  setup();
4723
4754
  }