@pluve/logger-sdk 0.0.7 → 0.0.9

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.
Files changed (100) hide show
  1. package/README.html +681 -0
  2. package/README.md +131 -153
  3. package/dist/cjs/capture/jsError.js +48 -0
  4. package/dist/cjs/capture/promiseError.js +49 -0
  5. package/dist/cjs/capture/resourceError.js +48 -0
  6. package/dist/cjs/capture/wechatError.js +95 -0
  7. package/dist/cjs/compress/compression.js +84 -0
  8. package/dist/cjs/config/index.js +55 -0
  9. package/dist/cjs/core/fingerprint.js +36 -0
  10. package/dist/cjs/core/httpClient.js +96 -0
  11. package/dist/cjs/core/loggerSDK.js +641 -0
  12. package/dist/cjs/core/queueManager.js +249 -0
  13. package/dist/cjs/core/retryManager.js +127 -0
  14. package/dist/cjs/index.js +29 -0
  15. package/dist/cjs/stack/stacktrace.js +48 -0
  16. package/dist/cjs/transport/beaconTransport.js +64 -0
  17. package/dist/cjs/transport/pixelImageTransport.js +100 -0
  18. package/dist/cjs/transport/transport.js +17 -0
  19. package/dist/cjs/transport/transportAdapter.js +56 -0
  20. package/dist/cjs/transport/wechatTransport.js +103 -0
  21. package/dist/cjs/types/api.js +17 -0
  22. package/dist/cjs/types/env.js +17 -0
  23. package/dist/cjs/types/external.d.ts +21 -0
  24. package/dist/cjs/types/logEvent.js +17 -0
  25. package/dist/cjs/types/logEventLevel.js +17 -0
  26. package/dist/cjs/types/sdkOptions.js +17 -0
  27. package/dist/cjs/types/trackOptions.js +17 -0
  28. package/dist/cjs/utils/environment.js +183 -0
  29. package/dist/cjs/utils/session.js +31 -0
  30. package/dist/cjs/utils/tools.js +82 -0
  31. package/dist/cjs/utils/uuid.js +35 -0
  32. package/dist/esm/capture/jsError.js +45 -0
  33. package/dist/esm/capture/promiseError.js +46 -0
  34. package/dist/esm/capture/resourceError.js +24 -0
  35. package/dist/esm/capture/wechatError.js +92 -0
  36. package/dist/esm/compress/compression.js +82 -0
  37. package/dist/esm/config/index.js +28 -0
  38. package/dist/esm/core/fingerprint.js +12 -0
  39. package/dist/esm/core/httpClient.js +95 -0
  40. package/dist/esm/core/loggerSDK.js +650 -0
  41. package/dist/esm/core/queueManager.js +269 -0
  42. package/dist/esm/core/retryManager.js +129 -0
  43. package/dist/esm/index.js +5 -0
  44. package/dist/esm/stack/stacktrace.js +37 -0
  45. package/dist/esm/transport/beaconTransport.js +81 -0
  46. package/dist/esm/transport/pixelImageTransport.js +99 -0
  47. package/dist/esm/transport/transport.js +0 -0
  48. package/dist/esm/transport/transportAdapter.js +32 -0
  49. package/dist/esm/transport/wechatTransport.js +120 -0
  50. package/dist/esm/types/api.js +0 -0
  51. package/dist/esm/types/env.js +0 -0
  52. package/dist/esm/types/external.d.ts +21 -0
  53. package/dist/esm/types/logEvent.js +0 -0
  54. package/dist/esm/types/logEventLevel.js +0 -0
  55. package/dist/esm/types/sdkOptions.js +0 -0
  56. package/dist/esm/types/trackOptions.js +0 -0
  57. package/dist/esm/utils/environment.js +154 -0
  58. package/dist/esm/utils/session.js +7 -0
  59. package/dist/esm/utils/tools.js +76 -0
  60. package/dist/esm/utils/uuid.js +11 -0
  61. package/dist/types/capture/jsError.d.ts +2 -0
  62. package/dist/types/capture/promiseError.d.ts +2 -0
  63. package/dist/types/capture/resourceError.d.ts +2 -0
  64. package/dist/types/capture/wechatError.d.ts +3 -0
  65. package/dist/types/compress/compression.d.ts +10 -0
  66. package/dist/types/config/index.d.ts +9 -0
  67. package/dist/types/core/fingerprint.d.ts +8 -0
  68. package/dist/types/core/httpClient.d.ts +11 -0
  69. package/dist/{loggerSDK.d.ts → types/core/loggerSDK.d.ts} +27 -2
  70. package/dist/{queueManager.d.ts → types/core/queueManager.d.ts} +9 -1
  71. package/dist/{retryManager.d.ts → types/core/retryManager.d.ts} +0 -4
  72. package/dist/types/index.d.ts +1 -0
  73. package/dist/types/stack/stacktrace.d.ts +2 -0
  74. package/dist/types/transport/beaconTransport.d.ts +11 -0
  75. package/dist/types/transport/pixelImageTransport.d.ts +11 -0
  76. package/dist/types/transport/transport.d.ts +14 -0
  77. package/dist/types/transport/transportAdapter.d.ts +10 -0
  78. package/dist/types/transport/wechatTransport.d.ts +11 -0
  79. package/dist/types/types/api.d.ts +12 -0
  80. package/dist/types/types/env.d.ts +14 -0
  81. package/dist/types/types/logEvent.d.ts +57 -0
  82. package/dist/types/types/logEventLevel.d.ts +2 -0
  83. package/dist/{types.d.ts → types/types/sdkOptions.d.ts} +23 -42
  84. package/dist/types/types/trackOptions.d.ts +7 -0
  85. package/dist/types/utils/environment.d.ts +21 -0
  86. package/dist/types/utils/session.d.ts +1 -0
  87. package/dist/types/utils/tools.d.ts +12 -0
  88. package/dist/types/utils/uuid.d.ts +7 -0
  89. package/dist/umd/logger-sdk.min.js +1 -0
  90. package/package.json +29 -5
  91. package/dist/index.d.ts +0 -10
  92. package/dist/index.js +0 -13
  93. package/dist/loggerSDK.js +0 -560
  94. package/dist/queueManager.js +0 -186
  95. package/dist/retryManager.js +0 -224
  96. package/dist/transportAdapter.d.ts +0 -51
  97. package/dist/transportAdapter.js +0 -315
  98. package/dist/types.js +0 -1
  99. package/dist/utils.d.ts +0 -52
  100. package/dist/utils.js +0 -348
