core-outline 1.1.16 → 1.1.18

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/.babelrc CHANGED
@@ -1,6 +1,3 @@
1
- {
2
- "presets": [
3
- "@babel/preset-env",
4
- "@babel/preset-react"
5
- ]
6
- }
1
+ {
2
+ "presets": ["@babel/preset-env", "@babel/preset-react"]
3
+ }
package/dist/index.es.js CHANGED
@@ -6347,7 +6347,7 @@ Object.assign(lookup, {
6347
6347
  connect: lookup,
6348
6348
  });
6349
6349
 
6350
- var socket = lookup('http://localhost:8000');
6350
+ var socket = lookup('http://streams.coreoutline.com');
6351
6351
 
6352
6352
  var CoreOutline = function CoreOutline(_ref) {
6353
6353
  var children = _ref.children,
@@ -6377,7 +6377,7 @@ var CoreOutline = function CoreOutline(_ref) {
6377
6377
  _useState10 = _slicedToArray(_useState9, 2),
6378
6378
  browser = _useState10[0];
6379
6379
  _useState10[1];
6380
- var _useState11 = useState(""),
6380
+ var _useState11 = useState(''),
6381
6381
  _useState12 = _slicedToArray(_useState11, 2);
6382
6382
  _useState12[0];
6383
6383
  var setAppToken = _useState12[1];
@@ -6395,22 +6395,22 @@ var CoreOutline = function CoreOutline(_ref) {
6395
6395
  while (1) switch (_context2.prev = _context2.next) {
6396
6396
  case 0:
6397
6397
  requestOptions = {
6398
- method: "POST",
6398
+ method: 'POST',
6399
6399
  headers: {
6400
- "Content-Type": "application/json"
6400
+ 'Content-Type': 'application/json'
6401
6401
  },
6402
6402
  body: JSON.stringify({
6403
6403
  data_source_id: data_source_id,
6404
6404
  data_source_secret: data_source_secret
6405
6405
  })
6406
6406
  };
6407
- response = fetch("http://localhost:4000/data-source/authorize", requestOptions).then(function (response) {
6407
+ response = fetch("http://api.coreoutline.com/data-source/authorize", requestOptions).then(function (response) {
6408
6408
  return response.json();
6409
6409
  }).then(function (data) {
6410
6410
  setAppToken(data.app_token);
6411
6411
  return data;
6412
6412
  })["catch"](function (error) {
6413
- console.error("Error:", error);
6413
+ console.error('Error:', error);
6414
6414
  return error;
6415
6415
  });
6416
6416
  return _context2.abrupt("return", response);
@@ -6422,39 +6422,88 @@ var CoreOutline = function CoreOutline(_ref) {
6422
6422
  }));
6423
6423
  return _authorizeApp.apply(this, arguments);
6424
6424
  }
6425
+ var offLoadFunctionality = function offLoadFunctionality() {
6426
+ var formattedEvents = events && events.length > 0 ? events : JSON.parse(localStorage.getItem('coreoutlineFormattedEvents') || '[]');
6427
+ var rawEvents = replayEvents && replayEvents.length > 0 ? replayEvents : JSON.parse(localStorage.getItem('coreoutlineRawEvents') || '[]');
6428
+ var data = JSON.stringify({
6429
+ data_source_id: data_source_id,
6430
+ sessionId: sessionId,
6431
+ formatted_events: formattedEvents,
6432
+ raw_events: rawEvents
6433
+ });
6434
+ socket.send({
6435
+ topic: 'session-data',
6436
+ data_source_id: data_source_id,
6437
+ session_id: localStorage.getItem('coreOutlineSessionId'),
6438
+ start_date: new Date().toLocaleString(),
6439
+ latitude: location.latitude,
6440
+ longitude: location.longitude,
6441
+ browser: browser,
6442
+ event_id: 'SESSION_END'
6443
+ });
6444
+ if (navigator.sendBeacon) {
6445
+ navigator.sendBeacon("http://data.coreoutline.com/upload-events", data);
6446
+ } else {
6447
+ fetch("http://data.coreoutline.com/upload-events", {
6448
+ method: 'POST',
6449
+ body: data,
6450
+ keepalive: true,
6451
+ headers: {
6452
+ 'Content-Type': 'application/json'
6453
+ }
6454
+ })["catch"](function (err) {
6455
+ return console.error('Upload failed:', err);
6456
+ });
6457
+ }
6458
+ };
6459
+ useEffect(function () {}, [events, replayEvents]);
6425
6460
  useEffect(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
6461
+ var handleBeforeUnload, handleVisibilityChange;
6426
6462
  return _regeneratorRuntime().wrap(function _callee$(_context) {
6427
6463
  while (1) switch (_context.prev = _context.next) {
6428
6464
  case 0:
6429
- _context.next = 2;
6465
+ handleBeforeUnload = function handleBeforeUnload() {
6466
+ offLoadFunctionality();
6467
+ };
6468
+ handleVisibilityChange = function handleVisibilityChange() {
6469
+ if (document.visibilityState === 'hidden') {
6470
+ offLoadFunctionality();
6471
+ }
6472
+ };
6473
+ window.addEventListener('beforeunload', handleBeforeUnload);
6474
+ document.addEventListener('visibilitychange', handleVisibilityChange);
6475
+ _context.next = 6;
6430
6476
  return authorizeApp(data_source_id, data_source_secret);
6431
- case 2:
6432
- localStorage.setItem("coreOutlineSessionId", sessionId);
6433
- localStorage.setItem("coreOutlineDataSourceIdId", data_source_id);
6434
- console.log("Session", sessionId);
6477
+ case 6:
6478
+ localStorage.setItem('coreOutlineSessionId', sessionId);
6479
+ localStorage.setItem('coreOutlineDataSourceIdId', data_source_id);
6480
+ console.log('Session', sessionId);
6435
6481
  socket.send({
6436
- topic: "session-data",
6482
+ topic: 'session-data',
6437
6483
  data_source_id: data_source_id,
6438
- session_id: localStorage.getItem("coreOutlineSessionId"),
6484
+ session_id: localStorage.getItem('coreOutlineSessionId'),
6439
6485
  start_date: new Date().toLocaleString(),
6440
6486
  latitude: location.latitude,
6441
6487
  longitude: location.longitude,
6442
6488
  browser: browser,
6443
- event_id: "SESSION_START"
6489
+ event_id: 'SESSION_START'
6444
6490
  });
6445
6491
  return _context.abrupt("return", function () {
6492
+ offLoadFunctionality();
6493
+ window.removeEventListener('beforeunload', handleBeforeUnload);
6494
+ document.removeEventListener('visibilitychange', handleVisibilityChange);
6446
6495
  socket.send({
6447
- topic: "session-data",
6496
+ topic: 'session-data',
6448
6497
  data_source_id: data_source_id,
6449
- session_id: localStorage.getItem("coreOutlineSessionId"),
6498
+ session_id: localStorage.getItem('coreOutlineSessionId'),
6450
6499
  start_date: new Date().toLocaleString(),
6451
6500
  latitude: location.latitude,
6452
6501
  longitude: location.longitude,
6453
6502
  browser: browser,
6454
- event_id: "SESSION_END"
6503
+ event_id: 'SESSION_END'
6455
6504
  });
6456
6505
  });
6457
- case 7:
6506
+ case 11:
6458
6507
  case "end":
6459
6508
  return _context.stop();
6460
6509
  }
@@ -6488,22 +6537,24 @@ var CoreOutline = function CoreOutline(_ref) {
6488
6537
  setEvents(function (prevEvents) {
6489
6538
  return [].concat(_toConsumableArray(prevEvents), [navigationEvent]);
6490
6539
  });
6540
+ localStorage.setItem('coreoutlineFormattedEvents', JSON.stringify(function (prevEvents) {
6541
+ return [].concat(_toConsumableArray(prevEvents), [navigationEvent]);
6542
+ }));
6491
6543
  var handleNavigation = function handleNavigation() {
6492
6544
  setCurrentPage(window.location.href);
6493
6545
  socket.send({
6494
- topic: "session-data",
6546
+ topic: 'session-data',
6495
6547
  data_source_id: data_source_id,
6496
- session_id: localStorage.getItem("coreOutlineSessionId"),
6548
+ session_id: localStorage.getItem('coreOutlineSessionId'),
6497
6549
  start_date: new Date().toLocaleString(),
6498
6550
  latitude: location.latitude,
6499
6551
  longitude: location.longitude,
6500
6552
  browser: browser,
6501
6553
  page_name: window.location.href,
6502
- event_id: "PAGE_NAVIGATION"
6554
+ event_id: 'PAGE_NAVIGATION'
6503
6555
  });
6504
- saveEvents(events);
6505
6556
  };
6506
- window.addEventListener("popstate", handleNavigation);
6557
+ window.addEventListener('popstate', handleNavigation);
6507
6558
  var originalPushState = window.history.pushState;
6508
6559
  window.history.pushState = function () {
6509
6560
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -6513,12 +6564,12 @@ var CoreOutline = function CoreOutline(_ref) {
6513
6564
  handleNavigation();
6514
6565
  };
6515
6566
  return function () {
6516
- window.removeEventListener("popstate", handleNavigation);
6567
+ window.removeEventListener('popstate', handleNavigation);
6517
6568
  window.history.pushState = originalPushState;
6518
6569
  };
6519
6570
  }, [currentPage]);
6520
6571
  useEffect(function () {
6521
- console.log("Location", location);
6572
+ console.log('Location', location);
6522
6573
  getLocation();
6523
6574
  }, []);
6524
6575
  useEffect(function () {
@@ -6529,6 +6580,9 @@ var CoreOutline = function CoreOutline(_ref) {
6529
6580
  setReplayEvents(function (prevEvents) {
6530
6581
  return [].concat(_toConsumableArray(prevEvents), [event]);
6531
6582
  });
6583
+ localStorage.setItem('coreoutlineRawEvents', JSON.stringify(function (prevEvents) {
6584
+ return [].concat(_toConsumableArray(replayEvents), [event]);
6585
+ }));
6532
6586
  },
6533
6587
  maskAllInputs: false,
6534
6588
  maskTextSelector: null
@@ -6538,7 +6592,6 @@ var CoreOutline = function CoreOutline(_ref) {
6538
6592
  return function () {
6539
6593
  if (stopFn) {
6540
6594
  stopFn();
6541
- saveEvents(events);
6542
6595
  recorderActive.current = false;
6543
6596
  }
6544
6597
  };
@@ -6548,7 +6601,7 @@ var CoreOutline = function CoreOutline(_ref) {
6548
6601
  if (!recorderActive.current) {
6549
6602
  stopFn = record({
6550
6603
  emit: function emit(event) {
6551
- console.log("Event:", event);
6604
+ console.log('Event:', event);
6552
6605
  if (event.type == 3 && event.data.type == 2) {
6553
6606
  return;
6554
6607
  }
@@ -6562,11 +6615,14 @@ var CoreOutline = function CoreOutline(_ref) {
6562
6615
  return;
6563
6616
  }
6564
6617
  if (event.type == 3 && event.data.type == 3) {
6565
- console.log("Contextmenu Event:", event);
6618
+ console.log('Contextmenu Event:', event);
6566
6619
  }
6567
6620
  setEvents(function (prevEvents) {
6568
6621
  return [].concat(_toConsumableArray(prevEvents), [event]);
6569
6622
  });
6623
+ localStorage.setItem('coreoutlineFormattedEvents', JSON.stringify(function (prevEvents) {
6624
+ return [].concat(_toConsumableArray(prevEvents), [event]);
6625
+ }));
6570
6626
  },
6571
6627
  maskAllInputs: false,
6572
6628
  maskTextSelector: null
@@ -6576,14 +6632,13 @@ var CoreOutline = function CoreOutline(_ref) {
6576
6632
  return function () {
6577
6633
  if (stopFn) {
6578
6634
  stopFn();
6579
- saveEvents(events);
6580
6635
  recorderActive.current = false;
6581
6636
  }
6582
6637
  };
6583
6638
  }, []);
6584
6639
  useEffect(function () {
6585
6640
  var handleClick = function handleClick(event) {
6586
- console.log("Inner text:", event.target.innerText);
6641
+ console.log('Inner text:', event.target.innerText);
6587
6642
  var clickEvent = {
6588
6643
  type: EventType.IncrementalSnapshot,
6589
6644
  data: {
@@ -6598,11 +6653,11 @@ var CoreOutline = function CoreOutline(_ref) {
6598
6653
  var clickedElement = document.elementFromPoint(clickEvent.data.x, clickEvent.data.y);
6599
6654
  if (clickedElement) {
6600
6655
  clickEvent.data.metadata = {
6601
- label: clickedElement.getAttribute("data-label") || clickedElement.innerText || null,
6602
- value: clickedElement.getAttribute("value") || clickedElement.innerText || null,
6603
- id: clickedElement.getAttribute("id") || clickedElement.innerText || null,
6604
- name: clickedElement.getAttribute("name") || clickedElement.innerText || null,
6605
- "class": clickedElement.getAttribute("class") || clickedElement.innerText || null,
6656
+ label: clickedElement.getAttribute('data-label') || clickedElement.innerText || null,
6657
+ value: clickedElement.getAttribute('value') || clickedElement.innerText || null,
6658
+ id: clickedElement.getAttribute('id') || clickedElement.innerText || null,
6659
+ name: clickedElement.getAttribute('name') || clickedElement.innerText || null,
6660
+ "class": clickedElement.getAttribute('class') || clickedElement.innerText || null,
6606
6661
  tag: clickedElement.tagName,
6607
6662
  html: String(clickedElement.getHTML()),
6608
6663
  innerText: event.target.innerText
@@ -6611,52 +6666,40 @@ var CoreOutline = function CoreOutline(_ref) {
6611
6666
  setEvents(function (prevEvents) {
6612
6667
  return [].concat(_toConsumableArray(prevEvents), [clickEvent]);
6613
6668
  });
6669
+ localStorage.setItem('coreoutlineFormattedEvents', JSON.stringify(function (prevEvents) {
6670
+ return [].concat(_toConsumableArray(prevEvents), [clickEvent]);
6671
+ }));
6614
6672
  socket.send({
6615
- topic: "session-data",
6673
+ topic: 'session-data',
6616
6674
  data_source_id: data_source_id,
6617
- session_id: localStorage.getItem("coreOutlineSessionId"),
6675
+ session_id: localStorage.getItem('coreOutlineSessionId'),
6618
6676
  start_date: new Date().toLocaleString(),
6619
6677
  latitude: location.latitude,
6620
6678
  longitude: location.longitude,
6621
6679
  browser: browser,
6622
- event_id: "ITEM_CLICKED"
6680
+ event_id: 'ITEM_CLICKED'
6623
6681
  // item_clicked: event.target,
6624
6682
  });
6625
6683
  };
6626
- document.addEventListener("click", handleClick);
6684
+ document.addEventListener('click', handleClick);
6627
6685
  return function () {
6628
- document.removeEventListener("click", handleClick);
6686
+ document.removeEventListener('click', handleClick);
6629
6687
  };
6630
6688
  }, []);
6631
- function saveEvents(events) {
6632
- var requestOptions = {
6633
- method: "PUT",
6634
- headers: {
6635
- "Content-Type": "application/json"
6636
- },
6637
- body: JSON.stringify(events)
6638
- };
6639
- fetch("http://localhost:5000/generate-s3-url/".concat(data_source_id, "/").concat(sessionId)).then(function (response) {
6640
- return response.json();
6641
- }).then(function (data) {
6642
- var uploadURL = data.signed_url;
6643
- return fetch(uploadURL, requestOptions);
6644
- });
6645
- }
6646
6689
  function saveEventsLocally() {
6647
- var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "formatted" ;
6648
- var blob = "";
6649
- if (type === "formatted") {
6690
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'formatted' ;
6691
+ var blob = '';
6692
+ if (type === 'formatted') {
6650
6693
  blob = new Blob([JSON.stringify(events, null, 2)], {
6651
- type: "application/json"
6694
+ type: 'application/json'
6652
6695
  });
6653
- } else if (type === "raw") {
6696
+ } else if (type === 'raw') {
6654
6697
  blob = new Blob([JSON.stringify(replayEvents, null, 2)], {
6655
- type: "application/json"
6698
+ type: 'application/json'
6656
6699
  });
6657
6700
  }
6658
6701
  var url = URL.createObjectURL(blob);
6659
- var a = document.createElement("a");
6702
+ var a = document.createElement('a');
6660
6703
  a.href = url;
6661
6704
  a.download = "".concat(type, "_events.json");
6662
6705
  a.click();
@@ -6664,17 +6707,17 @@ var CoreOutline = function CoreOutline(_ref) {
6664
6707
  }
6665
6708
  function getBrowserInfo() {
6666
6709
  var userAgent = navigator.userAgent;
6667
- var browserName = "Unknown";
6668
- if (userAgent.indexOf("Firefox") > -1) {
6669
- browserName = "Firefox";
6670
- } else if (userAgent.indexOf("Opera") > -1 || userAgent.indexOf("OPR") > -1) {
6671
- browserName = "Opera";
6672
- } else if (userAgent.indexOf("Chrome") > -1) {
6673
- browserName = "Chrome";
6674
- } else if (userAgent.indexOf("Safari") > -1) {
6675
- browserName = "Safari";
6676
- } else if (userAgent.indexOf("MSIE") > -1 || userAgent.indexOf("Trident/") > -1) {
6677
- browserName = "Internet Explorer";
6710
+ var browserName = 'Unknown';
6711
+ if (userAgent.indexOf('Firefox') > -1) {
6712
+ browserName = 'Firefox';
6713
+ } else if (userAgent.indexOf('Opera') > -1 || userAgent.indexOf('OPR') > -1) {
6714
+ browserName = 'Opera';
6715
+ } else if (userAgent.indexOf('Chrome') > -1) {
6716
+ browserName = 'Chrome';
6717
+ } else if (userAgent.indexOf('Safari') > -1) {
6718
+ browserName = 'Safari';
6719
+ } else if (userAgent.indexOf('MSIE') > -1 || userAgent.indexOf('Trident/') > -1) {
6720
+ browserName = 'Internet Explorer';
6678
6721
  }
6679
6722
  return browserName;
6680
6723
  }
@@ -6686,53 +6729,53 @@ var CoreOutline = function CoreOutline(_ref) {
6686
6729
  longitude: position.coords.longitude
6687
6730
  });
6688
6731
  }, function (error) {
6689
- console.error("Error getting location:", error);
6732
+ console.error('Error getting location:', error);
6690
6733
  });
6691
6734
  } else {
6692
- console.error("Geolocation is not supported by this browser.");
6735
+ console.error('Geolocation is not supported by this browser.');
6693
6736
  }
6694
6737
  }
6695
6738
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
6696
6739
  onClick: function onClick() {
6697
- saveEventsLocally("formatted");
6698
- saveEventsLocally("raw");
6740
+ saveEventsLocally('formatted');
6741
+ saveEventsLocally('raw');
6699
6742
  }
6700
6743
  }, "Save Events Locally"), children);
6701
6744
  };
6702
6745
  var flag_item_clicked = function flag_item_clicked(item_id) {
6703
- var sessionId = localStorage.getItem("coreOutlineSessionId");
6704
- var dataSourceId = localStorage.getItem("coreOutlineDataSourceIdId");
6705
- console.log("Session", sessionId);
6706
- console.log("Data Source", dataSourceId);
6746
+ var sessionId = localStorage.getItem('coreOutlineSessionId');
6747
+ var dataSourceId = localStorage.getItem('coreOutlineDataSourceIdId');
6748
+ console.log('Session', sessionId);
6749
+ console.log('Data Source', dataSourceId);
6707
6750
  socket.send({
6708
- topic: "session-data",
6751
+ topic: 'session-data',
6709
6752
  data_source_id: dataSourceId,
6710
- session_id: localStorage.getItem("coreOutlineSessionId"),
6753
+ session_id: localStorage.getItem('coreOutlineSessionId'),
6711
6754
  start_date: new Date().toLocaleString(),
6712
- event_id: "PRODUCT_CLICKED",
6755
+ event_id: 'PRODUCT_CLICKED',
6713
6756
  item_clicked: item_id
6714
6757
  });
6715
6758
  return {
6716
- status: "success",
6717
- message: "Item click flagged successfully."
6759
+ status: 'success',
6760
+ message: 'Item click flagged successfully.'
6718
6761
  };
6719
6762
  };
6720
6763
  var flag_item_purchased = function flag_item_purchased(item_id) {
6721
- var sessionId = localStorage.getItem("coreOutlineSessionId");
6722
- var dataSourceId = localStorage.getItem("coreOutlineDataSourceIdId");
6723
- console.log("Session", sessionId);
6724
- console.log("Data Source", dataSourceId);
6764
+ var sessionId = localStorage.getItem('coreOutlineSessionId');
6765
+ var dataSourceId = localStorage.getItem('coreOutlineDataSourceIdId');
6766
+ console.log('Session', sessionId);
6767
+ console.log('Data Source', dataSourceId);
6725
6768
  socket.send({
6726
- topic: "session-data",
6769
+ topic: 'session-data',
6727
6770
  data_source_id: dataSourceId,
6728
- session_id: localStorage.getItem("coreOutlineSessionId"),
6771
+ session_id: localStorage.getItem('coreOutlineSessionId'),
6729
6772
  start_date: new Date().toLocaleString(),
6730
- event_id: "PRODUCT_PURCHASED",
6773
+ event_id: 'PRODUCT_PURCHASED',
6731
6774
  item_clicked: item_id
6732
6775
  });
6733
6776
  return {
6734
- status: "success",
6735
- message: "Item purchase flagged successfully."
6777
+ status: 'success',
6778
+ message: 'Item purchase flagged successfully.'
6736
6779
  };
6737
6780
  };
6738
6781