@zxhy-npm/send-sls-logger 1.0.3 → 1.1.0

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/lib/index.js CHANGED
@@ -1,9 +1,4 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const web_track_browser_1 = __importDefault(require("@aliyun-sls/web-track-browser"));
7
- const init_1 = __importDefault(require("./init"));
8
- const SLSLog = (config) => new init_1.default(web_track_browser_1.default, config);
9
- exports.default = SLSLog;
1
+ import SlsTracker from "@aliyun-sls/web-track-browser";
2
+ import DefaultLog from "./init";
3
+ const SLSLog = (config) => new DefaultLog(SlsTracker, config);
4
+ export default SLSLog;
package/lib/init.d.ts CHANGED
@@ -47,3 +47,4 @@ declare class DefaultLog<T extends LogOptions> {
47
47
  info: (...args: any[]) => void;
48
48
  }
49
49
  export default DefaultLog;
50
+ export type LogClassInterface = InstanceType<typeof DefaultLog>;
package/lib/init.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  const getType = (val) => {
4
2
  return Object.prototype.toString.call(val).toLocaleLowerCase().slice(8, -1);
5
3
  };
@@ -33,7 +31,9 @@ class DefaultLog {
33
31
  if (options?.host && options.logstore && options.project) {
34
32
  this.tracker = new this.Tracker(options);
35
33
  }
36
- this.maxLength = strMaxLength;
34
+ if (this.maxLength === defaultMaxLength && strMaxLength !== defaultMaxLength) {
35
+ this.maxLength = strMaxLength;
36
+ }
37
37
  this.exclude.push(...defaultExclude);
38
38
  }
39
39
  formatDataMaxLength(data) {
@@ -126,4 +126,4 @@ class DefaultLog {
126
126
  log = this.send('info');
127
127
  info = this.send('info');
128
128
  }
129
- exports.default = DefaultLog;
129
+ export default DefaultLog;
package/lib/mini.js CHANGED
@@ -1,9 +1,4 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const web_track_mini_1 = __importDefault(require("@aliyun-sls/web-track-mini"));
7
- const init_1 = __importDefault(require("./init"));
8
- const MiniInit = (config) => new init_1.default(web_track_mini_1.default, config);
9
- exports.default = MiniInit;
1
+ import SlsMiniTracker from "@aliyun-sls/web-track-mini";
2
+ import DefaultLog from "./init";
3
+ const MiniInit = (config) => new DefaultLog(SlsMiniTracker, config);
4
+ export default MiniInit;
package/lib/trace.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function initTrace(info: (...data: any[]) => any): void;
package/lib/trace.js ADDED
@@ -0,0 +1,41 @@
1
+ export function initTrace(info) {
2
+ const observer = new MutationObserver(() => {
3
+ const modules = document.querySelectorAll('[data-module]');
4
+ const observer = new IntersectionObserver((entries, observer) => {
5
+ entries.forEach((entry) => {
6
+ if (entry.isIntersecting) {
7
+ const module = entry.target;
8
+ const moduleName = module.dataset.module;
9
+ moduleName && info({
10
+ moduleName,
11
+ entryType: 'load',
12
+ });
13
+ observer.unobserve(module);
14
+ delete module.dataset.module;
15
+ }
16
+ }, {
17
+ root: null,
18
+ threshold: 0.1,
19
+ rootMargin: '0px',
20
+ });
21
+ });
22
+ modules.forEach((module) => observer.observe(module));
23
+ });
24
+ observer.observe(document.body, {
25
+ childList: true,
26
+ subtree: true,
27
+ });
28
+ const clickHandler = (event) => {
29
+ const target = event.target;
30
+ const closestElement = target.closest('[data-click]');
31
+ if (closestElement) {
32
+ const moduleName = closestElement.dataset.click || '';
33
+ moduleName && info({
34
+ moduleName,
35
+ entryType: 'click',
36
+ });
37
+ delete target.dataset.click;
38
+ }
39
+ };
40
+ window.addEventListener('click', clickHandler);
41
+ }
package/package.json CHANGED
@@ -1,19 +1,15 @@
1
1
  {
2
2
  "name": "@zxhy-npm/send-sls-logger",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "阿里云sls的logger发送",
5
5
  "scripts": {
6
6
  "build": "rm -rf lib && tsc"
7
7
  },
8
8
  "files": [
9
- "lib"
9
+ "lib/**/*"
10
10
  ],
11
11
  "main": "lib/index.js",
12
12
  "types": "lib/index.d.ts",
13
- "exports": {
14
- ".": "./lib/index.js",
15
- "./mini": "./lib/mini.js"
16
- },
17
13
  "keywords": [
18
14
  "logger",
19
15
  "sls"
package/readme.md CHANGED
@@ -46,3 +46,5 @@ miniLog.info({ msg: "这是一条默认日志" });
46
46
  更新内容: 增加 ts 解析器
47
47
  0.0.41 ---------- 2023-02-10 14:51:18
48
48
  更新内容: 增加使用说明
49
+ 1.1.0 ---------- 12/15/2024, 3:05:43 PM
50
+ 更新内容: 增加了 initTrace 的方法, 只支持PC项目,监听 dom的进入试图,以及点击事件,需要在dom增加 data-module、data-click 对应的属性