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