@pluve/logger-sdk 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -2
- package/dist/{cjs/index.d.ts → index.d.ts} +1 -1
- package/dist/{esm/index.js → index.js} +2 -2
- package/dist/{cjs/loggerSDK.d.ts → loggerSDK.d.ts} +1 -1
- package/dist/{esm/loggerSDK.js → loggerSDK.js} +8 -4
- package/dist/{esm/transportAdapter.js → transportAdapter.js} +34 -10
- package/dist/{esm/types.d.ts → types.d.ts} +5 -1
- package/dist/{esm/utils.d.ts → utils.d.ts} +17 -0
- package/dist/utils.js +361 -0
- package/package.json +3 -5
- 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.d.ts +0 -46
- package/dist/cjs/types.js +0 -17
- package/dist/cjs/utils.d.ts +0 -30
- 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/utils.js +0 -229
- package/dist/umd/logger-sdk.min.js +0 -1
- package/lib/dbQueue.d.ts +0 -10
- package/lib/dbQueue.js +0 -133
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -9
- package/lib/loggerSDK.d.ts +0 -29
- package/lib/loggerSDK.js +0 -571
- package/lib/storeAdapter.d.ts +0 -7
- package/lib/storeAdapter.js +0 -99
- package/lib/transportAdapter.d.ts +0 -66
- package/lib/transportAdapter.js +0 -406
- package/lib/types.d.ts +0 -35
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +0 -5
- package/lib/utils.js +0 -50
- /package/dist/{cjs/transportAdapter.d.ts → transportAdapter.d.ts} +0 -0
- /package/dist/{esm/types.js → types.js} +0 -0
|
@@ -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.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/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.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
|
-
};
|
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
|
-
};
|