@pluve/mp-logger-sdk 0.0.1

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 (84) hide show
  1. package/README.md +133 -0
  2. package/dist/cjs/capture/wechatError.js +85 -0
  3. package/dist/cjs/compress/compression.js +94 -0
  4. package/dist/cjs/config/index.js +48 -0
  5. package/dist/cjs/core/fingerprint.js +32 -0
  6. package/dist/cjs/core/httpClient.js +55 -0
  7. package/dist/cjs/core/loggerSDK.js +580 -0
  8. package/dist/cjs/core/queueManager.js +121 -0
  9. package/dist/cjs/core/retryManager.js +123 -0
  10. package/dist/cjs/index.js +25 -0
  11. package/dist/cjs/stack/stacktrace.js +69 -0
  12. package/dist/cjs/transport/transport.js +17 -0
  13. package/dist/cjs/transport/transportAdapter.js +39 -0
  14. package/dist/cjs/transport/wechatTransport.js +98 -0
  15. package/dist/cjs/types/api.js +17 -0
  16. package/dist/cjs/types/env.js +17 -0
  17. package/dist/cjs/types/external.d.ts +15 -0
  18. package/dist/cjs/types/logEvent.js +17 -0
  19. package/dist/cjs/types/logEventLevel.js +17 -0
  20. package/dist/cjs/types/sdkOptions.js +17 -0
  21. package/dist/cjs/types/securityType.js +34 -0
  22. package/dist/cjs/types/trackOptions.js +17 -0
  23. package/dist/cjs/utils/environment.js +85 -0
  24. package/dist/cjs/utils/innerMD5.js +143 -0
  25. package/dist/cjs/utils/session.js +27 -0
  26. package/dist/cjs/utils/tools.js +73 -0
  27. package/dist/cjs/utils/uuid.js +31 -0
  28. package/dist/esm/capture/wechatError.js +65 -0
  29. package/dist/esm/compress/compression.js +74 -0
  30. package/dist/esm/config/index.js +28 -0
  31. package/dist/esm/core/fingerprint.js +12 -0
  32. package/dist/esm/core/httpClient.js +35 -0
  33. package/dist/esm/core/loggerSDK.js +560 -0
  34. package/dist/esm/core/queueManager.js +101 -0
  35. package/dist/esm/core/retryManager.js +103 -0
  36. package/dist/esm/index.js +5 -0
  37. package/dist/esm/stack/stacktrace.js +49 -0
  38. package/dist/esm/transport/transport.js +0 -0
  39. package/dist/esm/transport/transportAdapter.js +19 -0
  40. package/dist/esm/transport/wechatTransport.js +78 -0
  41. package/dist/esm/types/api.js +0 -0
  42. package/dist/esm/types/env.js +0 -0
  43. package/dist/esm/types/external.d.ts +15 -0
  44. package/dist/esm/types/logEvent.js +0 -0
  45. package/dist/esm/types/logEventLevel.js +0 -0
  46. package/dist/esm/types/sdkOptions.js +0 -0
  47. package/dist/esm/types/securityType.js +14 -0
  48. package/dist/esm/types/trackOptions.js +0 -0
  49. package/dist/esm/utils/environment.js +65 -0
  50. package/dist/esm/utils/innerMD5.js +123 -0
  51. package/dist/esm/utils/session.js +7 -0
  52. package/dist/esm/utils/tools.js +53 -0
  53. package/dist/esm/utils/uuid.js +11 -0
  54. package/dist/types/capture/jsError.d.ts +2 -0
  55. package/dist/types/capture/promiseError.d.ts +2 -0
  56. package/dist/types/capture/resourceError.d.ts +2 -0
  57. package/dist/types/capture/wechatError.d.ts +3 -0
  58. package/dist/types/compress/compression.d.ts +9 -0
  59. package/dist/types/config/index.d.ts +9 -0
  60. package/dist/types/core/fingerprint.d.ts +8 -0
  61. package/dist/types/core/httpClient.d.ts +11 -0
  62. package/dist/types/core/loggerSDK.d.ts +87 -0
  63. package/dist/types/core/queueManager.d.ts +55 -0
  64. package/dist/types/core/retryManager.d.ts +53 -0
  65. package/dist/types/index.d.ts +2 -0
  66. package/dist/types/stack/stacktrace.d.ts +2 -0
  67. package/dist/types/transport/beaconTransport.d.ts +11 -0
  68. package/dist/types/transport/pixelImageTransport.d.ts +11 -0
  69. package/dist/types/transport/transport.d.ts +14 -0
  70. package/dist/types/transport/transportAdapter.d.ts +8 -0
  71. package/dist/types/transport/wechatTransport.d.ts +11 -0
  72. package/dist/types/types/api.d.ts +12 -0
  73. package/dist/types/types/env.d.ts +14 -0
  74. package/dist/types/types/logEvent.d.ts +57 -0
  75. package/dist/types/types/logEventLevel.d.ts +2 -0
  76. package/dist/types/types/sdkOptions.d.ts +61 -0
  77. package/dist/types/types/securityType.d.ts +6 -0
  78. package/dist/types/types/trackOptions.d.ts +7 -0
  79. package/dist/types/utils/environment.d.ts +10 -0
  80. package/dist/types/utils/innerMD5.d.ts +6 -0
  81. package/dist/types/utils/session.d.ts +1 -0
  82. package/dist/types/utils/tools.d.ts +12 -0
  83. package/dist/types/utils/uuid.d.ts +7 -0
  84. package/package.json +65 -0
