@datarangers/sdk-javascript 0.1.3 → 0.1.4

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/es/index.min.js CHANGED
@@ -431,7 +431,10 @@ var cookie = createCommonjsModule(function (module, exports) {
431
431
  });
432
432
 
433
433
  // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
434
- var Memory$1 = /** @class */function () {
434
+ /**
435
+ * cacheStorage
436
+ */
437
+ var Memory = /** @class */function () {
435
438
  function Memory() {
436
439
  this.cache = {};
437
440
  }
@@ -444,36 +447,26 @@ var Memory$1 = /** @class */function () {
444
447
  Memory.prototype.removeItem = function (cacheKey) {
445
448
  this.cache[cacheKey] = undefined;
446
449
  };
447
- Memory.prototype.getCookie = function (name) {
448
- this.getItem(name);
449
- };
450
- Memory.prototype.setCookie = function (key, value) {
451
- this.setItem(key, value);
452
- };
453
450
  return Memory;
454
451
  }();
455
- function isSupportLS() {
456
- try {
457
- localStorage.setItem('_ranger-test-key', 'hi');
458
- localStorage.getItem('_ranger-test-key');
459
- localStorage.removeItem('_ranger-test-key');
460
- return true;
461
- } catch (e) {
462
- return false;
463
- }
464
- }
465
- function isSupportSession() {
466
- try {
467
- sessionStorage.setItem('_ranger-test-key', 'hi');
468
- sessionStorage.getItem('_ranger-test-key');
469
- sessionStorage.removeItem('_ranger-test-key');
470
- return true;
471
- } catch (e) {
472
- return false;
452
+ /**
453
+ * localStorage
454
+ */
455
+ var Local = /** @class */function () {
456
+ function Local() {
457
+ this.support = this.isSupportLS();
473
458
  }
474
- }
475
- var local = {
476
- getItem: function getItem(key) {
459
+ Local.prototype.isSupportLS = function () {
460
+ try {
461
+ localStorage.setItem('_applogtest-test-key', 'hi');
462
+ localStorage.getItem('_applogtest-test-key');
463
+ localStorage.removeItem('_applogtest-test-key');
464
+ return true;
465
+ } catch (e) {
466
+ return false;
467
+ }
468
+ };
469
+ Local.prototype.getItem = function (key) {
477
470
  try {
478
471
  var value = localStorage.getItem(key);
479
472
  var ret = value;
@@ -485,42 +478,38 @@ var local = {
485
478
  return ret || {};
486
479
  } catch (e) {}
487
480
  return {};
488
- },
489
- setItem: function setItem(key, value) {
481
+ };
482
+ Local.prototype.setItem = function (key, value) {
490
483
  try {
491
484
  var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
492
485
  localStorage.setItem(key, stringValue);
493
486
  } catch (e) {}
494
- },
495
- removeItem: function removeItem(key) {
487
+ };
488
+ Local.prototype.removeItem = function (key) {
496
489
  try {
497
490
  localStorage.removeItem(key);
498
491
  } catch (e) {}
499
- },
500
- getCookie: function getCookie(name, domain) {
492
+ };
493
+ return Local;
494
+ }();
495
+ /**
496
+ * sessionStorage
497
+ */
498
+ var Session$1 = /** @class */function () {
499
+ function Session() {
500
+ this.support = this.isSupportSession();
501
+ }
502
+ Session.prototype.isSupportSession = function () {
501
503
  try {
502
- var _matches = cookie.get(name);
503
- return _matches;
504
+ sessionStorage.setItem('_applogtest-test-key', 'hi');
505
+ sessionStorage.getItem('_applogtest-test-key');
506
+ sessionStorage.removeItem('_applogtest-test-key');
507
+ return true;
504
508
  } catch (e) {
505
- return '';
509
+ return false;
506
510
  }
507
- },
508
- setCookie: function setCookie(name, value, expiresTime, domain) {
509
- try {
510
- var _domain = domain || document.domain;
511
- var timestamp = +new Date();
512
- var furureTimestamp = timestamp + expiresTime; // 3年
513
- cookie.set(name, value, {
514
- expires: new Date(furureTimestamp),
515
- path: '/',
516
- domain: _domain
517
- });
518
- } catch (e) {}
519
- },
520
- isSupportLS: isSupportLS()
521
- };
522
- var session = {
523
- getItem: function getItem(key) {
511
+ };
512
+ Session.prototype.getItem = function (key) {
524
513
  try {
525
514
  var value = sessionStorage.getItem(key);
526
515
  var ret = value;
@@ -532,56 +521,92 @@ var session = {
532
521
  return ret || {};
533
522
  } catch (e) {}
534
523
  return {};
535
- },
536
- setItem: function setItem(key, value) {
524
+ };
525
+ Session.prototype.setItem = function (key, value) {
537
526
  try {
538
527
  var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
539
528
  sessionStorage.setItem(key, stringValue);
540
529
  } catch (e) {}
541
- },
542
- removeItem: function removeItem(key) {
530
+ };
531
+ Session.prototype.removeItem = function (key) {
543
532
  try {
544
533
  sessionStorage.removeItem(key);
545
534
  } catch (e) {}
546
- },
547
- getCookie: function getCookie(name) {
548
- this.getItem(name);
549
- },
550
- setCookie: function setCookie(key, value) {
551
- this.setItem(key, value);
552
- },
553
- isSupportSession: isSupportSession()
554
- };
555
- var Storage = /** @class */function () {
556
- function Storage(isCache, type) {
557
- if (type && type === 'session') {
558
- this._storage = session;
559
- } else {
560
- this._storage = !isCache && local.isSupportLS ? local : new Memory$1();
561
- }
535
+ };
536
+ return Session;
537
+ }();
538
+ var StorageManager = /** @class */function () {
539
+ function StorageManager() {
540
+ this.defaultExpireTime = 7 * 1000 * 60 * 60 * 24;
541
+ this.local = new Local();
542
+ this.session = new Session$1();
543
+ this.cache = new Memory();
562
544
  }
563
- Storage.prototype.getItem = function (key) {
564
- return this._storage.getItem(key);
545
+ StorageManager.prototype.getLocalItem = function (key) {
546
+ return this.local.getItem(key);
565
547
  };
566
- Storage.prototype.setItem = function (key, value) {
567
- this._storage.setItem(key, value);
548
+ StorageManager.prototype.setLocalItem = function (key, value) {
549
+ this.local.setItem(key, value);
568
550
  };
569
- Storage.prototype.getCookie = function (name, domain) {
570
- return this._storage.getCookie(name, domain);
551
+ StorageManager.prototype.removeLocalItem = function (key) {
552
+ this.local.removeItem(key);
571
553
  };
572
- Storage.prototype.setCookie = function (key, value, expiresTime, domain) {
573
- this._storage.setCookie(key, value, expiresTime, domain);
554
+ StorageManager.prototype.getSessionItem = function (key) {
555
+ return this.session.getItem(key);
574
556
  };
575
- Storage.prototype.removeItem = function (key) {
576
- this._storage.removeItem(key);
557
+ StorageManager.prototype.setSessionItem = function (key, value) {
558
+ this.session.setItem(key, value);
577
559
  };
578
- return Storage;
560
+ StorageManager.prototype.removeSessionItem = function (key) {
561
+ this.session.removeItem(key);
562
+ };
563
+ StorageManager.prototype.getCacheItem = function (key) {
564
+ return this.cache.getItem(key);
565
+ };
566
+ StorageManager.prototype.setCacheItem = function (key, value) {
567
+ this.cache.setItem(key, value);
568
+ };
569
+ StorageManager.prototype.removeCacheItem = function (key) {
570
+ this.cache.removeItem(key);
571
+ };
572
+ StorageManager.prototype.getCookie = function (key, domain) {
573
+ try {
574
+ // const _matches = Cookies.get(name, { domain: domain || document.domain })
575
+ var _matches = cookie.get(key);
576
+ return _matches;
577
+ } catch (e) {
578
+ return '';
579
+ }
580
+ };
581
+ StorageManager.prototype.setCookie = function (key, value, expiresTime, domain) {
582
+ if (expiresTime === void 0) {
583
+ expiresTime = this.defaultExpireTime;
584
+ }
585
+ try {
586
+ var _domain = domain || document.domain;
587
+ var timestamp = +new Date();
588
+ var furureTimestamp = timestamp + expiresTime;
589
+ cookie.set(key, value, {
590
+ expires: new Date(furureTimestamp),
591
+ path: '/',
592
+ domain: _domain
593
+ });
594
+ } catch (e) {}
595
+ };
596
+ StorageManager.prototype.removeCookie = function (key, domain) {
597
+ try {
598
+ cookie.remove(key, {
599
+ path: '/',
600
+ domain: domain || ''
601
+ });
602
+ } catch (e) {}
603
+ };
604
+ return StorageManager;
579
605
  }();
580
606
 
581
607
  // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
582
608
  var UTM = function UTM(app_id, urlQueryObj, domain, cookie_expire) {
583
- var storage = new Storage(false);
584
- var session = new Storage(false, 'session');
609
+ var storage = new StorageManager();
585
610
  var cacheKey = app_id ? "_tea_utm_cache_" + app_id : '_tea_utm_cache';
586
611
  var sourceKey = app_id ? "_$utm_from_url_" + app_id : '_$utm_from_url';
587
612
  var utmObj = {};
@@ -619,7 +644,7 @@ var UTM = function UTM(app_id, urlQueryObj, domain, cookie_expire) {
619
644
  }
620
645
  if (utmFromUrl) {
621
646
  // 发现url上有则更新缓存,并上报
622
- session.setItem(sourceKey, '1');
647
+ storage.setSessionItem(sourceKey, '1');
623
648
  storage.setCookie(cacheKey, JSON.stringify(utmObj), cookie_expire, domain);
624
649
  } else {
625
650
  // url没有则取缓存
@@ -628,7 +653,7 @@ var UTM = function UTM(app_id, urlQueryObj, domain, cookie_expire) {
628
653
  utmObj = JSON.parse(cache);
629
654
  }
630
655
  }
631
- if (session.getItem(sourceKey)) {
656
+ if (storage.getSessionItem(sourceKey)) {
632
657
  if (!utmObj.hasOwnProperty('tracer_data')) {
633
658
  utmObj['tracer_data'] = {};
634
659
  }
@@ -935,180 +960,6 @@ var Client = /** @class */function () {
935
960
  return Client;
936
961
  }();
937
962
 
938
- // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
939
- /**
940
- * cacheStorage
941
- */
942
- var Memory = /** @class */function () {
943
- function Memory() {
944
- this.cache = {};
945
- }
946
- Memory.prototype.setItem = function (cacheKey, data) {
947
- this.cache[cacheKey] = data;
948
- };
949
- Memory.prototype.getItem = function (cacheKey) {
950
- return this.cache[cacheKey];
951
- };
952
- Memory.prototype.removeItem = function (cacheKey) {
953
- this.cache[cacheKey] = undefined;
954
- };
955
- return Memory;
956
- }();
957
- /**
958
- * localStorage
959
- */
960
- var Local = /** @class */function () {
961
- function Local() {
962
- this.support = this.isSupportLS();
963
- }
964
- Local.prototype.isSupportLS = function () {
965
- try {
966
- localStorage.setItem('_applogtest-test-key', 'hi');
967
- localStorage.getItem('_applogtest-test-key');
968
- localStorage.removeItem('_applogtest-test-key');
969
- return true;
970
- } catch (e) {
971
- return false;
972
- }
973
- };
974
- Local.prototype.getItem = function (key) {
975
- try {
976
- var value = localStorage.getItem(key);
977
- var ret = value;
978
- try {
979
- if (value && typeof value === 'string') {
980
- ret = JSON.parse(value);
981
- }
982
- } catch (e) {}
983
- return ret || {};
984
- } catch (e) {}
985
- return {};
986
- };
987
- Local.prototype.setItem = function (key, value) {
988
- try {
989
- var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
990
- localStorage.setItem(key, stringValue);
991
- } catch (e) {}
992
- };
993
- Local.prototype.removeItem = function (key) {
994
- try {
995
- localStorage.removeItem(key);
996
- } catch (e) {}
997
- };
998
- return Local;
999
- }();
1000
- /**
1001
- * sessionStorage
1002
- */
1003
- var Session$1 = /** @class */function () {
1004
- function Session() {
1005
- this.support = this.isSupportSession();
1006
- }
1007
- Session.prototype.isSupportSession = function () {
1008
- try {
1009
- sessionStorage.setItem('_applogtest-test-key', 'hi');
1010
- sessionStorage.getItem('_applogtest-test-key');
1011
- sessionStorage.removeItem('_applogtest-test-key');
1012
- return true;
1013
- } catch (e) {
1014
- return false;
1015
- }
1016
- };
1017
- Session.prototype.getItem = function (key) {
1018
- try {
1019
- var value = sessionStorage.getItem(key);
1020
- var ret = value;
1021
- try {
1022
- if (value && typeof value === 'string') {
1023
- ret = JSON.parse(value);
1024
- }
1025
- } catch (e) {}
1026
- return ret || {};
1027
- } catch (e) {}
1028
- return {};
1029
- };
1030
- Session.prototype.setItem = function (key, value) {
1031
- try {
1032
- var stringValue = typeof value === 'string' ? value : JSON.stringify(value);
1033
- sessionStorage.setItem(key, stringValue);
1034
- } catch (e) {}
1035
- };
1036
- Session.prototype.removeItem = function (key) {
1037
- try {
1038
- sessionStorage.removeItem(key);
1039
- } catch (e) {}
1040
- };
1041
- return Session;
1042
- }();
1043
- var StorageManager = /** @class */function () {
1044
- function StorageManager() {
1045
- this.defaultExpireTime = 7 * 1000 * 60 * 60 * 24;
1046
- this.local = new Local();
1047
- this.session = new Session$1();
1048
- this.cache = new Memory();
1049
- }
1050
- StorageManager.prototype.getLocalItem = function (key) {
1051
- return this.local.getItem(key);
1052
- };
1053
- StorageManager.prototype.setLocalItem = function (key, value) {
1054
- this.local.setItem(key, value);
1055
- };
1056
- StorageManager.prototype.removeLocalItem = function (key) {
1057
- this.local.removeItem(key);
1058
- };
1059
- StorageManager.prototype.getSessionItem = function (key) {
1060
- return this.session.getItem(key);
1061
- };
1062
- StorageManager.prototype.setSessionItem = function (key, value) {
1063
- this.session.setItem(key, value);
1064
- };
1065
- StorageManager.prototype.removeSessionItem = function (key) {
1066
- this.session.removeItem(key);
1067
- };
1068
- StorageManager.prototype.getCacheItem = function (key) {
1069
- return this.cache.getItem(key);
1070
- };
1071
- StorageManager.prototype.setCacheItem = function (key, value) {
1072
- this.cache.setItem(key, value);
1073
- };
1074
- StorageManager.prototype.removeCacheItem = function (key) {
1075
- this.cache.removeItem(key);
1076
- };
1077
- StorageManager.prototype.getCookie = function (key, domain) {
1078
- try {
1079
- // const _matches = Cookies.get(name, { domain: domain || document.domain })
1080
- var _matches = cookie.get(key);
1081
- return _matches;
1082
- } catch (e) {
1083
- return '';
1084
- }
1085
- };
1086
- StorageManager.prototype.setCookie = function (key, value, expiresTime, domain) {
1087
- if (expiresTime === void 0) {
1088
- expiresTime = this.defaultExpireTime;
1089
- }
1090
- try {
1091
- var _domain = domain || document.domain;
1092
- var timestamp = +new Date();
1093
- var furureTimestamp = timestamp + expiresTime;
1094
- cookie.set(key, value, {
1095
- expires: new Date(furureTimestamp),
1096
- path: '/',
1097
- domain: _domain
1098
- });
1099
- } catch (e) {}
1100
- };
1101
- StorageManager.prototype.removeCookie = function (key, domain) {
1102
- try {
1103
- cookie.remove(key, {
1104
- path: '/',
1105
- domain: domain || ''
1106
- });
1107
- } catch (e) {}
1108
- };
1109
- return StorageManager;
1110
- }();
1111
-
1112
963
  // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
1113
964
  var LOG;
1114
965
  LOG = {
@@ -1118,7 +969,9 @@ LOG = {
1118
969
  };
1119
970
  // CN: https://mcs.volceapplog.com VA: https://mcs.itobsnssdk.com SG: https://mcs.tobsnssdk.com
1120
971
  var LOG_URL = LOG;
1121
- var SDK_VERSION = '0.1.3';
972
+ var SDK_VERSION = '0.1.4';
973
+ var SDK_USE_TYPE = 'npm';
974
+ var SDK_TYPE = SDK_USE_TYPE;
1122
975
  var AB_DOMAINS = {
1123
976
  cn: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k',
1124
977
  va: '1fz22z22z1nz21z4mz4bz4bz22z1mz19z1jz1mz1ez4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k',
@@ -2959,6 +2812,559 @@ var RequestManager = /** @class */function () {
2959
2812
  return RequestManager;
2960
2813
  }();
2961
2814
 
2815
+ // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
2816
+ // debugger icon的可拖拽
2817
+ var DraggableButton = /** @class */function () {
2818
+ function DraggableButton(element) {
2819
+ var _this = this;
2820
+ this.onMove = function (e) {
2821
+ if (!_this.isDragging) return;
2822
+ // 判断是否达到拖拽阈值
2823
+ var currentX = e.clientX || e.touches[0].clientX;
2824
+ var currentY = e.clientY || e.touches[0].clientY;
2825
+ if (_this.clickAllowed) {
2826
+ var deltaX = Math.abs(currentX - _this.initialX);
2827
+ var deltaY = Math.abs(currentY - _this.initialY);
2828
+ if (deltaX > _this.dragThreshold || deltaY > _this.dragThreshold) {
2829
+ _this.clickAllowed = false;
2830
+ }
2831
+ }
2832
+ // 节流处理
2833
+ if (_this.animationFrameId) {
2834
+ cancelAnimationFrame(_this.animationFrameId);
2835
+ }
2836
+ _this.animationFrameId = requestAnimationFrame(function () {
2837
+ var clientX = e.touches ? e.touches[0].clientX : e.clientX;
2838
+ var clientY = e.touches ? e.touches[0].clientY : e.clientY;
2839
+ // 计算新位置
2840
+ var newX = clientX - _this.offsetX;
2841
+ var newY = clientY - _this.offsetY;
2842
+ // 边界限制
2843
+ var maxX = window.innerWidth - _this.element.offsetWidth;
2844
+ var maxY = window.innerHeight - _this.element.offsetHeight;
2845
+ newX = Math.max(0, Math.min(newX, maxX));
2846
+ newY = Math.max(0, Math.min(newY, maxY));
2847
+ // 直接应用transform(不修改left/top)
2848
+ _this.element.style.transform = "translate(\n " + (newX - _this.initialX) + "px, \n " + (newY - _this.initialY) + "px\n )";
2849
+ });
2850
+ };
2851
+ this.onEnd = function () {
2852
+ if (!_this.isDragging) return;
2853
+ _this.isDragging = false;
2854
+ // 将最终位置同步到left/top
2855
+ var matrix = new DOMMatrix(getComputedStyle(_this.element).transform);
2856
+ var finalX = _this.initialX + matrix.m41;
2857
+ var finalY = _this.initialY + matrix.m42;
2858
+ _this.element.style.left = finalX + "px";
2859
+ _this.element.style.top = finalY + "px";
2860
+ _this.element.style.transform = 'none';
2861
+ // 更新初始位置记录
2862
+ _this.initialX = finalX;
2863
+ _this.initialY = finalY;
2864
+ // 清理事件监听
2865
+ document.removeEventListener('mousemove', _this.onMove);
2866
+ document.removeEventListener('mouseup', _this.onEnd);
2867
+ document.removeEventListener('touchmove', _this.onMove);
2868
+ document.removeEventListener('touchend', _this.onEnd);
2869
+ setTimeout(function () {
2870
+ _this.clickAllowed = true;
2871
+ }, 50);
2872
+ };
2873
+ this.element = element;
2874
+ this.isDragging = false;
2875
+ this.enableClick = false;
2876
+ this.animationFrameId = null;
2877
+ this.lastX = 0;
2878
+ this.lastY = 0;
2879
+ this.initialX = 0; // 元素初始X坐标
2880
+ this.initialY = 0; // 元素初始Y坐标
2881
+ this.offsetX = 0;
2882
+ this.offsetY = 0;
2883
+ this.clickAllowed = true;
2884
+ this.dragThreshold = 1; // 移动超过5px视为拖拽
2885
+ this.initPosition();
2886
+ this.bindEvents();
2887
+ this.bindClickHandler();
2888
+ }
2889
+ // 初始化元素定位方式
2890
+ DraggableButton.prototype.initPosition = function () {
2891
+ var rect = this.element.getBoundingClientRect();
2892
+ this.element.style.position = 'fixed';
2893
+ this.element.style.left = rect.left + "px";
2894
+ this.element.style.top = rect.top + "px";
2895
+ this.element.style.transform = 'translate(0, 0)';
2896
+ };
2897
+ DraggableButton.prototype.bindEvents = function () {
2898
+ this.element.addEventListener('mousedown', this.onStart.bind(this));
2899
+ this.element.addEventListener('touchstart', this.onStart.bind(this));
2900
+ };
2901
+ DraggableButton.prototype.onStart = function (e) {
2902
+ e.preventDefault();
2903
+ this.initialX = e.clientX || e.touches[0].clientX;
2904
+ this.initialY = e.clientY || e.touches[0].clientY;
2905
+ var clientX = e.touches ? e.touches[0].clientX : e.clientX;
2906
+ var clientY = e.touches ? e.touches[0].clientY : e.clientY;
2907
+ // 获取元素当前实际位置(包含transform)
2908
+ var rect = this.element.getBoundingClientRect();
2909
+ this.initialX = rect.left;
2910
+ this.initialY = rect.top;
2911
+ // 计算点击位置偏移量
2912
+ this.offsetX = clientX - this.initialX;
2913
+ this.offsetY = clientY - this.initialY;
2914
+ this.clickAllowed = true;
2915
+ this.isDragging = true;
2916
+ document.addEventListener('mousemove', this.onMove);
2917
+ document.addEventListener('mouseup', this.onEnd);
2918
+ document.addEventListener('touchmove', this.onMove);
2919
+ document.addEventListener('touchend', this.onEnd);
2920
+ };
2921
+ // 修改后的点击事件绑定方式
2922
+ DraggableButton.prototype.bindClickHandler = function () {
2923
+ var _this = this;
2924
+ this.element.addEventListener('click', function (e) {
2925
+ if (!_this.enableClick) return;
2926
+ if (!_this.clickAllowed) {
2927
+ e.stopImmediatePropagation();
2928
+ e.preventDefault();
2929
+ return;
2930
+ }
2931
+ // 原有的点击处理逻辑
2932
+ window && window.postMessage({
2933
+ type: 'devtool:web:open-draw'
2934
+ }, location.origin);
2935
+ });
2936
+ };
2937
+ DraggableButton.prototype.enable = function () {
2938
+ this.enableClick = true;
2939
+ this.element.style.cursor = 'pointer';
2940
+ this.element.style.opacity = '1';
2941
+ };
2942
+ return DraggableButton;
2943
+ }();
2944
+
2945
+ // Copyright 2022 Beijing Volcanoengine Technology Ltd. All Rights Reserved.
2946
+ var Debugger = /** @class */function () {
2947
+ function Debugger(collect, config) {
2948
+ this.devToolReady = false;
2949
+ this.devToolOrigin = '*';
2950
+ this.sendAlready = false;
2951
+ this.trackEnabled = true;
2952
+ if (config.disable_debug) return;
2953
+ if (collect.configManager.get('browser') === 'Microsoft Internet Explorer') return;
2954
+ this.collect = collect;
2955
+ this.config = config;
2956
+ this.app_id = config.app_id;
2957
+ this.trackEnabled = config.track_enabled ? true : false;
2958
+ this.cacheStorgae = new StorageManager();
2959
+ this.currentAppKey = "__applog_load_devtool_web_" + this.app_id;
2960
+ this.loadUrl = config.devtool_url || 'https://lf-static.applogcdn.com/obj/applog-sdk-static/log-sdk/collect/devtool/debug-web.v2.0.1.js';
2961
+ this.filterEvent = new Set(['__bav_page', '__bav_beat', '__bav_page_statistics', '__bav_click', '__bav_page_exposure', 'bav2b_page', 'bav2b_beat', 'bav2b_page_statistics', 'bav2b_click', 'bav2b_page_exposure', '_be_active', 'predefine_pageview', '__profile_set', '__profile_set_once', '__profile_increment', '__profile_unset', '__profile_append', 'predefine_page_alive', 'predefine_page_close', 'abtest_exposure']);
2962
+ this.load();
2963
+ }
2964
+ Debugger.prototype.loadScript = function (src) {
2965
+ var _this = this;
2966
+ try {
2967
+ var script = document.createElement('script');
2968
+ script.src = src;
2969
+ script.onerror = function () {
2970
+ console.log('load DevTool render fail');
2971
+ };
2972
+ script.onload = function () {
2973
+ _this.enableDebugButton();
2974
+ console.log('load DevTool render success');
2975
+ };
2976
+ document.getElementsByTagName('body')[0].appendChild(script);
2977
+ } catch (e) {
2978
+ console.log("devTool load fail, " + e.message);
2979
+ }
2980
+ };
2981
+ Debugger.prototype.parseUrl = function () {
2982
+ var params = {};
2983
+ try {
2984
+ var url = window.location.href;
2985
+ var hash = url.split('?')[1].split('&');
2986
+ if (hash.length) {
2987
+ hash.forEach(function (h) {
2988
+ var parts = h.split('=');
2989
+ params[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
2990
+ });
2991
+ }
2992
+ } catch (e) {}
2993
+ return params;
2994
+ };
2995
+ Debugger.prototype.load = function () {
2996
+ try {
2997
+ var queryObj = this.parseUrl();
2998
+ if (queryObj['open_devtool_web'] == false) {
2999
+ this.cacheStorgae.removeLocalItem("__applog_open_devtool_web");
3000
+ return;
3001
+ }
3002
+ if (queryObj['open_devtool_web'] && queryObj['app_id']) {
3003
+ if (parseInt(queryObj['app_id']) !== this.app_id) return;
3004
+ } else {
3005
+ if (!this.getStorage()) return;
3006
+ }
3007
+ this.loadBaseInfo();
3008
+ this.loadHook();
3009
+ this.setStorage();
3010
+ this.addLintener();
3011
+ this.loadDevTool();
3012
+ } catch (e) {
3013
+ console.log("debug fail, " + e.message);
3014
+ }
3015
+ };
3016
+ Debugger.prototype.getStorage = function () {
3017
+ var storage_appid = this.cacheStorgae.getLocalItem("__applog_open_devtool_web");
3018
+ return storage_appid && parseInt(storage_appid) === this.app_id;
3019
+ };
3020
+ Debugger.prototype.setStorage = function () {
3021
+ this.cacheStorgae.setLocalItem('__applog_open_devtool_web', this.app_id);
3022
+ this.cacheStorgae.setLocalItem('__applog_devtool_web_track_enable', this.trackEnabled);
3023
+ };
3024
+ Debugger.prototype.loadDevTool = function () {
3025
+ var currentAppHasLoad = this.cacheStorgae.getLocalItem(this.currentAppKey) == 1;
3026
+ if (currentAppHasLoad) {
3027
+ console.warn("your appid: " + this.app_id + " has load web devtools already, maybe your page has more than two applogsdk and use one appid");
3028
+ return;
3029
+ }
3030
+ this.loadDebuggerModule();
3031
+ this.loadScript(this.loadUrl);
3032
+ };
3033
+ Debugger.prototype.loadBaseInfo = function () {
3034
+ this.log = [];
3035
+ this.event = [];
3036
+ this.info = [{
3037
+ title: '基本信息',
3038
+ key: 'base',
3039
+ type: 1,
3040
+ content: [{
3041
+ name: 'app_id',
3042
+ desc: 'APP_ID',
3043
+ value: this.config.app_id
3044
+ }, {
3045
+ name: 'channel',
3046
+ desc: 'CHANNEL',
3047
+ value: this.config.channel
3048
+ }, {
3049
+ name: 'domain',
3050
+ desc: '上报域名',
3051
+ value: this.collect.configManager.getDomain()
3052
+ }, {
3053
+ name: 'sdk_version',
3054
+ desc: 'SDK版本',
3055
+ value: SDK_VERSION
3056
+ }, {
3057
+ name: 'sdk_type',
3058
+ desc: 'SDK引入方式',
3059
+ value: SDK_TYPE
3060
+ }]
3061
+ }, {
3062
+ title: '用户信息',
3063
+ key: 'user',
3064
+ type: 2,
3065
+ content: [{
3066
+ name: 'uuid',
3067
+ desc: 'UUID',
3068
+ value: this.collect.configManager.get('user').user_unique_id || ''
3069
+ }, {
3070
+ name: 'web_id',
3071
+ desc: 'WEB_ID',
3072
+ value: this.collect.configManager.get('user').web_id || ''
3073
+ }]
3074
+ }, {
3075
+ title: '公共参数信息',
3076
+ type: 2,
3077
+ key: 'common',
3078
+ content: [{
3079
+ name: 'browser',
3080
+ desc: '浏览器',
3081
+ value: this.collect.configManager.get('browser')
3082
+ }, {
3083
+ name: 'browser_version',
3084
+ desc: '浏览器版本',
3085
+ value: this.collect.configManager.get('browser_version')
3086
+ }, {
3087
+ name: 'platform',
3088
+ desc: '平台',
3089
+ value: this.collect.configManager.get('platform')
3090
+ }, {
3091
+ name: 'device_model',
3092
+ desc: '设备型号',
3093
+ value: this.collect.configManager.get('device_model')
3094
+ }, {
3095
+ name: 'os_name',
3096
+ desc: '操作系统',
3097
+ value: this.collect.configManager.get('os_name')
3098
+ }, {
3099
+ name: 'os_version',
3100
+ desc: '操作系统版本',
3101
+ value: this.collect.configManager.get('os_version')
3102
+ }, {
3103
+ name: 'resolution',
3104
+ desc: '屏幕分辨率',
3105
+ value: this.collect.configManager.get('resolution')
3106
+ }, {
3107
+ name: 'referrer',
3108
+ desc: '来源',
3109
+ value: this.collect.configManager.get('referrer')
3110
+ }, {
3111
+ name: 'custom',
3112
+ desc: '自定义信息',
3113
+ value: JSON.stringify(this.collect.configManager.get('custom'))
3114
+ }]
3115
+ }, {
3116
+ title: '配置信息',
3117
+ key: 'config',
3118
+ type: 3,
3119
+ content: [{
3120
+ name: 'autotrack',
3121
+ desc: '全埋点',
3122
+ value: this.config.autotrack ? true : false
3123
+ }, {
3124
+ name: 'stay',
3125
+ desc: '停留时长',
3126
+ value: this.config.enable_stay_duration ? true : false
3127
+ }]
3128
+ }, {
3129
+ title: 'A/B配置信息',
3130
+ key: 'ab',
3131
+ type: 4,
3132
+ content: [{
3133
+ name: 'ab',
3134
+ desc: 'A/B实验',
3135
+ value: this.config.enable_ab_test ? true : false
3136
+ }]
3137
+ }];
3138
+ if (this.config.enable_ab_test) {
3139
+ var ab = this.getInfo('ab');
3140
+ var content = [{
3141
+ name: 'ab',
3142
+ desc: 'A/B实验',
3143
+ value: this.config.enable_ab_test ? true : false
3144
+ }, {
3145
+ name: 'vid',
3146
+ desc: '已曝光VID',
3147
+ value: this.collect.configManager.getAbVersion()
3148
+ }, {
3149
+ name: 'ab_domain',
3150
+ desc: 'A/B域名',
3151
+ value: this.config.ab_channel_domain || decodeUrl(AB_DOMAINS[this.config.channel])
3152
+ }, {
3153
+ name: 'all_values',
3154
+ desc: '全部配置',
3155
+ value: this.collect.configManager.getAbCache()
3156
+ }];
3157
+ ab.content = content;
3158
+ this.setInfo('ab', ab);
3159
+ }
3160
+ if (this.config.enable_native || this.config.Native) {
3161
+ var _native = {
3162
+ title: '客户端信息',
3163
+ type: 3,
3164
+ content: [{
3165
+ name: 'native',
3166
+ desc: '是否打通',
3167
+ value: this.collect.bridgeReport ? true : false
3168
+ }]
3169
+ };
3170
+ this.setInfo('native', _native);
3171
+ }
3172
+ if (SDK_VERSION.includes('tob')) {
3173
+ var user = this.getInfo('user');
3174
+ user.content.push({
3175
+ name: 'sid',
3176
+ desc: 'DISS'.split('').reverse().join(''),
3177
+ value: '点击获取'
3178
+ });
3179
+ this.setInfo('user', user);
3180
+ }
3181
+ };
3182
+ Debugger.prototype.getInfo = function (key) {
3183
+ var current = null;
3184
+ this.info.forEach(function (item) {
3185
+ if (item.key === key) {
3186
+ current = item;
3187
+ }
3188
+ });
3189
+ return current;
3190
+ };
3191
+ Debugger.prototype.setInfo = function (key, data) {
3192
+ var hasKey = false;
3193
+ this.info.forEach(function (item) {
3194
+ if (item.key === key) {
3195
+ hasKey = true;
3196
+ item = data;
3197
+ }
3198
+ });
3199
+ if (!hasKey) {
3200
+ this.info.push(data);
3201
+ }
3202
+ };
3203
+ Debugger.prototype.getSecondInfo = function (key, valueKey) {
3204
+ var data = this.getInfo(key);
3205
+ var current = null;
3206
+ data.content.forEach(function (item) {
3207
+ if (item.name === valueKey) {
3208
+ current = item;
3209
+ }
3210
+ });
3211
+ return current;
3212
+ };
3213
+ Debugger.prototype.setSecondInfo = function (key, valueKey, value) {
3214
+ var data = this.getInfo(key);
3215
+ var contentHasKey = false;
3216
+ data.content.forEach(function (item) {
3217
+ if (item.name === valueKey) {
3218
+ item.value = value;
3219
+ contentHasKey = true;
3220
+ }
3221
+ });
3222
+ if (!contentHasKey) {
3223
+ var newContent = {
3224
+ name: valueKey,
3225
+ value: value,
3226
+ desc: valueKey.toLocaleUpperCase()
3227
+ };
3228
+ data.content.push(newContent);
3229
+ }
3230
+ this.setInfo(key, data);
3231
+ };
3232
+ Debugger.prototype.loadHook = function () {
3233
+ var _this = this;
3234
+ this.collect.on(DebuggerMesssge.DEBUGGER_MESSAGE, function (data) {
3235
+ switch (data.type) {
3236
+ case DebuggerMesssge.DEBUGGER_MESSAGE_SDK:
3237
+ var logObj = {
3238
+ time: data.time,
3239
+ type: data.logType || 'sdk',
3240
+ infoType: data.infoType || 'sdk',
3241
+ level: data.level,
3242
+ name: data.info,
3243
+ show: true,
3244
+ levelShow: true,
3245
+ needDesc: data.data ? true : false
3246
+ };
3247
+ if (data.data) {
3248
+ logObj['desc'] = {
3249
+ content: JSON.stringify(data.data)
3250
+ };
3251
+ }
3252
+ _this.updateLog(logObj);
3253
+ if (data.secType && data.secType === 'AB') {
3254
+ _this.setSecondInfo('ab', 'vid', _this.collect.configManager.getAbVersion());
3255
+ _this.setSecondInfo('ab', 'all_values', _this.collect.configManager.getAbCache());
3256
+ } else if (data.secType === 'USER') {
3257
+ // this.setSecondInfo('user', 'uuid', this.collect.configManager.get('user_unique_id'))
3258
+ // this.setSecondInfo('user', 'web_id', this.collect.configManager.get('web_id'))
3259
+ _this.setSecondInfo('user', data.common === 'user_unique_id' ? 'uuid' : data.common, _this.collect.configManager.get(data.common));
3260
+ } else if (data.secType === 'HEADER') {
3261
+ var value = _this.collect.configManager.get(data.common);
3262
+ _this.setSecondInfo('common', data.common, data.common === 'custom' ? JSON.stringify(value) : value);
3263
+ }
3264
+ _this.updateInfo();
3265
+ return;
3266
+ case DebuggerMesssge.DEBUGGER_MESSAGE_EVENT:
3267
+ if (data.data && data.data.length) {
3268
+ var events = data.data[0];
3269
+ var event_1 = events.events;
3270
+ if (!event_1.length) return;
3271
+ event_1.forEach(function (item) {
3272
+ item['checkShow'] = true;
3273
+ item['searchShow'] = true;
3274
+ item['focusShow'] = true;
3275
+ item['status'] = data.status;
3276
+ item['type'] = _this.filterEvent.has(item.event) ? 'sdk' : 'cus';
3277
+ item['verifyType'] = data.verifyType ? 'verify' : 'no';
3278
+ item['info'] = '';
3279
+ if (data.status === 'fail') {
3280
+ item['info'] = {
3281
+ message: "code: " + data.code + "\uFF0C msg: " + (data.msg || data.failType)
3282
+ };
3283
+ }
3284
+ });
3285
+ _this.updateEvent(events);
3286
+ }
3287
+ return;
3288
+ }
3289
+ });
3290
+ };
3291
+ Debugger.prototype.addLintener = function () {
3292
+ var _this = this;
3293
+ window.addEventListener('message', function (messgae) {
3294
+ if (messgae && messgae.data && messgae.data.type === 'devtool:web:ready') {
3295
+ _this.devToolOrigin = messgae.origin;
3296
+ _this.devToolReady = true;
3297
+ if (_this.sendAlready) return;
3298
+ _this.sendData('devtool:web:init', {
3299
+ info: _this.info,
3300
+ log: _this.log,
3301
+ event: _this.event,
3302
+ sdk_type: SDK_VERSION.includes('tob') ? 'tob' : 'inner',
3303
+ appId: _this.app_id
3304
+ });
3305
+ _this.sendAlready = true;
3306
+ }
3307
+ if (messgae && messgae.data && messgae.data.type === 'devtool:web:ssid') {
3308
+ _this.collect.getToken(function (res) {
3309
+ _this.setSecondInfo('user', 'sid', res.tobid);
3310
+ _this.updateInfo();
3311
+ });
3312
+ }
3313
+ });
3314
+ };
3315
+ Debugger.prototype.sendData = function (type, data) {
3316
+ try {
3317
+ var postData = {
3318
+ type: type,
3319
+ payload: data
3320
+ };
3321
+ // (window.opener || window.parent).postMessage(postData, this.devToolOrigin);
3322
+ window && window.postMessage(postData, this.devToolOrigin);
3323
+ } catch (e) {}
3324
+ };
3325
+ Debugger.prototype.updateInfo = function () {
3326
+ if (!this.devToolReady) {
3327
+ return;
3328
+ }
3329
+ this.sendData('devtool:web:info', this.info);
3330
+ };
3331
+ Debugger.prototype.updateLog = function (logObj) {
3332
+ if (!this.devToolReady) {
3333
+ this.log.push(logObj);
3334
+ return;
3335
+ }
3336
+ this.sendData('devtool:web:log', logObj);
3337
+ };
3338
+ Debugger.prototype.updateEvent = function (events) {
3339
+ if (!this.devToolReady) {
3340
+ this.event.push(events);
3341
+ return;
3342
+ }
3343
+ this.sendData('devtool:web:event', events);
3344
+ };
3345
+ Debugger.prototype.loadDebuggerModule = function () {
3346
+ var debugCss = "#debugger-applog-web {\n position: fixed;\n width: 90px;\n height: 30px;\n background: #23c243;\n border-radius: 6px;\n color: #fff;\n font-size: 12px;\n bottom: 5%;\n right: 10%;\n text-align: center;\n line-height: 30px;\n cursor: not-allowed;\n z-index:1000;\n font-weight:bold;\n opacity: 0.6;\n }";
3347
+ var head = document.head || document.getElementsByTagName('head')[0];
3348
+ var style = document.createElement('style');
3349
+ style.appendChild(document.createTextNode(debugCss));
3350
+ head.appendChild(style);
3351
+ var debuggerHtml = "<div id=\"debugger-applog-web\" class=\"debugger-applog-web\">AppLog\u8C03\u8BD5</div>";
3352
+ var debugDiv = document.createElement('div');
3353
+ debugDiv.innerHTML = debuggerHtml;
3354
+ var debuggerContainer = "<div id=\"debugger-container\" class=\"debugger-container\"></div>";
3355
+ var debugContainerDiv = document.createElement('div');
3356
+ debugContainerDiv.innerHTML = debuggerContainer;
3357
+ document.getElementsByTagName('body')[0].appendChild(debugDiv);
3358
+ document.getElementsByTagName('body')[0].appendChild(debugContainerDiv);
3359
+ var debugTool = document.getElementById('debugger-applog-web');
3360
+ this.debugButton = new DraggableButton(debugTool);
3361
+ };
3362
+ Debugger.prototype.enableDebugButton = function () {
3363
+ this.debugButton && this.debugButton.enable();
3364
+ };
3365
+ return Debugger;
3366
+ }();
3367
+
2962
3368
  var jsbn = createCommonjsModule(function (module, exports) {
2963
3369
  (function(){
2964
3370
  var dbits;
@@ -5119,7 +5525,7 @@ var Collector$1 = /** @class */function () {
5119
5525
  this.configManager = new ConfigManager(this, initConfig);
5120
5526
  this.appBridge = new AppBridge(initConfig, this.configManager);
5121
5527
  this.bridgeReport = this.appBridge.bridgeInject();
5122
- // this.debugger = new Debugger(this, initConfig)
5528
+ this["debugger"] = new Debugger(this, initConfig);
5123
5529
  this.requestManager = new RequestManager(this, initConfig);
5124
5530
  this.initConfig = initConfig;
5125
5531
  this.env = initConfig.channel_domain ? 'self' : 'public';
@@ -8938,8 +9344,7 @@ var Store = /** @class */function () {
8938
9344
  this.config = config;
8939
9345
  if (this.collect.destroy) return;
8940
9346
  var Types = collect.Types;
8941
- var storage = collect.adapters.storage;
8942
- this.storage = new storage(false);
9347
+ this.storage = new StorageManager();
8943
9348
  this.eventUrl = this.collect.configManager.getUrl('event');
8944
9349
  this.eventKey = "__tea_cache_events_" + config.app_id;
8945
9350
  this.storageNum = config.storage_num || 50; // 默认最大存储50条数据
@@ -8988,19 +9393,19 @@ var Store = /** @class */function () {
8988
9393
  }, this.retryInterval);
8989
9394
  };
8990
9395
  Store.prototype.storeData = function (errorInfo) {
8991
- var data = this.storage.getItem(this.eventKey);
9396
+ var data = this.storage.getLocalItem(this.eventKey);
8992
9397
  var eventData = errorInfo.eventData;
8993
9398
  // 数据错误不进行存储
8994
9399
  if (Object.keys(data).length === this.storageNum) return;
8995
9400
  // 数据满了,就不再添加数据
8996
9401
  data[Date.now()] = eventData;
8997
- this.storage.setItem(this.eventKey, data);
9402
+ this.storage.setLocalItem(this.eventKey, data);
8998
9403
  };
8999
9404
  Store.prototype.checkStorage = function () {
9000
9405
  var _this = this;
9001
9406
  try {
9002
9407
  if (!window.navigator.onLine) return; // 设备未联网
9003
- var data_1 = this.storage.getItem(this.eventKey);
9408
+ var data_1 = this.storage.getLocalItem(this.eventKey);
9004
9409
  if (!data_1 || !Object.keys(data_1).length) return;
9005
9410
  var loadData = {
9006
9411
  events: [{
@@ -9020,7 +9425,7 @@ var Store = /** @class */function () {
9020
9425
  var _loop_1 = function _loop_1(key) {
9021
9426
  _this.fetchData(data_1[key], function () {
9022
9427
  delete copyData[key];
9023
- _this.storage.setItem(_this.eventKey, copyData);
9428
+ _this.storage.setLocalItem(_this.eventKey, copyData);
9024
9429
  }, function () {}, false);
9025
9430
  };
9026
9431
  for (var key in data_1) {