@@ -0,0 +1,120 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+
41
+ // src/transport/wechatTransport.ts
42
+ import { gzipCompress } from "../compress/compression";
43
+ import { getReportApi } from "../config";
44
+ import { isWeChatMiniProgram } from "../utils/environment";
45
+ import { logDebug, now, safeStringify } from "../utils/tools";
46
+ var WechatTransport = class {
47
+ constructor(opts) {
48
+ /** 传输器名称 */
49
+ this.name = "wechat";
50
+ this.opts = opts;
51
+ }
52
+ // eslint-disable-next-line class-methods-use-this
53
+ isSupported() {
54
+ return isWeChatMiniProgram();
55
+ }
56
+ send(payload) {
57
+ return __async(this, null, function* () {
58
+ var _a, _b, _c, _d, _e;
59
+ let body = typeof payload === "string" ? payload : safeStringify(payload);
60
+ const endpoint = getReportApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop");
61
+ const timeout = 1e4;
62
+ let contentType = "application/json";
63
+ if (((_b = this.opts) == null ? void 0 : _b.enableGzip) && (!((_c = this.opts) == null ? void 0 : _c.gzipOnlyInBatchMode) || payload.items.length > 0)) {
64
+ const t = now();
65
+ logDebug(!!((_d = this.opts) == null ? void 0 : _d.debug), "WeChat request enable gzip compress: ", t);
66
+ const compressedItems = yield gzipCompress(safeStringify(payload.items));
67
+ body = safeStringify(__spreadProps(__spreadValues({}, payload), {
68
+ items: compressedItems
69
+ }));
70
+ logDebug(!!((_e = this.opts) == null ? void 0 : _e.debug), "WeChat request gzip compress cost: ", now() - t);
71
+ contentType = "application/json; charset=utf-8";
72
+ }
73
+ return new Promise((resolve, reject) => {
74
+ var _a2;
75
+ let timeoutId = null;
76
+ let settled = false;
77
+ timeoutId = setTimeout(() => {
78
+ if (!settled) {
79
+ settled = true;
80
+ reject(new Error(`WeChat request timeout after ${timeout}ms`));
81
+ }
82
+ }, timeout);
83
+ wx.request({
84
+ url: endpoint,
85
+ method: "POST",
86
+ data: body,
87
+ header: {
88
+ "Content-Type": contentType,
89
+ token: ((_a2 = this.opts) == null ? void 0 : _a2.token) || ""
90
+ },
91
+ success(res) {
92
+ if (timeoutId)
93
+ clearTimeout(timeoutId);
94
+ if (!settled) {
95
+ settled = true;
96
+ if (res.statusCode >= 200 && res.statusCode < 300) {
97
+ resolve();
98
+ } else {
99
+ reject(new Error(`HTTP ${res.statusCode}`));
100
+ }
101
+ }
102
+ },
103
+ fail(err) {
104
+ var _a3;
105
+ if (timeoutId)
106
+ clearTimeout(timeoutId);
107
+ if (!settled) {
108
+ settled = true;
109
+ logDebug(!!((_a3 = this.opts) == null ? void 0 : _a3.debug), "WeChat request failed", err);
110
+ reject(new Error(`WeChat request failed: ${err.errMsg || "unknown error"}`));
111
+ }
112
+ }
113
+ });
114
+ });
115
+ });
116
+ }
117
+ };
118
+ export {
119
+ WechatTransport
120
+ };
File without changes
File without changes
@@ -0,0 +1,21 @@
1
+ declare module 'fflate' {
2
+ export function gzipSync(input: Uint8Array | string): Uint8Array;
3
+ }
4
+
5
+ declare module 'js-base64' {
6
+ export const Base64: {
7
+ encode(input: string | Uint8Array, urlSafe?: boolean): string;
8
+ decode(input: string): string;
9
+ fromUint8Array(input: Uint8Array, urlSafe?: boolean): string;
10
+ toUint8Array(input: string): Uint8Array;
11
+ };
12
+ }
13
+
14
+ declare class CompressionStream {
15
+ constructor(format: 'gzip' | 'deflate');
16
+ readable: ReadableStream<any>;
17
+
18
+ writable: WritableStream<any>;
19
+ }
20
+
21
+ declare let Buffer: any;
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,154 @@
1
+ // src/utils/environment.ts
2
+ function isBrowser() {
3
+ try {
4
+ return typeof window !== "undefined" && typeof window.document !== "undefined";
5
+ } catch (e) {
6
+ return false;
7
+ }
8
+ }
9
+ function isWeChatMiniProgram() {
10
+ try {
11
+ return typeof wx !== "undefined" && typeof wx.getSystemInfo === "function";
12
+ } catch (e) {
13
+ return false;
14
+ }
15
+ }
16
+ function getCurrentUrl() {
17
+ if (isWeChatMiniProgram()) {
18
+ try {
19
+ const pages = getCurrentPages();
20
+ if (pages && pages.length > 0) {
21
+ const currentPage = pages[pages.length - 1];
22
+ return currentPage.route || "";
23
+ }
24
+ } catch (e) {
25
+ return "";
26
+ }
27
+ }
28
+ if (isBrowser()) {
29
+ return window.location.href;
30
+ }
31
+ return "";
32
+ }
33
+ function getEnvironmentInfo() {
34
+ const envInfo = {
35
+ platform: "unknown"
36
+ };
37
+ if (isWeChatMiniProgram()) {
38
+ envInfo.platform = "wechat";
39
+ try {
40
+ const systemInfo = wx.getSystemInfoSync();
41
+ envInfo.systemInfo = {
42
+ brand: systemInfo.brand,
43
+ model: systemInfo.model,
44
+ system: systemInfo.system,
45
+ platform: systemInfo.platform,
46
+ version: systemInfo.version,
47
+ SDKVersion: systemInfo.SDKVersion
48
+ };
49
+ envInfo.screenWidth = systemInfo.screenWidth;
50
+ envInfo.screenHeight = systemInfo.screenHeight;
51
+ envInfo.language = systemInfo.language;
52
+ } catch (e) {
53
+ }
54
+ } else if (isBrowser()) {
55
+ envInfo.platform = "browser";
56
+ envInfo.userAgent = navigator.userAgent;
57
+ envInfo.screenWidth = window.screen.width;
58
+ envInfo.screenHeight = window.screen.height;
59
+ envInfo.language = navigator.language;
60
+ }
61
+ return envInfo;
62
+ }
63
+ function parseBrowserInfo(userAgent) {
64
+ const ua = userAgent.toLowerCase();
65
+ let browser = "Unknown";
66
+ let browserVersion = "";
67
+ let os = "Unknown";
68
+ let osVersion = "";
69
+ if (ua.indexOf("chrome") > -1 && ua.indexOf("edge") === -1) {
70
+ browser = "Chrome";
71
+ const match = ua.match(/chrome\/(\d+\.\d+)/);
72
+ browserVersion = match ? match[1] : "";
73
+ } else if (ua.indexOf("safari") > -1 && ua.indexOf("chrome") === -1) {
74
+ browser = "Safari";
75
+ const match = ua.match(/version\/(\d+\.\d+)/);
76
+ browserVersion = match ? match[1] : "";
77
+ } else if (ua.indexOf("firefox") > -1) {
78
+ browser = "Firefox";
79
+ const match = ua.match(/firefox\/(\d+\.\d+)/);
80
+ browserVersion = match ? match[1] : "";
81
+ } else if (ua.indexOf("edge") > -1) {
82
+ browser = "Edge";
83
+ const match = ua.match(/edge\/(\d+\.\d+)/);
84
+ browserVersion = match ? match[1] : "";
85
+ }
86
+ if (ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1) {
87
+ os = "iOS";
88
+ const match = ua.match(/os (\d+[._]\d+)/);
89
+ osVersion = match ? match[1].replace("_", ".") : "";
90
+ } else if (ua.indexOf("windows") > -1) {
91
+ os = "Windows";
92
+ if (ua.indexOf("windows nt 10") > -1)
93
+ osVersion = "10";
94
+ else if (ua.indexOf("windows nt 6.3") > -1)
95
+ osVersion = "8.1";
96
+ else if (ua.indexOf("windows nt 6.2") > -1)
97
+ osVersion = "8";
98
+ else if (ua.indexOf("windows nt 6.1") > -1)
99
+ osVersion = "7";
100
+ } else if (ua.indexOf("mac os") > -1) {
101
+ os = "macOS";
102
+ const match = ua.match(/mac os x (\d+[._]\d+)/);
103
+ osVersion = match ? match[1].replace("_", ".") : "";
104
+ } else if (ua.indexOf("android") > -1) {
105
+ os = "Android";
106
+ const match = ua.match(/android (\d+(?:\.\d+)?)/);
107
+ if (match) {
108
+ const [, version] = match;
109
+ osVersion = version;
110
+ if (osVersion.indexOf(".") === -1) {
111
+ osVersion = `${osVersion}.0`;
112
+ }
113
+ } else {
114
+ osVersion = "";
115
+ }
116
+ } else if (ua.indexOf("linux") > -1) {
117
+ os = "Linux";
118
+ }
119
+ return { browser, browserVersion, os, osVersion };
120
+ }
121
+ function collectEnvironmentTags() {
122
+ const envInfo = getEnvironmentInfo();
123
+ const tags = {
124
+ platform: envInfo.platform
125
+ };
126
+ if (envInfo.platform === "browser" && envInfo.userAgent) {
127
+ const browserInfo = parseBrowserInfo(envInfo.userAgent);
128
+ tags.browser = browserInfo.browser;
129
+ tags.browserVersion = browserInfo.browserVersion;
130
+ tags.os = browserInfo.os;
131
+ tags.osVersion = browserInfo.osVersion;
132
+ tags.screenWidth = envInfo.screenWidth;
133
+ tags.screenHeight = envInfo.screenHeight;
134
+ tags.language = envInfo.language;
135
+ } else if (envInfo.platform === "wechat" && envInfo.systemInfo) {
136
+ tags.brand = envInfo.systemInfo.brand;
137
+ tags.model = envInfo.systemInfo.model;
138
+ tags.system = envInfo.systemInfo.system;
139
+ tags.wechatVersion = envInfo.systemInfo.version;
140
+ tags.SDKVersion = envInfo.systemInfo.SDKVersion;
141
+ tags.screenWidth = envInfo.screenWidth;
142
+ tags.screenHeight = envInfo.screenHeight;
143
+ tags.language = envInfo.language;
144
+ }
145
+ return tags;
146
+ }
147
+ export {
148
+ collectEnvironmentTags,
149
+ getCurrentUrl,
150
+ getEnvironmentInfo,
151
+ isBrowser,
152
+ isWeChatMiniProgram,
153
+ parseBrowserInfo
154
+ };
@@ -0,0 +1,7 @@
1
+ // src/utils/session.ts
2
+ function getSessionId() {
3
+ return `${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
4
+ }
5
+ export {
6
+ getSessionId
7
+ };
@@ -0,0 +1,76 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/utils/tools.ts
23
+ import { parseStack } from "../stack/stacktrace";
24
+ var now = () => Date.now();
25
+ function safeStringify(obj) {
26
+ const seen = /* @__PURE__ */ new WeakSet();
27
+ return JSON.stringify(obj, (_k, v) => {
28
+ if (v && typeof v === "object") {
29
+ if (seen.has(v))
30
+ return "[Circular]";
31
+ seen.add(v);
32
+ }
33
+ return v;
34
+ });
35
+ }
36
+ function normalizeMessage(message) {
37
+ return message.replace(/\d+/g, "{n}").replace(/https?:\/\/\S+/g, "{url}").replace(/[a-f0-9]{16,}/gi, "{id}").slice(0, 200);
38
+ }
39
+ function logDebug(debug, ...args) {
40
+ if (debug)
41
+ console.debug("[LoggerSDK]", ...args);
42
+ }
43
+ function hashToProb(s) {
44
+ let h = 2166136261 >>> 0;
45
+ for (let i = 0; i < s.length; i += 1) {
46
+ h ^= s.charCodeAt(i);
47
+ h = h + (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) >>> 0;
48
+ }
49
+ return h % 1e4 / 1e4;
50
+ }
51
+ function flattenStack(error) {
52
+ return __async(this, null, function* () {
53
+ if (!error) {
54
+ return {
55
+ location: "",
56
+ throwable: ""
57
+ };
58
+ }
59
+ const stackFrames = yield parseStack(error);
60
+ return stackFrames && stackFrames.length > 0 ? {
61
+ location: [stackFrames[0]].map((frame) => `${frame.file}:${frame.line}:${frame.column}`).join("\n "),
62
+ throwable: stackFrames.map((frame) => `${frame.file}:${frame.line}:${frame.column}`).join("\n ")
63
+ } : {
64
+ location: "",
65
+ throwable: ""
66
+ };
67
+ });
68
+ }
69
+ export {
70
+ flattenStack,
71
+ hashToProb,
72
+ logDebug,
73
+ normalizeMessage,
74
+ now,
75
+ safeStringify
76
+ };
@@ -0,0 +1,11 @@
1
+ // src/utils/uuid.ts
2
+ function uuid() {
3
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
4
+ const r = Math.floor(Math.random() * 16);
5
+ const v = c === "x" ? r : Math.floor(r % 4 + 8);
6
+ return v.toString(16);
7
+ });
8
+ }
9
+ export {
10
+ uuid
11
+ };
@@ -0,0 +1,2 @@
1
+ import { BaseErrorInfo } from '../types/logEvent';
2
+ export declare function registerJsErrorCapture(debug: boolean, callback: (error: BaseErrorInfo) => void): (() => void) | undefined;
@@ -0,0 +1,2 @@
1
+ import { BaseErrorInfo } from '../types/logEvent';
2
+ export declare function registerPromiseErrorCapture(debug: boolean, callback: (error: BaseErrorInfo) => void): (() => void) | undefined;
@@ -0,0 +1,2 @@
1
+ import { BaseErrorInfo } from '../types/logEvent';
2
+ export declare function registerResourceErrorCapture(debug: boolean, callback: (error: BaseErrorInfo) => void): (() => void) | undefined;
@@ -0,0 +1,3 @@
1
+ import { BaseErrorInfo } from '../types/logEvent';
2
+ export declare function registerWechatErrorCapture(debug: boolean, callback: (error: BaseErrorInfo) => void): (() => void) | undefined;
3
+ export declare function registerWechatUnhandledCapture(debug: boolean, callback: (error: BaseErrorInfo) => void): (() => void) | undefined;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * gzip 压缩字符串
3
+ * @param data - 需要压缩的字符串
4
+ * @returns 压缩后的 Base64 字符串
5
+ */
6
+ export declare function gzipCompress(data: string): Promise<string>;
7
+ /**
8
+ * 检查是否支持 gzip 压缩
9
+ */
10
+ export declare function isGzipSupported(): boolean;
@@ -0,0 +1,9 @@
1
+ import { Env } from '../types/env';
2
+ /** 获取 SDK 基础 API */
3
+ export declare const getSDKBaseApi: (env: Env) => "https://apm.pharmacyyf.com" | "https://apm-te.pharmacyyf.com" | "https://chief-dev.yifengx.com";
4
+ /** 获取 SDK 注册 API */
5
+ export declare const getRegisterApi: (env: Env) => string;
6
+ /** 获取 SDK 上报 API */
7
+ export declare const getReportApi: (env: Env) => string;
8
+ /** 获取 SDK 像素上报 API */
9
+ export declare const getPixelBatchApi: (env: Env) => string;
@@ -0,0 +1,8 @@
1
+ export declare function generateFingerprint(error: {
2
+ type: string;
3
+ message: string;
4
+ stack?: {
5
+ file: string;
6
+ line: number;
7
+ }[];
8
+ }): string;
@@ -0,0 +1,11 @@
1
+ export declare type HttpClientResponse = {
2
+ type: 'xhr' | 'fetch' | 'wechat';
3
+ response?: any;
4
+ error?: any;
5
+ };
6
+ export declare class HttpClient {
7
+ /**
8
+ * 发送 POST 请求,需要兼容浏览器和微信小程序
9
+ */
10
+ static post(url: string, data: any, token: string): Promise<HttpClientResponse>;
11
+ }
@@ -1,4 +1,6 @@
1
- import { SDKOptions, TrackOptions } from './types';
1
+ import { Env } from '../types/env';
2
+ import { SDKOptions } from '../types/sdkOptions';
3
+ import { TrackOptions } from '../types/trackOptions';
2
4
  export declare class LoggerSDK {
3
5
  private static instance;
4
6
  private opts?;
@@ -16,10 +18,19 @@ export declare class LoggerSDK {
16
18
  private queueManager?;
17
19
  /** 重试管理器 */
18
20
  private retryManager?;
21
+ private transporter?;
19
22
  /** 批量上报定时器 */
20
23
  private batchTimer?;
21
24
  /** 是否正在上报 */
22
25
  private isSending;
26
+ private collectSwitch;
27
+ private collectLogLevel;
28
+ private recentAutoEvents;
29
+ private offJs?;
30
+ private offPromise?;
31
+ private offResource?;
32
+ private offWxError?;
33
+ private offWxUnhandled?;
23
34
  private constructor();
24
35
  static getInstance(): LoggerSDK;
25
36
  /**
@@ -30,11 +41,21 @@ export declare class LoggerSDK {
30
41
  * 设置用户信息
31
42
  */
32
43
  identify(userId: string): void;
44
+ /** 设置店铺编码 */
33
45
  setStoreCode(storeCode: string): void;
46
+ /** 设置日志 stage(env) */
47
+ setStage(stage: Env): void;
48
+ private flattenEnvTags;
49
+ track({ message, error, traceId, logLevel }: TrackOptions): Promise<void>;
50
+ private trackInner;
51
+ /**
52
+ * 判断是否应该发送事件
53
+ */
54
+ private shouldSend;
34
55
  /**
35
56
  * 记录事件
36
57
  */
37
- track({ message, error, traceId, logLevel, }: TrackOptions): Promise<void>;
58
+ private doTrack;
38
59
  /**
39
60
  * 手动刷新队列,立即上报所有待发送日志
40
61
  */
@@ -59,5 +80,9 @@ export declare class LoggerSDK {
59
80
  * 监听页面卸载事件
60
81
  */
61
82
  private attachUnloadHandlers;
83
+ /**
84
+ * 初始化 SDK(注册/初始化)
85
+ */
86
+ private initSDK;
62
87
  }
63
88
  export default LoggerSDK;
@@ -1,4 +1,9 @@
1
- import { LogEvent } from './types';
1
+ import { LogEvent } from '../types/logEvent';
2
+ declare type LocalForageLike = {
3
+ getItem: (key: string) => Promise<any>;
4
+ setItem: (key: string, value: any) => Promise<any>;
5
+ removeItem: (key: string) => Promise<any>;
6
+ };
2
7
  /** 队列配置选项 */
3
8
  export interface QueueOptions {
4
9
  /** 队列最大长度 */
@@ -19,7 +24,9 @@ export declare class QueueManager {
19
24
  private queue;
20
25
  private opts;
21
26
  private storageKey;
27
+ private localforage;
22
28
  constructor(options: QueueOptions);
29
+ loadLocalForage(): Promise<LocalForageLike | null>;
23
30
  /**
24
31
  * 添加日志到队列
25
32
  */
@@ -53,3 +60,4 @@ export declare class QueueManager {
53
60
  */
54
61
  private removeFromStorage;
55
62
  }
63
+ export {};
@@ -50,8 +50,4 @@ export declare class RetryManager {
50
50
  * 清空所有重试任务
51
51
  */
52
52
  clear(): void;
53
- /**
54
- * 调试日志
55
- */
56
- private logDebug;
57
53
  }
@@ -0,0 +1 @@
1
+ export { LoggerSDK } from './core/loggerSDK';
@@ -0,0 +1,2 @@
1
+ import { StackFrame } from '../types/logEvent';
2
+ export declare function parseStack(error: Error): Promise<StackFrame[]>;
@@ -0,0 +1,11 @@
1
+ import { ReportData } from '../types/logEvent';
2
+ import { Transporter, TransportOptions } from './transport';
3
+ export declare class BeaconTransport implements Transporter {
4
+ /** 传输器名称 */
5
+ name: string;
6
+ /** 传输器名称 */
7
+ private opts?;
8
+ constructor(opts: TransportOptions);
9
+ isSupported(): boolean;
10
+ send(payload: ReportData): Promise<void>;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { Transporter, TransportOptions } from './transport';
2
+ import { ReportData } from '../types/logEvent';
3
+ export declare class PixelImageTransport implements Transporter {
4
+ /** 传输器名称 */
5
+ name: string;
6
+ /** 传输器选项 */
7
+ private opts?;
8
+ constructor(opts: TransportOptions);
9
+ isSupported(): boolean;
10
+ send(payload: ReportData): Promise<void>;
11
+ }
@@ -0,0 +1,14 @@
1
+ import { ReportData } from '../types/logEvent';
2
+ import { SDKOptions } from '../types/sdkOptions';
3
+ /** 传输选项接口 */
4
+ export interface TransportOptions extends SDKOptions {
5
+ }
6
+ /** 传输适配器接口 */
7
+ export interface Transporter {
8
+ /** 适配器名称 */
9
+ name: string;
10
+ /** 是否支持当前环境 */
11
+ isSupported(): boolean;
12
+ /** 发送数据 */
13
+ send(payload: ReportData): Promise<void>;
14
+ }
@@ -0,0 +1,10 @@
1
+ import { Transporter, TransportOptions } from './transport';
2
+ export declare class TransportAdapter {
3
+ private static instance;
4
+ private beaconTransport;
5
+ private pixelImageTransport;
6
+ private wechatTransport;
7
+ private constructor();
8
+ static getInstance(opts: TransportOptions): TransportAdapter;
9
+ getTransporter(): Transporter;
10
+ }
@@ -0,0 +1,11 @@
1
+ import { ReportData } from '../types/logEvent';
2
+ import { Transporter, TransportOptions } from './transport';
3
+ export declare class WechatTransport implements Transporter {
4
+ /** 传输器名称 */
5
+ name: string;
6
+ /** 传输器选项 */
7
+ private opts?;
8
+ constructor(opts: TransportOptions);
9
+ isSupported(): boolean;
10
+ send(payload: ReportData): Promise<void>;
11
+ }
@@ -0,0 +1,12 @@
1
+ export interface SDKInitData {
2
+ collectSwitch: number;
3
+ collectLogLevel: string[];
4
+ samplingRate: number;
5
+ }
6
+ export interface APIResponse<T> {
7
+ code: number;
8
+ message?: string;
9
+ data: T;
10
+ timestamp: string;
11
+ traceId: string;
12
+ }
@@ -0,0 +1,14 @@
1
+ /** 环境类型 */
2
+ export declare type Env = 'develop' | 'testing' | 'product';
3
+ export declare type Stage = 'develop' | 'testing' | 'sit' | 'yace' | 'product';
4
+ /** 平台类型 */
5
+ export declare type PlatformType = 'browser' | 'wechat' | 'unknown';
6
+ /** 环境信息 */
7
+ export interface EnvironmentInfo {
8
+ platform: PlatformType;
9
+ userAgent?: string;
10
+ screenWidth?: number;
11
+ screenHeight?: number;
12
+ language?: string;
13
+ systemInfo?: any;
14
+ }