@@ -0,0 +1,103 @@
1
+ // src/core/retryManager.ts
2
+ import { logDebug } from "../utils/tools";
3
+ var RetryManager = class {
4
+ constructor(options) {
5
+ this.retryingTasks = /* @__PURE__ */ new Map();
6
+ this.opts = options;
7
+ }
8
+ /**
9
+ * 执行带重试的任务
10
+ * @param taskId - 任务唯一标识
11
+ * @param fn - 要执行的异步函数
12
+ * @returns Promise
13
+ */
14
+ async executeWithRetry(taskId, fn) {
15
+ if (this.retryingTasks.has(taskId)) {
16
+ logDebug(!!this.opts.debug, `Task ${taskId} already retrying, skipped`);
17
+ throw new Error(`Task ${taskId} already retrying`);
18
+ }
19
+ const task = {
20
+ id: taskId,
21
+ fn,
22
+ retries: 0,
23
+ maxRetries: this.opts.maxRetries,
24
+ baseDelay: this.opts.baseDelay,
25
+ useBackoff: this.opts.useBackoff
26
+ };
27
+ this.retryingTasks.set(taskId, task);
28
+ try {
29
+ const result = await this.executeTask(task);
30
+ this.retryingTasks.delete(taskId);
31
+ return result;
32
+ } catch (error) {
33
+ this.retryingTasks.delete(taskId);
34
+ throw error;
35
+ }
36
+ }
37
+ /**
38
+ * 执行任务(带重试逻辑)
39
+ */
40
+ async executeTask(task) {
41
+ while (task.retries <= task.maxRetries) {
42
+ try {
43
+ const result = await task.fn();
44
+ if (task.retries > 0) {
45
+ logDebug(!!this.opts.debug, `Task ${task.id} succeeded after ${task.retries} retries`);
46
+ }
47
+ return result;
48
+ } catch (error) {
49
+ task.retries += 1;
50
+ if (task.retries > task.maxRetries) {
51
+ logDebug(!!this.opts.debug, `Task ${task.id} failed after ${task.maxRetries} retries`);
52
+ throw error;
53
+ }
54
+ const delay = RetryManager.calculateDelay(task.retries, task.baseDelay, task.useBackoff);
55
+ logDebug(
56
+ !!this.opts.debug,
57
+ `Task ${task.id} failed (attempt ${task.retries}/${task.maxRetries}), retrying in ${delay}ms`
58
+ );
59
+ await RetryManager.sleep(delay);
60
+ }
61
+ }
62
+ throw new Error(`Task ${task.id} exceeded max retries`);
63
+ }
64
+ /**
65
+ * 计算延迟时间
66
+ * @param attempt - 当前重试次数
67
+ * @param baseDelay - 基础延迟时间
68
+ * @param useBackoff - 是否使用指数退避
69
+ * @returns 延迟时间(毫秒)
70
+ */
71
+ static calculateDelay(attempt, baseDelay, useBackoff) {
72
+ if (!useBackoff) {
73
+ return baseDelay;
74
+ }
75
+ const factor = 2 ** (attempt - 1);
76
+ const delay = baseDelay * factor;
77
+ const jitterRatio = 0.3;
78
+ const maxDelay = 3e4;
79
+ const jitter = Math.random() * jitterRatio * delay;
80
+ return Math.min(delay + jitter, maxDelay);
81
+ }
82
+ /**
83
+ * 睡眠函数
84
+ */
85
+ static sleep(ms) {
86
+ return new Promise((resolve) => setTimeout(resolve, ms));
87
+ }
88
+ /**
89
+ * 获取正在重试的任务数量
90
+ */
91
+ getRetryingCount() {
92
+ return this.retryingTasks.size;
93
+ }
94
+ /**
95
+ * 清空所有重试任务
96
+ */
97
+ clear() {
98
+ this.retryingTasks.clear();
99
+ }
100
+ };
101
+ export {
102
+ RetryManager
103
+ };
@@ -0,0 +1,5 @@
1
+ // src/index.ts
2
+ import { LoggerSDK } from "./core/loggerSDK";
3
+ export {
4
+ LoggerSDK
5
+ };
@@ -0,0 +1,49 @@
1
+ // src/stack/stacktrace.ts
2
+ function parseErrorStack(stack) {
3
+ const lines = stack.split("\n");
4
+ const frames = [];
5
+ lines.forEach((line) => {
6
+ const trimmed = line.trim();
7
+ if (!trimmed)
8
+ return;
9
+ if (trimmed.startsWith("Error:"))
10
+ return;
11
+ const v8Match = trimmed.match(/^at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+))\)?$/);
12
+ if (v8Match) {
13
+ frames.push({
14
+ function: v8Match[1] || void 0,
15
+ file: v8Match[2],
16
+ line: parseInt(v8Match[3], 10),
17
+ column: parseInt(v8Match[4], 10)
18
+ });
19
+ return;
20
+ }
21
+ const jscMatch = trimmed.match(/^(?:(.+?)@)?(.+?):(\d+):(\d+)$/);
22
+ if (jscMatch) {
23
+ frames.push({
24
+ function: jscMatch[1] || void 0,
25
+ file: jscMatch[2],
26
+ line: parseInt(jscMatch[3], 10),
27
+ column: parseInt(jscMatch[4], 10)
28
+ });
29
+ }
30
+ });
31
+ return frames;
32
+ }
33
+ async function parseStack(error) {
34
+ return new Promise((resolve) => {
35
+ try {
36
+ if (!error || !error.stack) {
37
+ resolve([]);
38
+ return;
39
+ }
40
+ const frames = parseErrorStack(error.stack);
41
+ resolve(frames.slice(0, 5));
42
+ } catch (e) {
43
+ resolve([]);
44
+ }
45
+ });
46
+ }
47
+ export {
48
+ parseStack
49
+ };
File without changes
@@ -0,0 +1,19 @@
1
+ // src/transport/transportAdapter.ts
2
+ import { WechatTransport } from "./wechatTransport";
3
+ var TransportAdapter = class {
4
+ constructor(opts) {
5
+ this.opts = opts;
6
+ }
7
+ static getInstance(opts) {
8
+ if (!TransportAdapter.instance) {
9
+ TransportAdapter.instance = new TransportAdapter(opts);
10
+ }
11
+ return TransportAdapter.instance;
12
+ }
13
+ async getTransporter() {
14
+ return new WechatTransport(this.opts);
15
+ }
16
+ };
17
+ export {
18
+ TransportAdapter
19
+ };
@@ -0,0 +1,78 @@
1
+ // src/transport/wechatTransport.ts
2
+ import { gzipCompress } from "../compress/compression";
3
+ import { getReportApi } from "../config";
4
+ import { logDebug, now, safeStringify } from "../utils/tools";
5
+ var WechatTransport = class {
6
+ constructor(opts) {
7
+ /** 传输器名称 */
8
+ this.name = "wechat";
9
+ this.opts = opts;
10
+ }
11
+ // eslint-disable-next-line class-methods-use-this
12
+ isSupported() {
13
+ return true;
14
+ }
15
+ async send(token, payload) {
16
+ var _a, _b, _c, _d, _e;
17
+ let body = typeof payload === "string" ? payload : safeStringify(payload);
18
+ const endpoint = `${getReportApi(((_a = this.opts) == null ? void 0 : _a.env) || "develop")}?token=${token}`;
19
+ const timeout = 1e4;
20
+ let contentType = "application/json";
21
+ if (((_b = this.opts) == null ? void 0 : _b.enableGzip) && payload.items.length >= ((_c = this.opts) == null ? void 0 : _c.gzipBatchMinSize)) {
22
+ const t = now();
23
+ logDebug(!!((_d = this.opts) == null ? void 0 : _d.debug), "WeChat request enable gzip compress: ", t);
24
+ const compressedItems = await gzipCompress(safeStringify(payload.items));
25
+ body = safeStringify({
26
+ ...payload,
27
+ items: compressedItems
28
+ });
29
+ logDebug(!!((_e = this.opts) == null ? void 0 : _e.debug), "WeChat request gzip compress cost: ", now() - t);
30
+ contentType = "application/json; charset=utf-8";
31
+ }
32
+ return new Promise((resolve, reject) => {
33
+ var _a2;
34
+ let timeoutId = null;
35
+ let settled = false;
36
+ timeoutId = setTimeout(() => {
37
+ if (!settled) {
38
+ settled = true;
39
+ reject(new Error(`WeChat request timeout after ${timeout}ms`));
40
+ }
41
+ }, timeout);
42
+ wx.request({
43
+ url: endpoint,
44
+ method: "POST",
45
+ data: body,
46
+ header: {
47
+ "Content-Type": contentType,
48
+ token: ((_a2 = this.opts) == null ? void 0 : _a2.token) || ""
49
+ },
50
+ success(res) {
51
+ if (timeoutId)
52
+ clearTimeout(timeoutId);
53
+ if (!settled) {
54
+ settled = true;
55
+ if (res.statusCode >= 200 && res.statusCode < 300) {
56
+ resolve();
57
+ } else {
58
+ reject(new Error(`HTTP ${res.statusCode}`));
59
+ }
60
+ }
61
+ },
62
+ fail(err) {
63
+ var _a3;
64
+ if (timeoutId)
65
+ clearTimeout(timeoutId);
66
+ if (!settled) {
67
+ settled = true;
68
+ logDebug(!!((_a3 = this.opts) == null ? void 0 : _a3.debug), "WeChat request failed", err);
69
+ reject(new Error(`WeChat request failed: ${err.errMsg || "unknown error"}`));
70
+ }
71
+ }
72
+ });
73
+ });
74
+ }
75
+ };
76
+ export {
77
+ WechatTransport
78
+ };
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ /*
2
+ * @Author: 黄震 huangzhen@yfpharmacy.com
3
+ * @Date: 2026-02-03 10:26:04
4
+ * @LastEditors: 黄震 huangzhen@yfpharmacy.com
5
+ * @LastEditTime: 2026-02-13 15:15:07
6
+ * @FilePath: /pluve-lib/packages/mp-logger-sdk/src/types/external.d.ts
7
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8
+ */
9
+ declare module 'fflate' {
10
+ export function gzipSync(input: Uint8Array | string): Uint8Array;
11
+ }
12
+
13
+ declare const wx: any;
14
+ declare function getCurrentPages(): any[];
15
+
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ // src/types/securityType.ts
2
+ var SecurityType = {
3
+ ACCOUNT_CENTER: "2B",
4
+ // 2B(账号中心)
5
+ EHP: "EHP",
6
+ // EHP(医疗)
7
+ CUSTOMER: "CUSTOMER",
8
+ // 2C(会员,这期不涉及先预留)
9
+ BASE: "BASE"
10
+ // BASE(兜底MD5)
11
+ };
12
+ export {
13
+ SecurityType
14
+ };
File without changes
@@ -0,0 +1,65 @@
1
+ // src/utils/environment.ts
2
+ function getCurrentUrl() {
3
+ try {
4
+ if (typeof getCurrentPages !== "function") {
5
+ return "";
6
+ }
7
+ const pages = getCurrentPages();
8
+ if (pages && pages.length > 0) {
9
+ const currentPage = pages[pages.length - 1];
10
+ const route = currentPage.route || "";
11
+ const options = currentPage.options || {};
12
+ let query = "";
13
+ if (options && typeof options === "object") {
14
+ query = Object.keys(options).map((key) => `${key}=${options[key]}`).join("&");
15
+ }
16
+ return query ? `${route}?${query}` : route;
17
+ }
18
+ } catch (e) {
19
+ return "";
20
+ }
21
+ return "";
22
+ }
23
+ function getEnvironmentInfo() {
24
+ const envInfo = {
25
+ platform: "wechat"
26
+ };
27
+ try {
28
+ const systemInfo = wx.getSystemInfoSync();
29
+ envInfo.systemInfo = {
30
+ brand: systemInfo.brand,
31
+ model: systemInfo.model,
32
+ system: systemInfo.system,
33
+ platform: systemInfo.platform,
34
+ version: systemInfo.version,
35
+ SDKVersion: systemInfo.SDKVersion
36
+ };
37
+ envInfo.screenWidth = systemInfo.screenWidth;
38
+ envInfo.screenHeight = systemInfo.screenHeight;
39
+ envInfo.language = systemInfo.language;
40
+ } catch (e) {
41
+ }
42
+ return envInfo;
43
+ }
44
+ function collectEnvironmentTags() {
45
+ const envInfo = getEnvironmentInfo();
46
+ const tags = {
47
+ platform: envInfo.platform
48
+ };
49
+ if (envInfo.platform === "wechat" && envInfo.systemInfo) {
50
+ tags.brand = envInfo.systemInfo.brand;
51
+ tags.model = envInfo.systemInfo.model;
52
+ tags.system = envInfo.systemInfo.system;
53
+ tags.wechatVersion = envInfo.systemInfo.version;
54
+ tags.SDKVersion = envInfo.systemInfo.SDKVersion;
55
+ tags.screenWidth = envInfo.screenWidth;
56
+ tags.screenHeight = envInfo.screenHeight;
57
+ tags.language = envInfo.language;
58
+ }
59
+ return tags;
60
+ }
61
+ export {
62
+ collectEnvironmentTags,
63
+ getCurrentUrl,
64
+ getEnvironmentInfo
65
+ };
@@ -0,0 +1,123 @@
1
+ // src/utils/innerMD5.ts
2
+ var md5 = (input) => {
3
+ const k = [
4
+ 3614090360,
5
+ 3905402710,
6
+ 606105819,
7
+ 3250441966,
8
+ 4118548399,
9
+ 1200080426,
10
+ 2821735955,
11
+ 4249261313,
12
+ 1770035416,
13
+ 2336552879,
14
+ 4294925233,
15
+ 2304563134,
16
+ 1804603682,
17
+ 4254626195,
18
+ 2792965006,
19
+ 1236535329,
20
+ 4129170786,
21
+ 3225465664,
22
+ 643717713,
23
+ 3921069994,
24
+ 3593408605,
25
+ 38016083,
26
+ 3634488961,
27
+ 3889429448,
28
+ 568446438,
29
+ 3275163606,
30
+ 4107603335,
31
+ 1163531501,
32
+ 2850285829,
33
+ 4243563512,
34
+ 1735328473,
35
+ 2368359562,
36
+ 4294588738,
37
+ 2272392833,
38
+ 1839030562,
39
+ 4259657740,
40
+ 2763975236,
41
+ 1272893353,
42
+ 4139469664,
43
+ 3200236656,
44
+ 681279174,
45
+ 3936430074,
46
+ 3572445317,
47
+ 76029189,
48
+ 3654602809,
49
+ 3873151461,
50
+ 530742520,
51
+ 3299628645,
52
+ 4096336452,
53
+ 1126891415,
54
+ 2878612391,
55
+ 4237533241,
56
+ 1700485571,
57
+ 2399980690,
58
+ 4293915773,
59
+ 2240044497,
60
+ 1873313359,
61
+ 4264355552,
62
+ 2734768916,
63
+ 1309151649,
64
+ 4149444226,
65
+ 3174756917,
66
+ 718787259,
67
+ 3951481745
68
+ ];
69
+ const str = unescape(encodeURIComponent(input));
70
+ const x = [];
71
+ for (let i = 0; i < str.length * 8; i += 8) {
72
+ x[i >> 5] |= (str.charCodeAt(i / 8) & 255) << i % 32;
73
+ }
74
+ x[str.length * 8 >> 5 << 5] |= 128 << str.length * 8 % 32;
75
+ x[(str.length * 8 + 64 >>> 9 << 4) + 14] = str.length * 8;
76
+ let a = 1732584193;
77
+ let b = -271733879;
78
+ let c = -1732584194;
79
+ let d = 271733878;
80
+ for (let i = 0; i < x.length; i += 16) {
81
+ const olda = a;
82
+ const oldb = b;
83
+ const oldc = c;
84
+ const oldd = d;
85
+ for (let j = 0; j < 64; j += 1) {
86
+ let f;
87
+ let g;
88
+ if (j < 16) {
89
+ f = b & c | ~b & d;
90
+ g = j;
91
+ } else if (j < 32) {
92
+ f = d & b | ~d & c;
93
+ g = (5 * j + 1) % 16;
94
+ } else if (j < 48) {
95
+ f = b ^ c ^ d;
96
+ g = (3 * j + 5) % 16;
97
+ } else {
98
+ f = c ^ (b | ~d);
99
+ g = 7 * j % 16;
100
+ }
101
+ const temp = d;
102
+ d = c;
103
+ c = b;
104
+ b = b + (a + f + k[j] + (x[i + g] || 0) << 7 + (j < 16 ? [7, 12, 17, 22][j % 4] : j < 32 ? [5, 9, 14, 20][j % 4] : j < 48 ? [4, 11, 16, 23][j % 4] : [6, 10, 15, 21][j % 4])) | 0;
105
+ a = temp;
106
+ }
107
+ a = a + olda | 0;
108
+ b = b + oldb | 0;
109
+ c = c + oldc | 0;
110
+ d = d + oldd | 0;
111
+ }
112
+ const hex = (val) => {
113
+ let output = "";
114
+ for (let i = 0; i < 4; i += 1) {
115
+ output += (val >> i * 8 & 255).toString(16).padStart(2, "0");
116
+ }
117
+ return output;
118
+ };
119
+ return hex(a) + hex(b) + hex(c) + hex(d);
120
+ };
121
+ export {
122
+ md5
123
+ };
@@ -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,53 @@
1
+ // src/utils/tools.ts
2
+ import { parseStack } from "../stack/stacktrace";
3
+ var now = () => Date.now();
4
+ function safeStringify(obj) {
5
+ const seen = /* @__PURE__ */ new WeakSet();
6
+ return JSON.stringify(obj, (_k, v) => {
7
+ if (v && typeof v === "object") {
8
+ if (seen.has(v))
9
+ return "[Circular]";
10
+ seen.add(v);
11
+ }
12
+ return v;
13
+ });
14
+ }
15
+ function normalizeMessage(message) {
16
+ return message.replace(/\d+/g, "{n}").replace(/https?:\/\/\S+/g, "{url}").replace(/[a-f0-9]{16,}/gi, "{id}").slice(0, 200);
17
+ }
18
+ function logDebug(debug, ...args) {
19
+ if (debug)
20
+ console.debug("[LoggerSDK]", ...args);
21
+ }
22
+ function hashToProb(s) {
23
+ let h = 2166136261 >>> 0;
24
+ for (let i = 0; i < s.length; i += 1) {
25
+ h ^= s.charCodeAt(i);
26
+ h = h + (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) >>> 0;
27
+ }
28
+ return h % 1e4 / 1e4;
29
+ }
30
+ async function flattenStack(error) {
31
+ if (!error) {
32
+ return {
33
+ location: "",
34
+ throwable: ""
35
+ };
36
+ }
37
+ const stackFrames = await parseStack(error);
38
+ return stackFrames && stackFrames.length > 0 ? {
39
+ location: [stackFrames[0]].map((frame) => `${frame.file}:${frame.line}:${frame.column}`).join("\n "),
40
+ throwable: stackFrames.map((frame) => `${frame.file}:${frame.line}:${frame.column}`).join("\n ")
41
+ } : {
42
+ location: "",
43
+ throwable: ""
44
+ };
45
+ }
46
+ export {
47
+ flattenStack,
48
+ hashToProb,
49
+ logDebug,
50
+ normalizeMessage,
51
+ now,
52
+ safeStringify
53
+ };
@@ -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,9 @@
1
+ /**
2
+ * gzip 压缩字符串
3
+ * @param data - 需要压缩的字符串
4
+ * @returns 压缩后的 Base64 字符串
5
+ */
6
+ export declare function gzipCompress(data: string): Promise<string>;
7
+ export declare function isGzipSupported(): boolean;
8
+ export declare function convert2Base64FromArray(data: Uint8Array): any;
9
+ export declare function convert2Base64(data: string): Promise<string>;
@@ -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 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
+ }