@pluve/logger-sdk 0.0.2 → 0.0.3
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/dist/index.d.ts +1 -0
- package/dist/{esm/index.js → index.js} +2 -4
- package/package.json +1 -1
- package/dist/cjs/index.d.ts +0 -6
- package/dist/cjs/index.js +0 -41
- package/dist/cjs/loggerSDK.js +0 -158
- package/dist/cjs/transportAdapter.js +0 -182
- package/dist/cjs/types.js +0 -17
- package/dist/cjs/utils.js +0 -208
- package/dist/esm/index.d.ts +0 -6
- package/dist/esm/loggerSDK.d.ts +0 -36
- package/dist/esm/transportAdapter.d.ts +0 -51
- package/dist/esm/types.d.ts +0 -46
- package/dist/esm/utils.d.ts +0 -30
- package/dist/umd/logger-sdk.min.js +0 -1
- /package/dist/{cjs/loggerSDK.d.ts → loggerSDK.d.ts} +0 -0
- /package/dist/{esm/loggerSDK.js → loggerSDK.js} +0 -0
- /package/dist/{cjs/transportAdapter.d.ts → transportAdapter.d.ts} +0 -0
- /package/dist/{esm/transportAdapter.js → transportAdapter.js} +0 -0
- /package/dist/{cjs/types.d.ts → types.d.ts} +0 -0
- /package/dist/{esm/types.js → types.js} +0 -0
- /package/dist/{cjs/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/{esm/utils.js → utils.js} +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LoggerSDK } from './loggerSDK';
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
* @Author : 黄震 huangzhen@yfpharmacy.com
|
|
3
3
|
* @Date : 2025-11-21 14:25:26
|
|
4
4
|
* @LastEditors : 黄震 huangzhen@yfpharmacy.com
|
|
5
|
-
* @LastEditTime : 2025-12-04
|
|
5
|
+
* @LastEditTime : 2025-12-04 15:56:03
|
|
6
6
|
* @Description : 描述
|
|
7
7
|
* Copyright (c) 2025 by 益丰大药房连锁股份有限公司, All Rights Reserved.
|
|
8
8
|
*/
|
|
9
|
-
export { LoggerSDK } from "./loggerSDK";
|
|
10
|
-
export { defaultTransport, TransportAdapters } from "./transportAdapter";
|
|
11
|
-
export { getEnvironmentInfo, parseBrowserInfo, isWeChatMiniProgram } from "./utils";
|
|
9
|
+
export { LoggerSDK } from "./loggerSDK";
|
package/package.json
CHANGED
package/dist/cjs/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { LoggerSDK } from './loggerSDK';
|
|
2
|
-
export { defaultTransport, TransportAdapters } from './transportAdapter';
|
|
3
|
-
export type { TransportAdapter, TransportOptions } from './transportAdapter';
|
|
4
|
-
export type { SDKOptions, LogEvent, LogEventType, LogEventLevel, Env } from './types';
|
|
5
|
-
export type { PlatformType, EnvironmentInfo } from './utils';
|
|
6
|
-
export { getEnvironmentInfo, parseBrowserInfo, isWeChatMiniProgram } from './utils';
|
package/dist/cjs/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/index.ts
|
|
20
|
-
var src_exports = {};
|
|
21
|
-
__export(src_exports, {
|
|
22
|
-
LoggerSDK: () => import_loggerSDK.LoggerSDK,
|
|
23
|
-
TransportAdapters: () => import_transportAdapter.TransportAdapters,
|
|
24
|
-
defaultTransport: () => import_transportAdapter.defaultTransport,
|
|
25
|
-
getEnvironmentInfo: () => import_utils.getEnvironmentInfo,
|
|
26
|
-
isWeChatMiniProgram: () => import_utils.isWeChatMiniProgram,
|
|
27
|
-
parseBrowserInfo: () => import_utils.parseBrowserInfo
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(src_exports);
|
|
30
|
-
var import_loggerSDK = require("./loggerSDK");
|
|
31
|
-
var import_transportAdapter = require("./transportAdapter");
|
|
32
|
-
var import_utils = require("./utils");
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
LoggerSDK,
|
|
36
|
-
TransportAdapters,
|
|
37
|
-
defaultTransport,
|
|
38
|
-
getEnvironmentInfo,
|
|
39
|
-
isWeChatMiniProgram,
|
|
40
|
-
parseBrowserInfo
|
|
41
|
-
});
|
package/dist/cjs/loggerSDK.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/loggerSDK.ts
|
|
20
|
-
var loggerSDK_exports = {};
|
|
21
|
-
__export(loggerSDK_exports, {
|
|
22
|
-
LoggerSDK: () => LoggerSDK,
|
|
23
|
-
default: () => loggerSDK_default
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(loggerSDK_exports);
|
|
26
|
-
var import_transportAdapter = require("./transportAdapter");
|
|
27
|
-
var import_utils = require("./utils");
|
|
28
|
-
var LoggerSDK = class {
|
|
29
|
-
constructor(options) {
|
|
30
|
-
this.seq = 0;
|
|
31
|
-
this.closed = false;
|
|
32
|
-
this.opts = {
|
|
33
|
-
endpoint: options.endpoint,
|
|
34
|
-
appId: options.appId || "unknown",
|
|
35
|
-
env: options.env || "dev",
|
|
36
|
-
debug: !!options.debug,
|
|
37
|
-
pixelParam: options.pixelParam || "data",
|
|
38
|
-
maxPixelUrlLen: options.maxPixelUrlLen || 1900
|
|
39
|
-
};
|
|
40
|
-
this.envTags = this.collectEnvironmentTags();
|
|
41
|
-
this.attachUnloadHandlers();
|
|
42
|
-
}
|
|
43
|
-
logDebug(...args) {
|
|
44
|
-
if (this.opts.debug)
|
|
45
|
-
console.debug("[LoggerSDK]", ...args);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* 收集环境信息并生成 tags(仅在初始化时执行一次)
|
|
49
|
-
*/
|
|
50
|
-
collectEnvironmentTags() {
|
|
51
|
-
const envInfo = (0, import_utils.getEnvironmentInfo)();
|
|
52
|
-
const tags = {
|
|
53
|
-
platform: envInfo.platform
|
|
54
|
-
};
|
|
55
|
-
if (envInfo.platform === "browser" && envInfo.userAgent) {
|
|
56
|
-
const browserInfo = (0, import_utils.parseBrowserInfo)(envInfo.userAgent);
|
|
57
|
-
tags.browser = browserInfo.browser;
|
|
58
|
-
tags.browserVersion = browserInfo.browserVersion;
|
|
59
|
-
tags.os = browserInfo.os;
|
|
60
|
-
tags.osVersion = browserInfo.osVersion;
|
|
61
|
-
tags.screenWidth = envInfo.screenWidth;
|
|
62
|
-
tags.screenHeight = envInfo.screenHeight;
|
|
63
|
-
tags.language = envInfo.language;
|
|
64
|
-
} else if (envInfo.platform === "wechat" && envInfo.systemInfo) {
|
|
65
|
-
tags.brand = envInfo.systemInfo.brand;
|
|
66
|
-
tags.model = envInfo.systemInfo.model;
|
|
67
|
-
tags.system = envInfo.systemInfo.system;
|
|
68
|
-
tags.wechatVersion = envInfo.systemInfo.version;
|
|
69
|
-
tags.SDKVersion = envInfo.systemInfo.SDKVersion;
|
|
70
|
-
tags.screenWidth = envInfo.screenWidth;
|
|
71
|
-
tags.screenHeight = envInfo.screenHeight;
|
|
72
|
-
tags.language = envInfo.language;
|
|
73
|
-
}
|
|
74
|
-
this.logDebug("Environment tags collected:", tags);
|
|
75
|
-
return tags;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 记录事件
|
|
79
|
-
*/
|
|
80
|
-
async track(eventType, message, options) {
|
|
81
|
-
if (this.closed)
|
|
82
|
-
return;
|
|
83
|
-
this.seq += 1;
|
|
84
|
-
const logEvent = {
|
|
85
|
-
eventType,
|
|
86
|
-
ts: (0, import_utils.now)(),
|
|
87
|
-
appId: this.opts.appId || "unknown",
|
|
88
|
-
env: this.opts.env || "dev",
|
|
89
|
-
level: (options == null ? void 0 : options.level) || "info",
|
|
90
|
-
message,
|
|
91
|
-
stack: options == null ? void 0 : options.stack,
|
|
92
|
-
url: (0, import_utils.getCurrentUrl)(),
|
|
93
|
-
userId: options == null ? void 0 : options.userId,
|
|
94
|
-
sessionId: (0, import_utils.getSessionId)(),
|
|
95
|
-
// 合并预收集的环境 tags 和用户自定义 tags
|
|
96
|
-
tags: {
|
|
97
|
-
...this.envTags,
|
|
98
|
-
...(options == null ? void 0 : options.tags) || {}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
this.logDebug("track", logEvent);
|
|
102
|
-
try {
|
|
103
|
-
await (0, import_transportAdapter.defaultTransport)(logEvent, this.opts);
|
|
104
|
-
} catch (error) {
|
|
105
|
-
this.logDebug("track failed", error);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* 设置用户信息
|
|
110
|
-
*/
|
|
111
|
-
identify(userId) {
|
|
112
|
-
this.logDebug("identify", userId);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* 销毁实例
|
|
116
|
-
*/
|
|
117
|
-
destroy() {
|
|
118
|
-
this.closed = true;
|
|
119
|
-
}
|
|
120
|
-
// ========== 自动采集 ===========
|
|
121
|
-
/**
|
|
122
|
-
* 监听页面卸载事件
|
|
123
|
-
*/
|
|
124
|
-
attachUnloadHandlers() {
|
|
125
|
-
if ((0, import_utils.isWeChatMiniProgram)()) {
|
|
126
|
-
this.logDebug("WeChat MiniProgram environment detected");
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (!(0, import_utils.isBrowser)())
|
|
130
|
-
return;
|
|
131
|
-
const win = window;
|
|
132
|
-
document.addEventListener && document.addEventListener("visibilitychange", () => {
|
|
133
|
-
try {
|
|
134
|
-
if (document.visibilityState === "hidden") {
|
|
135
|
-
console.log("Page hidden");
|
|
136
|
-
}
|
|
137
|
-
} catch {
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
win.addEventListener && win.addEventListener("pagehide", () => {
|
|
141
|
-
try {
|
|
142
|
-
console.log("Page hide");
|
|
143
|
-
} catch {
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
win.addEventListener && win.addEventListener("beforeunload", () => {
|
|
147
|
-
try {
|
|
148
|
-
console.log("Page unload");
|
|
149
|
-
} catch {
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
var loggerSDK_default = LoggerSDK;
|
|
155
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
-
0 && (module.exports = {
|
|
157
|
-
LoggerSDK
|
|
158
|
-
});
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/transportAdapter.ts
|
|
20
|
-
var transportAdapter_exports = {};
|
|
21
|
-
__export(transportAdapter_exports, {
|
|
22
|
-
TransportAdapters: () => TransportAdapters,
|
|
23
|
-
beaconTransport: () => beaconTransport,
|
|
24
|
-
defaultTransport: () => defaultTransport,
|
|
25
|
-
imageTransport: () => imageTransport,
|
|
26
|
-
wechatTransport: () => wechatTransport
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(transportAdapter_exports);
|
|
29
|
-
var import_utils = require("./utils");
|
|
30
|
-
function getEndpoint(opts) {
|
|
31
|
-
return (opts == null ? void 0 : opts.endpoint) || "";
|
|
32
|
-
}
|
|
33
|
-
var beaconTransport = {
|
|
34
|
-
name: "beacon",
|
|
35
|
-
isSupported() {
|
|
36
|
-
return (0, import_utils.isBrowser)() && typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function";
|
|
37
|
-
},
|
|
38
|
-
async send(payload, opts) {
|
|
39
|
-
const body = typeof payload === "string" ? payload : (0, import_utils.safeStringify)(payload);
|
|
40
|
-
const endpoint = getEndpoint(opts);
|
|
41
|
-
const blob = new Blob([body], { type: "application/json" });
|
|
42
|
-
const success = navigator.sendBeacon(endpoint, blob);
|
|
43
|
-
if (!success) {
|
|
44
|
-
throw new Error("sendBeacon failed (queue full or other error)");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var wechatTransport = {
|
|
49
|
-
name: "wechat",
|
|
50
|
-
isSupported() {
|
|
51
|
-
return (0, import_utils.isWeChatMiniProgram)();
|
|
52
|
-
},
|
|
53
|
-
async send(payload, opts) {
|
|
54
|
-
const body = typeof payload === "string" ? payload : (0, import_utils.safeStringify)(payload);
|
|
55
|
-
const endpoint = getEndpoint(opts);
|
|
56
|
-
const timeout = 1e4;
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
let timeoutId = null;
|
|
59
|
-
let settled = false;
|
|
60
|
-
timeoutId = setTimeout(() => {
|
|
61
|
-
if (!settled) {
|
|
62
|
-
settled = true;
|
|
63
|
-
reject(new Error(`WeChat request timeout after ${timeout}ms`));
|
|
64
|
-
}
|
|
65
|
-
}, timeout);
|
|
66
|
-
wx.request({
|
|
67
|
-
url: endpoint,
|
|
68
|
-
method: "POST",
|
|
69
|
-
data: body,
|
|
70
|
-
header: {
|
|
71
|
-
"Content-Type": "application/json"
|
|
72
|
-
},
|
|
73
|
-
success(res) {
|
|
74
|
-
if (timeoutId)
|
|
75
|
-
clearTimeout(timeoutId);
|
|
76
|
-
if (!settled) {
|
|
77
|
-
settled = true;
|
|
78
|
-
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
79
|
-
resolve();
|
|
80
|
-
} else {
|
|
81
|
-
reject(new Error(`HTTP ${res.statusCode}`));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
fail(err) {
|
|
86
|
-
if (timeoutId)
|
|
87
|
-
clearTimeout(timeoutId);
|
|
88
|
-
if (!settled) {
|
|
89
|
-
settled = true;
|
|
90
|
-
reject(new Error(`WeChat request failed: ${err.errMsg || "unknown error"}`));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
var imageTransport = {
|
|
98
|
-
name: "image",
|
|
99
|
-
isSupported() {
|
|
100
|
-
return (0, import_utils.isBrowser)() && typeof Image !== "undefined";
|
|
101
|
-
},
|
|
102
|
-
async send(payload, opts) {
|
|
103
|
-
const body = typeof payload === "string" ? payload : (0, import_utils.safeStringify)(payload);
|
|
104
|
-
const endpoint = getEndpoint(opts);
|
|
105
|
-
const param = (opts == null ? void 0 : opts.pixelParam) || "data";
|
|
106
|
-
const maxLen = (opts == null ? void 0 : opts.maxPixelUrlLen) || 1900;
|
|
107
|
-
const cacheBuster = `_=${(0, import_utils.now)()}`;
|
|
108
|
-
const qs = `${param}=${encodeURIComponent(body)}&${cacheBuster}`;
|
|
109
|
-
const url = endpoint.includes("?") ? `${endpoint}&${qs}` : `${endpoint}?${qs}`;
|
|
110
|
-
if (url.length > maxLen) {
|
|
111
|
-
throw new Error(`URL too long (${url.length} > ${maxLen})`);
|
|
112
|
-
}
|
|
113
|
-
return new Promise((resolve, reject) => {
|
|
114
|
-
const img = new Image();
|
|
115
|
-
let timeoutId = null;
|
|
116
|
-
let settled = false;
|
|
117
|
-
timeoutId = setTimeout(() => {
|
|
118
|
-
if (!settled) {
|
|
119
|
-
settled = true;
|
|
120
|
-
img.src = "";
|
|
121
|
-
reject(new Error("Image request timeout after 5000ms"));
|
|
122
|
-
}
|
|
123
|
-
}, 5e3);
|
|
124
|
-
img.onload = () => {
|
|
125
|
-
if (timeoutId)
|
|
126
|
-
clearTimeout(timeoutId);
|
|
127
|
-
if (!settled) {
|
|
128
|
-
settled = true;
|
|
129
|
-
resolve();
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
img.onerror = () => {
|
|
133
|
-
if (timeoutId)
|
|
134
|
-
clearTimeout(timeoutId);
|
|
135
|
-
if (!settled) {
|
|
136
|
-
settled = true;
|
|
137
|
-
reject(new Error("Image request failed"));
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
img.src = url;
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
async function defaultTransport(payload, opts) {
|
|
145
|
-
if ((0, import_utils.isWeChatMiniProgram)()) {
|
|
146
|
-
if (wechatTransport.isSupported(opts)) {
|
|
147
|
-
await wechatTransport.send(payload, opts);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const transports = [beaconTransport, imageTransport];
|
|
152
|
-
const adapter = transports.find((t) => t.isSupported(opts));
|
|
153
|
-
if (!adapter) {
|
|
154
|
-
throw new Error("No supported transport adapter available");
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
await adapter.send(payload, opts);
|
|
158
|
-
} catch (error) {
|
|
159
|
-
if (adapter.name === "beacon" && imageTransport.isSupported(opts)) {
|
|
160
|
-
try {
|
|
161
|
-
await imageTransport.send(payload, opts);
|
|
162
|
-
return;
|
|
163
|
-
} catch (imgError) {
|
|
164
|
-
throw error;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
var TransportAdapters = {
|
|
171
|
-
beacon: beaconTransport,
|
|
172
|
-
wechat: wechatTransport,
|
|
173
|
-
image: imageTransport
|
|
174
|
-
};
|
|
175
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
176
|
-
0 && (module.exports = {
|
|
177
|
-
TransportAdapters,
|
|
178
|
-
beaconTransport,
|
|
179
|
-
defaultTransport,
|
|
180
|
-
imageTransport,
|
|
181
|
-
wechatTransport
|
|
182
|
-
});
|
package/dist/cjs/types.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
|
|
15
|
-
// src/types.ts
|
|
16
|
-
var types_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(types_exports);
|
package/dist/cjs/utils.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/utils.ts
|
|
20
|
-
var utils_exports = {};
|
|
21
|
-
__export(utils_exports, {
|
|
22
|
-
getCurrentUrl: () => getCurrentUrl,
|
|
23
|
-
getEnvironmentInfo: () => getEnvironmentInfo,
|
|
24
|
-
getSessionId: () => getSessionId,
|
|
25
|
-
isBrowser: () => isBrowser,
|
|
26
|
-
isWeChatMiniProgram: () => isWeChatMiniProgram,
|
|
27
|
-
now: () => now,
|
|
28
|
-
parseBrowserInfo: () => parseBrowserInfo,
|
|
29
|
-
safeStringify: () => safeStringify
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(utils_exports);
|
|
32
|
-
var now = () => Date.now();
|
|
33
|
-
function isBrowser() {
|
|
34
|
-
try {
|
|
35
|
-
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
36
|
-
} catch (e) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function isWeChatMiniProgram() {
|
|
41
|
-
try {
|
|
42
|
-
return typeof wx !== "undefined" && typeof wx.getSystemInfo === "function";
|
|
43
|
-
} catch (e) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function safeStringify(obj) {
|
|
48
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
49
|
-
return JSON.stringify(obj, (_k, v) => {
|
|
50
|
-
if (v && typeof v === "object") {
|
|
51
|
-
if (seen.has(v))
|
|
52
|
-
return "[Circular]";
|
|
53
|
-
seen.add(v);
|
|
54
|
-
}
|
|
55
|
-
return v;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
var cachedSessionId = null;
|
|
59
|
-
function getSessionId() {
|
|
60
|
-
if (cachedSessionId)
|
|
61
|
-
return cachedSessionId;
|
|
62
|
-
if (isWeChatMiniProgram()) {
|
|
63
|
-
try {
|
|
64
|
-
const stored = wx.getStorageSync("logger_session_id");
|
|
65
|
-
if (stored) {
|
|
66
|
-
cachedSessionId = stored;
|
|
67
|
-
return stored;
|
|
68
|
-
}
|
|
69
|
-
} catch (e) {
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (isBrowser() && typeof sessionStorage !== "undefined") {
|
|
73
|
-
try {
|
|
74
|
-
const stored = sessionStorage.getItem("logger_session_id");
|
|
75
|
-
if (stored) {
|
|
76
|
-
cachedSessionId = stored;
|
|
77
|
-
return stored;
|
|
78
|
-
}
|
|
79
|
-
} catch (e) {
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
cachedSessionId = `${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
83
|
-
if (isWeChatMiniProgram()) {
|
|
84
|
-
try {
|
|
85
|
-
wx.setStorageSync("logger_session_id", cachedSessionId);
|
|
86
|
-
} catch (e) {
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (isBrowser() && typeof sessionStorage !== "undefined") {
|
|
90
|
-
try {
|
|
91
|
-
sessionStorage.setItem("logger_session_id", cachedSessionId);
|
|
92
|
-
} catch (e) {
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return cachedSessionId;
|
|
96
|
-
}
|
|
97
|
-
function getCurrentUrl() {
|
|
98
|
-
if (isWeChatMiniProgram()) {
|
|
99
|
-
try {
|
|
100
|
-
const pages = getCurrentPages();
|
|
101
|
-
if (pages && pages.length > 0) {
|
|
102
|
-
const currentPage = pages[pages.length - 1];
|
|
103
|
-
return currentPage.route || "";
|
|
104
|
-
}
|
|
105
|
-
} catch (e) {
|
|
106
|
-
return "";
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (isBrowser()) {
|
|
110
|
-
return window.location.href;
|
|
111
|
-
}
|
|
112
|
-
return "";
|
|
113
|
-
}
|
|
114
|
-
var cachedEnvInfo = null;
|
|
115
|
-
function getEnvironmentInfo() {
|
|
116
|
-
if (cachedEnvInfo)
|
|
117
|
-
return cachedEnvInfo;
|
|
118
|
-
const envInfo = {
|
|
119
|
-
platform: "unknown"
|
|
120
|
-
};
|
|
121
|
-
if (isWeChatMiniProgram()) {
|
|
122
|
-
envInfo.platform = "wechat";
|
|
123
|
-
try {
|
|
124
|
-
const systemInfo = wx.getSystemInfoSync();
|
|
125
|
-
envInfo.systemInfo = {
|
|
126
|
-
brand: systemInfo.brand,
|
|
127
|
-
model: systemInfo.model,
|
|
128
|
-
system: systemInfo.system,
|
|
129
|
-
platform: systemInfo.platform,
|
|
130
|
-
version: systemInfo.version,
|
|
131
|
-
SDKVersion: systemInfo.SDKVersion
|
|
132
|
-
};
|
|
133
|
-
envInfo.screenWidth = systemInfo.screenWidth;
|
|
134
|
-
envInfo.screenHeight = systemInfo.screenHeight;
|
|
135
|
-
envInfo.language = systemInfo.language;
|
|
136
|
-
} catch (e) {
|
|
137
|
-
}
|
|
138
|
-
} else if (isBrowser()) {
|
|
139
|
-
envInfo.platform = "browser";
|
|
140
|
-
envInfo.userAgent = navigator.userAgent;
|
|
141
|
-
envInfo.screenWidth = window.screen.width;
|
|
142
|
-
envInfo.screenHeight = window.screen.height;
|
|
143
|
-
envInfo.language = navigator.language;
|
|
144
|
-
}
|
|
145
|
-
cachedEnvInfo = envInfo;
|
|
146
|
-
return envInfo;
|
|
147
|
-
}
|
|
148
|
-
function parseBrowserInfo(userAgent) {
|
|
149
|
-
const ua = userAgent.toLowerCase();
|
|
150
|
-
let browser = "Unknown";
|
|
151
|
-
let browserVersion = "";
|
|
152
|
-
let os = "Unknown";
|
|
153
|
-
let osVersion = "";
|
|
154
|
-
if (ua.indexOf("chrome") > -1 && ua.indexOf("edge") === -1) {
|
|
155
|
-
browser = "Chrome";
|
|
156
|
-
const match = ua.match(/chrome\/(\d+\.\d+)/);
|
|
157
|
-
browserVersion = match ? match[1] : "";
|
|
158
|
-
} else if (ua.indexOf("safari") > -1 && ua.indexOf("chrome") === -1) {
|
|
159
|
-
browser = "Safari";
|
|
160
|
-
const match = ua.match(/version\/(\d+\.\d+)/);
|
|
161
|
-
browserVersion = match ? match[1] : "";
|
|
162
|
-
} else if (ua.indexOf("firefox") > -1) {
|
|
163
|
-
browser = "Firefox";
|
|
164
|
-
const match = ua.match(/firefox\/(\d+\.\d+)/);
|
|
165
|
-
browserVersion = match ? match[1] : "";
|
|
166
|
-
} else if (ua.indexOf("edge") > -1) {
|
|
167
|
-
browser = "Edge";
|
|
168
|
-
const match = ua.match(/edge\/(\d+\.\d+)/);
|
|
169
|
-
browserVersion = match ? match[1] : "";
|
|
170
|
-
}
|
|
171
|
-
if (ua.indexOf("windows") > -1) {
|
|
172
|
-
os = "Windows";
|
|
173
|
-
if (ua.indexOf("windows nt 10") > -1)
|
|
174
|
-
osVersion = "10";
|
|
175
|
-
else if (ua.indexOf("windows nt 6.3") > -1)
|
|
176
|
-
osVersion = "8.1";
|
|
177
|
-
else if (ua.indexOf("windows nt 6.2") > -1)
|
|
178
|
-
osVersion = "8";
|
|
179
|
-
else if (ua.indexOf("windows nt 6.1") > -1)
|
|
180
|
-
osVersion = "7";
|
|
181
|
-
} else if (ua.indexOf("mac os") > -1) {
|
|
182
|
-
os = "macOS";
|
|
183
|
-
const match = ua.match(/mac os x (\d+[._]\d+)/);
|
|
184
|
-
osVersion = match ? match[1].replace("_", ".") : "";
|
|
185
|
-
} else if (ua.indexOf("android") > -1) {
|
|
186
|
-
os = "Android";
|
|
187
|
-
const match = ua.match(/android (\d+\.\d+)/);
|
|
188
|
-
osVersion = match ? match[1] : "";
|
|
189
|
-
} else if (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1) {
|
|
190
|
-
os = "iOS";
|
|
191
|
-
const match = ua.match(/os (\d+[._]\d+)/);
|
|
192
|
-
osVersion = match ? match[1].replace("_", ".") : "";
|
|
193
|
-
} else if (ua.indexOf("linux") > -1) {
|
|
194
|
-
os = "Linux";
|
|
195
|
-
}
|
|
196
|
-
return { browser, browserVersion, os, osVersion };
|
|
197
|
-
}
|
|
198
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
-
0 && (module.exports = {
|
|
200
|
-
getCurrentUrl,
|
|
201
|
-
getEnvironmentInfo,
|
|
202
|
-
getSessionId,
|
|
203
|
-
isBrowser,
|
|
204
|
-
isWeChatMiniProgram,
|
|
205
|
-
now,
|
|
206
|
-
parseBrowserInfo,
|
|
207
|
-
safeStringify
|
|
208
|
-
});
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { LoggerSDK } from './loggerSDK';
|
|
2
|
-
export { defaultTransport, TransportAdapters } from './transportAdapter';
|
|
3
|
-
export type { TransportAdapter, TransportOptions } from './transportAdapter';
|
|
4
|
-
export type { SDKOptions, LogEvent, LogEventType, LogEventLevel, Env } from './types';
|
|
5
|
-
export type { PlatformType, EnvironmentInfo } from './utils';
|
|
6
|
-
export { getEnvironmentInfo, parseBrowserInfo, isWeChatMiniProgram } from './utils';
|
package/dist/esm/loggerSDK.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { SDKOptions, LogEventType, LogEventLevel } from './types';
|
|
2
|
-
export declare class LoggerSDK {
|
|
3
|
-
private opts;
|
|
4
|
-
private seq;
|
|
5
|
-
private closed;
|
|
6
|
-
/** 预收集的环境信息 tags */
|
|
7
|
-
private envTags;
|
|
8
|
-
constructor(options: SDKOptions);
|
|
9
|
-
private logDebug;
|
|
10
|
-
/**
|
|
11
|
-
* 收集环境信息并生成 tags(仅在初始化时执行一次)
|
|
12
|
-
*/
|
|
13
|
-
private collectEnvironmentTags;
|
|
14
|
-
/**
|
|
15
|
-
* 记录事件
|
|
16
|
-
*/
|
|
17
|
-
track(eventType: LogEventType, message: string, options?: {
|
|
18
|
-
level?: LogEventLevel;
|
|
19
|
-
stack?: string;
|
|
20
|
-
userId?: string;
|
|
21
|
-
tags?: Record<string, any>;
|
|
22
|
-
}): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* 设置用户信息
|
|
25
|
-
*/
|
|
26
|
-
identify(userId: string): void;
|
|
27
|
-
/**
|
|
28
|
-
* 销毁实例
|
|
29
|
-
*/
|
|
30
|
-
destroy(): void;
|
|
31
|
-
/**
|
|
32
|
-
* 监听页面卸载事件
|
|
33
|
-
*/
|
|
34
|
-
private attachUnloadHandlers;
|
|
35
|
-
}
|
|
36
|
-
export default LoggerSDK;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { SDKOptions } from './types';
|
|
2
|
-
/** 传输选项接口 */
|
|
3
|
-
export interface TransportOptions extends Omit<SDKOptions, 'endpoint'> {
|
|
4
|
-
endpoint: string;
|
|
5
|
-
}
|
|
6
|
-
/** 传输适配器接口 */
|
|
7
|
-
export interface TransportAdapter {
|
|
8
|
-
/** 适配器名称 */
|
|
9
|
-
name: string;
|
|
10
|
-
/** 是否支持当前环境 */
|
|
11
|
-
isSupported(opts?: TransportOptions): boolean;
|
|
12
|
-
/** 发送数据 */
|
|
13
|
-
send(payload: any, opts?: TransportOptions): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Beacon 传输适配器
|
|
17
|
-
* - 兼容性:现代浏览器(Chrome 39+, Firefox 31+, Edge 14+)
|
|
18
|
-
* - 健壮性:页面卸载时可靠传输、不阻塞页面卸载
|
|
19
|
-
* - 适用场景:页面关闭、visibilitychange、pagehide、beforeunload 事件
|
|
20
|
-
* - 限制:无法获取响应、队列有大小限制(通常 64KB)
|
|
21
|
-
*/
|
|
22
|
-
export declare const beaconTransport: TransportAdapter;
|
|
23
|
-
/**
|
|
24
|
-
* 微信小程序传输适配器
|
|
25
|
-
* - 兼容性:微信小程序环境
|
|
26
|
-
* - 健壮性:支持超时控制、完善的错误处理
|
|
27
|
-
* - 适用场景:微信小程序环境下的日志上报
|
|
28
|
-
*/
|
|
29
|
-
export declare const wechatTransport: TransportAdapter;
|
|
30
|
-
/**
|
|
31
|
-
* Image 像素上报适配器
|
|
32
|
-
* - 兼容性:所有浏览器
|
|
33
|
-
* - 健壮性:轻量级、无跨域限制、支持超时控制
|
|
34
|
-
* - 适用场景:数据量小的快速上报、跨域场景、降级方案
|
|
35
|
-
* - 限制:URL 长度限制(默认 1900 字符)
|
|
36
|
-
*/
|
|
37
|
-
export declare const imageTransport: TransportAdapter;
|
|
38
|
-
/**
|
|
39
|
-
* 默认传输函数 - 按环境选择最佳传输方式
|
|
40
|
-
* 浏览器策略:Beacon(可靠) > Image(兼容)
|
|
41
|
-
* 微信小程序策略:WeChat Request
|
|
42
|
-
*/
|
|
43
|
-
export declare function defaultTransport(payload: any, opts?: TransportOptions): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* 导出所有适配器,方便自定义使用
|
|
46
|
-
*/
|
|
47
|
-
export declare const TransportAdapters: {
|
|
48
|
-
beacon: TransportAdapter;
|
|
49
|
-
wechat: TransportAdapter;
|
|
50
|
-
image: TransportAdapter;
|
|
51
|
-
};
|
package/dist/esm/types.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/** 环境类型 */
|
|
2
|
-
export type Env = 'prod' | 'stage' | 'dev';
|
|
3
|
-
/** 事件类型 */
|
|
4
|
-
export type LogEventType = 'error' | 'crash' | 'pageview' | 'custom';
|
|
5
|
-
/** 日志级别 */
|
|
6
|
-
export type LogEventLevel = 'info' | 'warn' | 'error' | 'fatal';
|
|
7
|
-
/** SDK 配置选项 */
|
|
8
|
-
export interface SDKOptions {
|
|
9
|
-
/** 上报端点 URL */
|
|
10
|
-
endpoint: string;
|
|
11
|
-
/** 应用 ID */
|
|
12
|
-
appId?: string;
|
|
13
|
-
/** 环境标识 */
|
|
14
|
-
env?: Env;
|
|
15
|
-
/** 是否开启调试模式 */
|
|
16
|
-
debug?: boolean;
|
|
17
|
-
/** 像素上报参数名,默认 'data' */
|
|
18
|
-
pixelParam?: string;
|
|
19
|
-
/** 像素上报 URL 最大长度,默认 1900 */
|
|
20
|
-
maxPixelUrlLen?: number;
|
|
21
|
-
}
|
|
22
|
-
/** 标准化日志上报格式 */
|
|
23
|
-
export interface LogEvent {
|
|
24
|
-
/** 事件类型:error/crash/pageview/custom */
|
|
25
|
-
eventType: LogEventType;
|
|
26
|
-
/** 毫秒时间戳 */
|
|
27
|
-
ts: number;
|
|
28
|
-
/** 应用标识 */
|
|
29
|
-
appId: string;
|
|
30
|
-
/** 环境标识:prod/stage/dev */
|
|
31
|
-
env: Env;
|
|
32
|
-
/** 日志级别:info/warn/error/fatal */
|
|
33
|
-
level: LogEventLevel;
|
|
34
|
-
/** 摘要信息 */
|
|
35
|
-
message: string;
|
|
36
|
-
/** 可选:堆栈信息(长字符串) */
|
|
37
|
-
stack?: string;
|
|
38
|
-
/** 发生页面 URL */
|
|
39
|
-
url: string;
|
|
40
|
-
/** 可选:用户 ID(脱敏) */
|
|
41
|
-
userId?: string;
|
|
42
|
-
/** 会话标识 */
|
|
43
|
-
sessionId: string;
|
|
44
|
-
/** 可选的结构化额外信息 */
|
|
45
|
-
tags?: Record<string, any>;
|
|
46
|
-
}
|
package/dist/esm/utils.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export declare const now: () => number;
|
|
2
|
-
export declare function isBrowser(): boolean;
|
|
3
|
-
export declare function isWeChatMiniProgram(): boolean;
|
|
4
|
-
export declare function safeStringify(obj: any): string;
|
|
5
|
-
export declare function getSessionId(): string;
|
|
6
|
-
export declare function getCurrentUrl(): string;
|
|
7
|
-
/** 平台类型 */
|
|
8
|
-
export type PlatformType = 'browser' | 'wechat' | 'unknown';
|
|
9
|
-
/** 环境信息 */
|
|
10
|
-
export interface EnvironmentInfo {
|
|
11
|
-
platform: PlatformType;
|
|
12
|
-
userAgent?: string;
|
|
13
|
-
screenWidth?: number;
|
|
14
|
-
screenHeight?: number;
|
|
15
|
-
language?: string;
|
|
16
|
-
systemInfo?: any;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 获取环境信息
|
|
20
|
-
*/
|
|
21
|
-
export declare function getEnvironmentInfo(): EnvironmentInfo;
|
|
22
|
-
/**
|
|
23
|
-
* 解析浏览器信息
|
|
24
|
-
*/
|
|
25
|
-
export declare function parseBrowserInfo(userAgent: string): {
|
|
26
|
-
browser: string;
|
|
27
|
-
browserVersion: string;
|
|
28
|
-
os: string;
|
|
29
|
-
osVersion: string;
|
|
30
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LoggerSDK=t():e.LoggerSDK=t()}(self,(function(){return function(){var e={750:function(e){function t(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}e.exports=function(e){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=e.apply(r,n);function s(e){t(a,o,i,s,c,"next",e)}function c(e){t(a,o,i,s,c,"throw",e)}s(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},811:function(e){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},997:function(e,t,r){var n=r(969);function o(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,n(o.key),o)}}e.exports=function(e,t,r){return t&&o(e.prototype,t),r&&o(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},411:function(e,t,r){var n=r(969);e.exports=function(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports},731:function(e,t,r){var n=r(411);function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}e.exports=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e},e.exports.__esModule=!0,e.exports.default=e.exports},25:function(e,t,r){var n=r(505).default;function o(){"use strict";e.exports=o=function(){return r},e.exports.__esModule=!0,e.exports.default=e.exports;var t,r={},i=Object.prototype,a=i.hasOwnProperty,s=Object.defineProperty||function(e,t,r){e[t]=r.value},c="function"==typeof Symbol?Symbol:{},u=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function d(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{d({},"")}catch(t){d=function(e,t,r){return e[t]=r}}function p(e,t,r,n){var o=t&&t.prototype instanceof w?t:w,i=Object.create(o.prototype),a=new D(n||[]);return s(i,"_invoke",{value:P(e,r,a)}),i}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=p;var v="suspendedStart",g="executing",y="completed",m={};function w(){}function x(){}function b(){}var O={};d(O,u,(function(){return this}));var _=Object.getPrototypeOf,S=_&&_(_(M([])));S&&S!==i&&a.call(S,u)&&(O=S);var E=b.prototype=w.prototype=Object.create(O);function L(e){["next","throw","return"].forEach((function(t){d(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){function r(o,i,s,c){var u=h(e[o],e,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==n(l)&&a.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,s,c)}),(function(e){r("throw",e,s,c)})):t.resolve(l).then((function(e){f.value=e,s(f)}),(function(e){return r("throw",e,s,c)}))}c(u.arg)}var o;s(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,o){r(e,n,t,o)}))}return o=o?o.then(i,i):i()}})}function P(e,r,n){var o=v;return function(i,a){if(o===g)throw new Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var c=j(s,n);if(c){if(c===m)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===v)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=g;var u=h(e,r,n);if("normal"===u.type){if(o=n.done?y:"suspendedYield",u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(o=y,n.method="throw",n.arg=u.arg)}}}function j(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,j(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function I(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function D(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(I,this),this.reset(!0)}function M(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(a.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(n(e)+" is not iterable")}return x.prototype=b,s(E,"constructor",{value:b,configurable:!0}),s(b,"constructor",{value:x,configurable:!0}),x.displayName=d(b,l,"GeneratorFunction"),r.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===x||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,d(e,l,"GeneratorFunction")),e.prototype=Object.create(E),e},r.awrap=function(e){return{__await:e}},L(k.prototype),d(k.prototype,f,(function(){return this})),r.AsyncIterator=k,r.async=function(e,t,n,o,i){void 0===i&&(i=Promise);var a=new k(p(e,t,n,o),i);return r.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},L(E),d(E,l,"Generator"),d(E,u,(function(){return this})),d(E,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=M,D.prototype={constructor:D,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return s.type="throw",s.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),u=a.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),m},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:M(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},r}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports},159:function(e,t,r){var n=r(505).default;e.exports=function(e,t){if("object"!=n(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},969:function(e,t,r){var n=r(505).default,o=r(159);e.exports=function(e){var t=o(e,"string");return"symbol"==n(t)?t:String(t)},e.exports.__esModule=!0,e.exports.default=e.exports},505:function(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return function(){"use strict";r.r(n),r.d(n,{LoggerSDK:function(){return M},TransportAdapters:function(){return D},defaultTransport:function(){return I},getEnvironmentInfo:function(){return S},isWeChatMiniProgram:function(){return m},parseBrowserInfo:function(){return E}});var e=r(25),t=r.n(e),o=r(731),i=r.n(o),a=r(750),s=r.n(a),c=r(811),u=r.n(c),f=r(997),l=r.n(f),d=r(411),p=r.n(d),h=r(505),v=r.n(h),g=function(){return Date.now()};function y(){try{return"undefined"!=typeof window&&void 0!==window.document}catch(e){return!1}}function m(){try{return"undefined"!=typeof wx&&"function"==typeof wx.getSystemInfo}catch(e){return!1}}function w(e){var t=new WeakSet;return JSON.stringify(e,(function(e,r){if(r&&"object"===v()(r)){if(t.has(r))return"[Circular]";t.add(r)}return r}))}var x=null;function b(){if(x)return x;if(m())try{var e=wx.getStorageSync("logger_session_id");if(e)return x=e,e}catch(e){}if(y()&&"undefined"!=typeof sessionStorage)try{var t=sessionStorage.getItem("logger_session_id");if(t)return x=t,t}catch(e){}if(x="".concat(Date.now(),"_").concat(Math.random().toString(36).substring(2,15)),m())try{wx.setStorageSync("logger_session_id",x)}catch(e){}if(y()&&"undefined"!=typeof sessionStorage)try{sessionStorage.setItem("logger_session_id",x)}catch(e){}return x}function O(){if(m())try{var e=getCurrentPages();if(e&&e.length>0)return e[e.length-1].route||""}catch(e){return""}return y()?window.location.href:""}var _=null;function S(){if(_)return _;var e={platform:"unknown"};if(m()){e.platform="wechat";try{var t=wx.getSystemInfoSync();e.systemInfo={brand:t.brand,model:t.model,system:t.system,platform:t.platform,version:t.version,SDKVersion:t.SDKVersion},e.screenWidth=t.screenWidth,e.screenHeight=t.screenHeight,e.language=t.language}catch(e){}}else y()&&(e.platform="browser",e.userAgent=navigator.userAgent,e.screenWidth=window.screen.width,e.screenHeight=window.screen.height,e.language=navigator.language);return _=e,e}function E(e){var t=e.toLowerCase(),r="Unknown",n="",o="Unknown",i="";if(t.indexOf("chrome")>-1&&-1===t.indexOf("edge")){r="Chrome";var a=t.match(/chrome\/(\d+\.\d+)/);n=a?a[1]:""}else if(t.indexOf("safari")>-1&&-1===t.indexOf("chrome")){r="Safari";var s=t.match(/version\/(\d+\.\d+)/);n=s?s[1]:""}else if(t.indexOf("firefox")>-1){r="Firefox";var c=t.match(/firefox\/(\d+\.\d+)/);n=c?c[1]:""}else if(t.indexOf("edge")>-1){r="Edge";var u=t.match(/edge\/(\d+\.\d+)/);n=u?u[1]:""}if(t.indexOf("windows")>-1)o="Windows",t.indexOf("windows nt 10")>-1?i="10":t.indexOf("windows nt 6.3")>-1?i="8.1":t.indexOf("windows nt 6.2")>-1?i="8":t.indexOf("windows nt 6.1")>-1&&(i="7");else if(t.indexOf("mac os")>-1){o="macOS";var f=t.match(/mac os x (\d+[._]\d+)/);i=f?f[1].replace("_","."):""}else if(t.indexOf("android")>-1){o="Android";var l=t.match(/android (\d+\.\d+)/);i=l?l[1]:""}else if(t.indexOf("iphone")>-1||t.indexOf("ipad")>-1){o="iOS";var d=t.match(/os (\d+[._]\d+)/);i=d?d[1].replace("_","."):""}else t.indexOf("linux")>-1&&(o="Linux");return{browser:r,browserVersion:n,os:o,osVersion:i}}function L(e){return(null==e?void 0:e.endpoint)||""}var k={name:"beacon",isSupported:function(){return y()&&"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon},send:function(e,r){return s()(t()().mark((function n(){var o,i,a;return t()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o="string"==typeof e?e:w(e),i=L(r),a=new Blob([o],{type:"application/json"}),navigator.sendBeacon(i,a)){t.next=6;break}throw new Error("sendBeacon failed (queue full or other error)");case 6:case"end":return t.stop()}}),n)})))()}},P={name:"wechat",isSupported:function(){return m()},send:function(e,r){return s()(t()().mark((function n(){var o,i;return t()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o="string"==typeof e?e:w(e),i=L(r),1e4,t.abrupt("return",new Promise((function(e,t){var r,n=!1;r=setTimeout((function(){n||(n=!0,t(new Error("WeChat request timeout after ".concat(1e4,"ms"))))}),1e4),wx.request({url:i,method:"POST",data:o,header:{"Content-Type":"application/json"},success:function(o){r&&clearTimeout(r),n||(n=!0,o.statusCode>=200&&o.statusCode<300?e():t(new Error("HTTP ".concat(o.statusCode))))},fail:function(e){r&&clearTimeout(r),n||(n=!0,t(new Error("WeChat request failed: ".concat(e.errMsg||"unknown error"))))}})})));case 4:case"end":return t.stop()}}),n)})))()}},j={name:"image",isSupported:function(){return y()&&"undefined"!=typeof Image},send:function(e,r){return s()(t()().mark((function n(){var o,i,a,s,c,u,f;return t()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o="string"==typeof e?e:w(e),i=L(r),a=(null==r?void 0:r.pixelParam)||"data",s=(null==r?void 0:r.maxPixelUrlLen)||1900,c="_=".concat(g()),u="".concat(a,"=").concat(encodeURIComponent(o),"&").concat(c),!((f=i.includes("?")?"".concat(i,"&").concat(u):"".concat(i,"?").concat(u)).length>s)){t.next=9;break}throw new Error("URL too long (".concat(f.length," > ").concat(s,")"));case 9:return t.abrupt("return",new Promise((function(e,t){var r,n=new Image,o=!1;r=setTimeout((function(){o||(o=!0,n.src="",t(new Error("Image request timeout after 5000ms")))}),5e3),n.onload=function(){r&&clearTimeout(r),o||(o=!0,e())},n.onerror=function(){r&&clearTimeout(r),o||(o=!0,t(new Error("Image request failed")))},n.src=f})));case 10:case"end":return t.stop()}}),n)})))()}};function I(e,t){return T.apply(this,arguments)}function T(){return(T=s()(t()().mark((function e(r,n){var o;return t()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!m()){e.next=5;break}if(!P.isSupported(n)){e.next=5;break}return e.next=4,P.send(r,n);case 4:case 20:return e.abrupt("return");case 5:if(o=[k,j].find((function(e){return e.isSupported(n)}))){e.next=9;break}throw new Error("No supported transport adapter available");case 9:return e.prev=9,e.next=12,o.send(r,n);case 12:e.next=27;break;case 14:if(e.prev=14,e.t0=e.catch(9),"beacon"!==o.name||!j.isSupported(n)){e.next=26;break}return e.prev=17,e.next=20,j.send(r,n);case 23:throw e.prev=23,e.t1=e.catch(17),e.t0;case 26:throw e.t0;case 27:case"end":return e.stop()}}),e,null,[[9,14],[17,23]])})))).apply(this,arguments)}var D={beacon:k,wechat:P,image:j},M=function(){function e(t){u()(this,e),p()(this,"opts",void 0),p()(this,"seq",0),p()(this,"closed",!1),p()(this,"envTags",void 0),this.opts={endpoint:t.endpoint,appId:t.appId||"unknown",env:t.env||"dev",debug:!!t.debug,pixelParam:t.pixelParam||"data",maxPixelUrlLen:t.maxPixelUrlLen||1900},this.envTags=this.collectEnvironmentTags(),this.attachUnloadHandlers()}var r;return l()(e,[{key:"logDebug",value:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];this.opts.debug&&(e=console).debug.apply(e,["[LoggerSDK]"].concat(r))}},{key:"collectEnvironmentTags",value:function(){var e=S(),t={platform:e.platform};if("browser"===e.platform&&e.userAgent){var r=E(e.userAgent);t.browser=r.browser,t.browserVersion=r.browserVersion,t.os=r.os,t.osVersion=r.osVersion,t.screenWidth=e.screenWidth,t.screenHeight=e.screenHeight,t.language=e.language}else"wechat"===e.platform&&e.systemInfo&&(t.brand=e.systemInfo.brand,t.model=e.systemInfo.model,t.system=e.systemInfo.system,t.wechatVersion=e.systemInfo.version,t.SDKVersion=e.systemInfo.SDKVersion,t.screenWidth=e.screenWidth,t.screenHeight=e.screenHeight,t.language=e.language);return this.logDebug("Environment tags collected:",t),t}},{key:"track",value:(r=s()(t()().mark((function e(r,n,o){var a;return t()().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.closed){e.next=2;break}return e.abrupt("return");case 2:return this.seq+=1,a={eventType:r,ts:g(),appId:this.opts.appId||"unknown",env:this.opts.env||"dev",level:(null==o?void 0:o.level)||"info",message:n,stack:null==o?void 0:o.stack,url:O(),userId:null==o?void 0:o.userId,sessionId:b(),tags:i()(i()({},this.envTags),(null==o?void 0:o.tags)||{})},this.logDebug("track",a),e.prev=5,e.next=8,I(a,this.opts);case 8:e.next=13;break;case 10:e.prev=10,e.t0=e.catch(5),this.logDebug("track failed",e.t0);case 13:case"end":return e.stop()}}),e,this,[[5,10]])}))),function(e,t,n){return r.apply(this,arguments)})},{key:"identify",value:function(e){this.logDebug("identify",e)}},{key:"destroy",value:function(){this.closed=!0}},{key:"attachUnloadHandlers",value:function(){if(m())this.logDebug("WeChat MiniProgram environment detected");else if(y()){var e=window;document.addEventListener&&document.addEventListener("visibilitychange",(function(){try{"hidden"===document.visibilityState&&console.log("Page hidden")}catch(e){}})),e.addEventListener&&e.addEventListener("pagehide",(function(){try{console.log("Page hide")}catch(e){}})),e.addEventListener&&e.addEventListener("beforeunload",(function(){try{console.log("Page unload")}catch(e){}}))}}}]),e}()}(),n}()}));
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|