polyv-rum-sdk 0.1.2

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.js ADDED
@@ -0,0 +1,1657 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ MitoSLSAdapter: () => MitoSLSAdapter,
34
+ RUMPluginVue2: () => RUMPluginVue2,
35
+ RUM_ENV: () => RUM_ENV,
36
+ SLSWebTrackingAdapter: () => SLSWebTrackingAdapter,
37
+ createRUMPluginVue3: () => createRUMPluginVue3,
38
+ destroyRUMVue2: () => destroyRUM,
39
+ disableRUMVue2: () => disableRUM,
40
+ enableRUMVue2: () => enableRUM,
41
+ getBreadcrumbsVue2: () => getBreadcrumbs,
42
+ getMitoAdapter: () => getMitoAdapter,
43
+ getRUMConfigVue2: () => getRUMConfig,
44
+ getRUMCoreInstance: () => getRUMCoreInstance,
45
+ getRUMEnv: () => getRUMEnv,
46
+ getRUMManagerVue2: () => getRUMManager,
47
+ getUserInfo: () => getUserInfo,
48
+ initRUMCore: () => initRUMCore,
49
+ initRUMSystemVue2: () => initRUMSystem,
50
+ mitoConfig: () => mitoConfig,
51
+ shouldReport: () => shouldReport,
52
+ slsConfig: () => slsConfig,
53
+ trackActionVue2: () => trackAction,
54
+ trackEventVue2: () => trackEvent,
55
+ trackMetricVue2: () => trackMetric,
56
+ trackPerformanceVue2: () => trackPerformance,
57
+ transformDataForSLS: () => transformDataForSLS,
58
+ useRUM: () => useRUM,
59
+ vue2: () => plugin_vue2_exports,
60
+ vue3: () => plugin_vue3_exports
61
+ });
62
+ module.exports = __toCommonJS(src_exports);
63
+
64
+ // src/core/env.ts
65
+ var getRUMEnv = () => {
66
+ if (typeof window !== "undefined" && window.VUE_APP_ENV) {
67
+ return window.VUE_APP_ENV;
68
+ }
69
+ if (typeof process !== "undefined" && process.env) {
70
+ return process.env;
71
+ }
72
+ return {};
73
+ };
74
+ var RUM_ENV = getRUMEnv();
75
+
76
+ // src/core/config.ts
77
+ var getEnv = (key, defaultValue = "") => {
78
+ const env = getRUMEnv();
79
+ if (env && Object.prototype.hasOwnProperty.call(env, key)) {
80
+ return env[key] || defaultValue;
81
+ }
82
+ return defaultValue;
83
+ };
84
+ var isProduction = getEnv("NODE_ENV") === "production";
85
+ var isDebugEnabled = getEnv("VUE_APP_RUM_DEBUG", "false") === "true";
86
+ var getSessionId = () => {
87
+ if (typeof sessionStorage === "undefined") {
88
+ return `session_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
89
+ }
90
+ let sessionId = sessionStorage.getItem("rum_session_id");
91
+ if (!sessionId) {
92
+ sessionId = `session_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
93
+ sessionStorage.setItem("rum_session_id", sessionId);
94
+ }
95
+ return sessionId;
96
+ };
97
+ var getMetricType = (data) => {
98
+ switch (data.type) {
99
+ case "performance":
100
+ return "duration";
101
+ case "xhr":
102
+ return "xhr";
103
+ case "fetch":
104
+ return "fetch";
105
+ case "click":
106
+ return "click";
107
+ case "route":
108
+ return "route";
109
+ case "error":
110
+ return "error";
111
+ default:
112
+ return "unknown";
113
+ }
114
+ };
115
+ var extractValue = (data) => {
116
+ switch (data.type) {
117
+ case "performance":
118
+ return data.duration || 0;
119
+ case "xhr":
120
+ case "fetch":
121
+ return data.duration || data.status || 0;
122
+ case "click":
123
+ case "error":
124
+ return 1;
125
+ default:
126
+ return 1;
127
+ }
128
+ };
129
+ var slsConfig = {
130
+ host: getEnv("VUE_APP_SLS_HOST", "cn-shenzhen.log.aliyuncs.com"),
131
+ project: getEnv("VUE_APP_SLS_PROJECT", "live-admin-rum"),
132
+ logstore: getEnv("VUE_APP_SLS_LOGSTORE", "rum-traces-dev"),
133
+ time: 10,
134
+ count: 10,
135
+ topic: "rum-monitor",
136
+ source: "web",
137
+ enabled: getEnv("VUE_APP_SLS_ENABLED", "true") !== "false",
138
+ debug: isDebugEnabled,
139
+ appName: "live-admin-v3",
140
+ appVersion: getEnv("PACKAGE_VERSION", "1.0.0"),
141
+ retryCount: 3,
142
+ retryInterval: 2e3
143
+ };
144
+ if (typeof console !== "undefined" && isDebugEnabled) {
145
+ console.log("\u{1F527} SLS Config:", {
146
+ enabled: slsConfig.enabled,
147
+ debug: slsConfig.debug,
148
+ host: slsConfig.host,
149
+ project: slsConfig.project,
150
+ logstore: slsConfig.logstore,
151
+ envCheck: {
152
+ VUE_APP_SLS_ENABLED: getEnv("VUE_APP_SLS_ENABLED"),
153
+ VUE_APP_RUM_DEBUG: getEnv("VUE_APP_RUM_DEBUG")
154
+ }
155
+ });
156
+ }
157
+ var mitoConfig = {
158
+ dsn: getEnv("VUE_APP_RUM_DSN", "") || null,
159
+ appName: "live-admin-v3",
160
+ appVersion: getEnv("PACKAGE_VERSION", "1.0.0"),
161
+ environment: getEnv("NODE_ENV", "development"),
162
+ debug: isDebugEnabled,
163
+ maxBreadcrumbs: 20,
164
+ sampleRate: {
165
+ error: 1,
166
+ click: isProduction ? 0.1 : 1,
167
+ route: 1,
168
+ custom: 1,
169
+ xhr: isProduction ? 0.5 : 1
170
+ },
171
+ vue: {
172
+ Vue: void 0,
173
+ lifecycle: true,
174
+ performance: true
175
+ },
176
+ network: {
177
+ xhr: true,
178
+ fetch: true,
179
+ ignoreUrls: [/sls\.aliyuncs\.com/, /file:\/\//],
180
+ responseSizeLimit: 500
181
+ },
182
+ error: {
183
+ javascript: true,
184
+ promise: true,
185
+ resource: true,
186
+ ignoreErrors: [/third-party/, /Network timeout/]
187
+ },
188
+ user: {
189
+ click: true,
190
+ route: true,
191
+ performance: true,
192
+ sensitiveSelectors: [
193
+ 'input[type="password"]',
194
+ 'input[name*="password"]',
195
+ 'input[name*="token"]',
196
+ 'textarea[name*="secret"]'
197
+ ]
198
+ },
199
+ breadcrumb: {
200
+ console: isDebugEnabled,
201
+ dom: true,
202
+ navigation: true,
203
+ customTypes: ["vue", "vuex", "axios"]
204
+ },
205
+ transport: {
206
+ type: "xhr",
207
+ batch: {
208
+ size: 10,
209
+ interval: 5e3,
210
+ immediateOnError: true
211
+ },
212
+ retry: {
213
+ times: 3,
214
+ interval: 2e3
215
+ }
216
+ }
217
+ };
218
+ var getUserInfo = (store) => {
219
+ try {
220
+ if (!store || !store.state) {
221
+ return {};
222
+ }
223
+ const userModule = store.state.user || {};
224
+ const userInfo = userModule.userInfo || userModule || {};
225
+ const getters = store.getters || {};
226
+ return {
227
+ userId: userInfo.userId || userInfo.id || getters["user/userId"],
228
+ userName: userInfo.userName || userInfo.contact || userInfo.name,
229
+ accountId: userInfo.accountId,
230
+ email: userInfo.email,
231
+ roles: userInfo.roles || [],
232
+ permissions: getters["user/permissions"] || userInfo.permissions || []
233
+ };
234
+ } catch (error) {
235
+ console.warn("Failed to get user info from store:", error);
236
+ return {};
237
+ }
238
+ };
239
+ var transformDataForSLS = (data, context = {}) => {
240
+ var _a;
241
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
242
+ const userInfo = getUserInfo(context.store);
243
+ const dimensions = {
244
+ pageTitle: typeof document !== "undefined" ? document.title : "",
245
+ path: typeof window !== "undefined" ? window.location.pathname : "",
246
+ search: typeof window !== "undefined" ? window.location.search : "",
247
+ hash: typeof window !== "undefined" ? window.location.hash : "",
248
+ ...userInfo && {
249
+ userId: userInfo.userId,
250
+ userName: userInfo.userName,
251
+ accountId: userInfo.accountId,
252
+ userEmail: userInfo.email,
253
+ userRoles: (userInfo.roles || []).join(","),
254
+ userPermissions: (userInfo.permissions || []).join(",")
255
+ },
256
+ ...data.customData
257
+ };
258
+ if (data.type === "click") {
259
+ const target = data.target || {};
260
+ const page = data.page || {};
261
+ dimensions.clickBizId = data.bizId;
262
+ dimensions.clickTargetTag = target.tagName;
263
+ dimensions.clickTargetId = target.id;
264
+ dimensions.clickTargetClass = target.className;
265
+ dimensions.clickTargetSelector = target.selector;
266
+ dimensions.clickTargetText = target.textContent;
267
+ dimensions.clickPageUrl = page.url;
268
+ dimensions.clickPagePath = page.path;
269
+ dimensions.clickPageTitle = page.title;
270
+ dimensions.clickX = data.x;
271
+ dimensions.clickY = data.y;
272
+ }
273
+ return {
274
+ __time__: Math.floor(Date.now() / 1e3),
275
+ __source__: "live-admin-v3",
276
+ timestamp,
277
+ environment: mitoConfig.environment,
278
+ sessionId: getSessionId(),
279
+ user: userInfo,
280
+ dataType: data.type || "unknown",
281
+ metricType: getMetricType(data),
282
+ value: extractValue(data),
283
+ event: {
284
+ type: data.type,
285
+ url: typeof window !== "undefined" && window.location ? window.location.href : "",
286
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "unknown",
287
+ referrer: typeof document !== "undefined" ? document.referrer : void 0
288
+ },
289
+ techStack: {
290
+ vue: ((_a = context.Vue) == null ? void 0 : _a.version) || "unknown",
291
+ platform: typeof navigator !== "undefined" ? navigator.platform : "unknown",
292
+ language: typeof navigator !== "undefined" ? navigator.language : "unknown"
293
+ },
294
+ rawData: isDebugEnabled ? data : void 0,
295
+ dimensions
296
+ };
297
+ };
298
+ var shouldReport = (data) => {
299
+ const dataType = data.type;
300
+ const sampleRate = mitoConfig.sampleRate[dataType] || 0;
301
+ if (sampleRate === 0)
302
+ return false;
303
+ if (sampleRate === 1)
304
+ return true;
305
+ return Math.random() < sampleRate;
306
+ };
307
+
308
+ // src/core/MitoSLSAdapter.ts
309
+ var import_browser = require("@mitojs/browser");
310
+
311
+ // src/transport/SLSWebTrackingAdapter.ts
312
+ var import_web_track_browser = __toESM(require("@aliyun-sls/web-track-browser"));
313
+ var getEnv2 = (key, defaultValue = "") => {
314
+ const env = getRUMEnv();
315
+ if (env && Object.prototype.hasOwnProperty.call(env, key)) {
316
+ return env[key] || defaultValue;
317
+ }
318
+ return defaultValue;
319
+ };
320
+ var SLSWebTrackingAdapter = class {
321
+ constructor(config = {}) {
322
+ this.slsTracker = null;
323
+ this.isInitialized = false;
324
+ this.isDestroyed = false;
325
+ this.pendingLogs = [];
326
+ this.retryQueue = [];
327
+ var _a, _b, _c, _d, _e, _f, _g;
328
+ this.config = {
329
+ host: config.host || getEnv2("VUE_APP_SLS_HOST", "cn-shenzhen.log.aliyuncs.com"),
330
+ project: config.project || getEnv2("VUE_APP_SLS_PROJECT", "live-admin-rum"),
331
+ logstore: config.logstore || "rum-traces-dev",
332
+ time: (_a = config.time) != null ? _a : 10,
333
+ count: (_b = config.count) != null ? _b : 10,
334
+ topic: config.topic || "rum-monitor",
335
+ source: config.source || "web",
336
+ environment: config.environment || getEnv2("NODE_ENV", "development"),
337
+ debug: (_c = config.debug) != null ? _c : getEnv2("VUE_APP_RUM_DEBUG", "false") === "true",
338
+ enabled: (_d = config.enabled) != null ? _d : true,
339
+ userId: (_e = config.userId) != null ? _e : null,
340
+ sessionId: config.sessionId || this.generateSessionId(),
341
+ appName: config.appName || "live-admin-v3",
342
+ appVersion: config.appVersion || getEnv2("PACKAGE_VERSION", "1.0.0"),
343
+ retryCount: (_f = config.retryCount) != null ? _f : 3,
344
+ retryInterval: (_g = config.retryInterval) != null ? _g : 2e3
345
+ };
346
+ this.handleBeforeSend = this.handleBeforeSend.bind(this);
347
+ this.handleError = this.handleError.bind(this);
348
+ }
349
+ async init() {
350
+ if (this.isInitialized) {
351
+ console.warn("SLSWebTrackingAdapter already initialized");
352
+ return;
353
+ }
354
+ if (this.isDestroyed) {
355
+ throw new Error(
356
+ "SLSWebTrackingAdapter has been destroyed, cannot reinitialize"
357
+ );
358
+ }
359
+ if (!this.config.enabled) {
360
+ if (this.config.debug) {
361
+ console.log("SLSWebTrackingAdapter is disabled");
362
+ }
363
+ return;
364
+ }
365
+ if (this.config.debug) {
366
+ console.log("\u{1F680} Initializing SLSWebTrackingAdapter...", {
367
+ config: this.config,
368
+ SlsTracker: typeof import_web_track_browser.default
369
+ });
370
+ }
371
+ try {
372
+ this.slsTracker = new import_web_track_browser.default({
373
+ host: this.config.host,
374
+ project: this.config.project,
375
+ logstore: this.config.logstore,
376
+ time: this.config.time,
377
+ count: this.config.count,
378
+ topic: this.config.topic,
379
+ source: this.config.source,
380
+ autoPopulateFields: false,
381
+ beforeSend: this.handleBeforeSend
382
+ });
383
+ this.isInitialized = true;
384
+ if (this.config.debug) {
385
+ console.log("\u2705 SLSWebTrackingAdapter initialized successfully", {
386
+ project: this.config.project,
387
+ logstore: this.config.logstore,
388
+ host: this.config.host,
389
+ trackerInstance: !!this.slsTracker
390
+ });
391
+ }
392
+ await this.sendLog({
393
+ type: "system",
394
+ category: "init",
395
+ message: "SLS WebTracking adapter initialized successfully",
396
+ level: "info",
397
+ timestamp: Date.now()
398
+ });
399
+ } catch (error) {
400
+ console.error("\u274C Failed to initialize SLSWebTrackingAdapter:", error);
401
+ this.handleError(error);
402
+ throw error;
403
+ }
404
+ }
405
+ async sendLog(data) {
406
+ if (this.config.debug) {
407
+ console.log("\u{1F4E4} Sending log to SLS...", {
408
+ originalData: data,
409
+ isReady: this.checkReady(),
410
+ hasTracker: !!this.slsTracker,
411
+ isInitialized: this.isInitialized
412
+ });
413
+ }
414
+ if (!this.checkReady()) {
415
+ if (this.config.debug) {
416
+ console.log("\u274C SLS adapter not ready, skipping log send");
417
+ }
418
+ return;
419
+ }
420
+ try {
421
+ const logData = await this.transformLogData(data);
422
+ if (this.config.debug) {
423
+ console.log("\u{1F527} Transformed SLS Log Data:", logData);
424
+ }
425
+ await this.slsTracker.send(logData);
426
+ if (this.config.debug) {
427
+ console.log("\u2705 Log sent to SLS successfully");
428
+ }
429
+ } catch (error) {
430
+ console.error("\u274C Failed to send log to SLS:", error);
431
+ await this.handleSendError(data, error);
432
+ }
433
+ }
434
+ async sendBatchLogs(logs) {
435
+ if (!this.checkReady()) {
436
+ return;
437
+ }
438
+ if (!Array.isArray(logs) || logs.length === 0) {
439
+ return;
440
+ }
441
+ try {
442
+ const transformedLogs = await Promise.all(
443
+ logs.map((log) => this.transformLogData(log))
444
+ );
445
+ for (const logData of transformedLogs) {
446
+ await this.slsTracker.send(logData);
447
+ }
448
+ if (this.config.debug) {
449
+ console.log(
450
+ `Batch sent ${transformedLogs.length} logs to SLS successfully`
451
+ );
452
+ }
453
+ } catch (error) {
454
+ console.error("Failed to send batch logs to SLS:", error);
455
+ for (const log of logs) {
456
+ await this.handleSendError(log, error);
457
+ }
458
+ }
459
+ }
460
+ async transformLogData(data) {
461
+ const timestamp = Math.floor(Date.now() / 1e3);
462
+ const logData = {
463
+ __time__: timestamp,
464
+ __source__: this.config.source,
465
+ // 基础信息
466
+ event_type: data.eventType || data.type || "unknown",
467
+ category: data.category || "general",
468
+ level: data.level || "info",
469
+ client_timestamp: Date.now(),
470
+ // 应用信息
471
+ app_name: this.config.appName,
472
+ // app_version: this.config.appVersion,
473
+ environment: this.config.environment,
474
+ // 会话信息
475
+ session_id: this.config.sessionId,
476
+ // 页面信息
477
+ page_url: typeof window !== "undefined" && window.location ? window.location.href : "",
478
+ page_title: typeof document !== "undefined" ? document.title : void 0,
479
+ page_path: typeof window !== "undefined" && window.location ? window.location.pathname : "",
480
+ // 用户代理信息
481
+ user_agent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
482
+ language: typeof navigator !== "undefined" ? navigator.language : void 0
483
+ };
484
+ if (this.config.userId) {
485
+ logData.user_id = this.config.userId;
486
+ }
487
+ if (data.userId) {
488
+ logData.user_id = data.userId;
489
+ }
490
+ if (data.userName) {
491
+ logData.user_name = data.userName;
492
+ }
493
+ if (data.userEmail) {
494
+ logData.user_email = data.userEmail;
495
+ }
496
+ if (logData.event_type === "error") {
497
+ this.addErrorFields(logData, data);
498
+ } else if (logData.event_type === "xhr" || logData.event_type === "fetch") {
499
+ this.addApiFields(logData, data);
500
+ } else if (logData.event_type === "click") {
501
+ this.addClickFields(logData, data);
502
+ }
503
+ try {
504
+ let hash = "";
505
+ if (data && typeof data.hash === "string") {
506
+ hash = data.hash;
507
+ } else if (data && data.dimensions && typeof data.dimensions.hash === "string") {
508
+ hash = data.dimensions.hash;
509
+ } else if (typeof window !== "undefined" && typeof window.location !== "undefined") {
510
+ hash = window.location.hash || "";
511
+ }
512
+ logData.detail_json = JSON.stringify({ hash });
513
+ } catch (error) {
514
+ console.warn("Failed to serialize detail data:", error);
515
+ logData.detail_json = JSON.stringify({
516
+ error: "Failed to serialize data"
517
+ });
518
+ }
519
+ return logData;
520
+ }
521
+ addErrorFields(logData, data) {
522
+ if (data.message) {
523
+ logData.error_message = String(data.message);
524
+ }
525
+ if (data.stack) {
526
+ logData.error_stack = String(data.stack);
527
+ }
528
+ if (data.filename) {
529
+ logData.error_filename = data.filename;
530
+ }
531
+ if (data.lineno) {
532
+ logData.error_lineno = String(data.lineno);
533
+ }
534
+ if (data.colno) {
535
+ logData.error_colno = String(data.colno);
536
+ }
537
+ if (data.name) {
538
+ logData.error_name = data.name;
539
+ }
540
+ }
541
+ addApiFields(logData, data) {
542
+ if (data.url) {
543
+ logData.api_url = data.url;
544
+ }
545
+ if (data.method) {
546
+ logData.api_method = data.method;
547
+ }
548
+ if (data.status !== void 0) {
549
+ logData.api_status = Number(data.status);
550
+ }
551
+ if (data.duration !== void 0) {
552
+ logData.api_duration = Number(data.duration);
553
+ }
554
+ if (data.responseSize !== void 0) {
555
+ logData.api_response_size = Number(data.responseSize);
556
+ }
557
+ }
558
+ addClickFields(logData, data) {
559
+ if (data.clickBizId || data.bizId) {
560
+ logData.click_biz_id = data.clickBizId || data.bizId;
561
+ }
562
+ if (data.target) {
563
+ logData.click_target = data.target;
564
+ }
565
+ if (data.selector) {
566
+ logData.click_selector = data.selector;
567
+ }
568
+ if (data.text) {
569
+ logData.click_text = data.text;
570
+ }
571
+ if (data.x !== void 0) {
572
+ logData.click_x = Number(data.x);
573
+ }
574
+ if (data.y !== void 0) {
575
+ logData.click_y = Number(data.y);
576
+ }
577
+ }
578
+ filterSensitiveData(data) {
579
+ const sensitivePatterns = [
580
+ /password/i,
581
+ /token/i,
582
+ /secret/i,
583
+ /key/i,
584
+ /auth/i,
585
+ /credential/i
586
+ ];
587
+ const filtered = { ...data };
588
+ Object.keys(filtered).forEach((key) => {
589
+ const value = filtered[key];
590
+ if (typeof value === "string") {
591
+ if (sensitivePatterns.some((pattern) => pattern.test(key))) {
592
+ filtered[key] = "[FILTERED]";
593
+ }
594
+ if (filtered[key].length > 500) {
595
+ filtered[key] = `${filtered[key].substring(0, 500)}...`;
596
+ }
597
+ }
598
+ });
599
+ return filtered;
600
+ }
601
+ async handleSendError(data, error) {
602
+ const retryItem = {
603
+ data,
604
+ error,
605
+ timestamp: Date.now(),
606
+ retryCount: 0
607
+ };
608
+ this.retryQueue.push(retryItem);
609
+ if (this.shouldRetry(error)) {
610
+ setTimeout(() => {
611
+ this.retryFailedLogs();
612
+ }, this.config.retryInterval);
613
+ }
614
+ }
615
+ async retryFailedLogs() {
616
+ if (this.retryQueue.length === 0) {
617
+ return;
618
+ }
619
+ const itemsToRetry = this.retryQueue.filter(
620
+ (item) => item.retryCount < this.config.retryCount
621
+ );
622
+ this.retryQueue = this.retryQueue.filter(
623
+ (item) => item.retryCount >= this.config.retryCount
624
+ );
625
+ for (const item of itemsToRetry) {
626
+ try {
627
+ item.retryCount++;
628
+ await this.sendLog(item.data);
629
+ const index = this.retryQueue.indexOf(item);
630
+ if (index > -1) {
631
+ this.retryQueue.splice(index, 1);
632
+ }
633
+ } catch (error) {
634
+ console.warn(
635
+ `Retry failed for log (attempt ${item.retryCount}):`,
636
+ error
637
+ );
638
+ if (item.retryCount < this.config.retryCount) {
639
+ setTimeout(() => {
640
+ this.retryFailedLogs();
641
+ }, this.config.retryInterval * item.retryCount);
642
+ } else {
643
+ console.error("Max retry attempts reached, dropping log:", item.data);
644
+ }
645
+ }
646
+ }
647
+ }
648
+ shouldRetry(error) {
649
+ const retryableErrors = [
650
+ "Network timeout",
651
+ "Connection failed",
652
+ "Service unavailable",
653
+ "Rate limit exceeded"
654
+ ];
655
+ return retryableErrors.some(
656
+ (pattern) => error.message && error.message.includes(pattern)
657
+ );
658
+ }
659
+ handleError(error) {
660
+ console.error("SLSWebTrackingAdapter Error:", error);
661
+ }
662
+ checkReady() {
663
+ if (!this.config.enabled) {
664
+ return false;
665
+ }
666
+ if (!this.isInitialized) {
667
+ console.warn("SLSWebTrackingAdapter not initialized");
668
+ return false;
669
+ }
670
+ if (!this.slsTracker) {
671
+ console.warn("SLS Tracker not available");
672
+ return false;
673
+ }
674
+ return true;
675
+ }
676
+ generateSessionId() {
677
+ if (typeof sessionStorage !== "undefined") {
678
+ let sessionId = sessionStorage.getItem("sls_session_id");
679
+ if (!sessionId) {
680
+ sessionId = `session_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
681
+ sessionStorage.setItem("sls_session_id", sessionId);
682
+ }
683
+ return sessionId;
684
+ }
685
+ return `session_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
686
+ }
687
+ handleBeforeSend(logData) {
688
+ try {
689
+ const dataSize = JSON.stringify(logData).length;
690
+ const maxSize = 1024 * 1024;
691
+ if (dataSize > maxSize) {
692
+ console.warn("Log data too large, skipping:", dataSize);
693
+ return false;
694
+ }
695
+ const filteredData = this.filterSensitiveData(logData);
696
+ if (this.config.debug) {
697
+ console.log("Log before send:", filteredData);
698
+ }
699
+ return filteredData;
700
+ } catch (error) {
701
+ console.error("Error in beforeSend handler:", error);
702
+ return false;
703
+ }
704
+ }
705
+ setUserId(userId) {
706
+ this.config.userId = userId;
707
+ }
708
+ updateConfig(newConfig) {
709
+ this.config = { ...this.config, ...newConfig };
710
+ }
711
+ getConfig() {
712
+ return { ...this.config };
713
+ }
714
+ getStats() {
715
+ return {
716
+ isInitialized: this.isInitialized,
717
+ isDestroyed: this.isDestroyed,
718
+ pendingLogsCount: this.pendingLogs.length,
719
+ retryQueueCount: this.retryQueue.length,
720
+ config: {
721
+ project: this.config.project,
722
+ logstore: this.config.logstore,
723
+ enabled: this.config.enabled
724
+ }
725
+ };
726
+ }
727
+ destroy() {
728
+ if (this.isDestroyed) {
729
+ return;
730
+ }
731
+ try {
732
+ if (this.retryQueue.length > 0 && this.config.debug) {
733
+ console.warn(
734
+ `Destroying adapter with ${this.retryQueue.length} items in retry queue`
735
+ );
736
+ }
737
+ if (this.slsTracker && this.slsTracker.destroy) {
738
+ this.slsTracker.destroy();
739
+ }
740
+ this.isDestroyed = true;
741
+ this.isInitialized = false;
742
+ this.slsTracker = null;
743
+ this.pendingLogs = [];
744
+ this.retryQueue = [];
745
+ if (this.config.debug) {
746
+ console.log("SLSWebTrackingAdapter destroyed");
747
+ }
748
+ } catch (error) {
749
+ console.error("Error destroying SLSWebTrackingAdapter:", error);
750
+ }
751
+ }
752
+ };
753
+
754
+ // src/core/MitoSLSAdapter.ts
755
+ var MitoSLSAdapter = class {
756
+ constructor(options = {}) {
757
+ this.mitoInstance = null;
758
+ this.slsAdapter = null;
759
+ this.store = null;
760
+ this.router = null;
761
+ this.isInitialized = false;
762
+ this.options = {
763
+ ...mitoConfig,
764
+ ...options
765
+ };
766
+ this.handleDataReport = this.handleDataReport.bind(this);
767
+ this.handleRouteChange = this.handleRouteChange.bind(this);
768
+ this.handleError = this.handleError.bind(this);
769
+ this.addBreadcrumb = this.addBreadcrumb.bind(this);
770
+ }
771
+ addBreadcrumb(payload) {
772
+ if (!this.mitoInstance || !this.mitoInstance.breadcrumb) {
773
+ return;
774
+ }
775
+ const breadcrumb = this.mitoInstance.breadcrumb;
776
+ if (typeof breadcrumb.add === "function") {
777
+ breadcrumb.add(payload);
778
+ return;
779
+ }
780
+ if (typeof breadcrumb.push === "function") {
781
+ breadcrumb.push(payload);
782
+ }
783
+ }
784
+ async init(context = {}) {
785
+ var _a;
786
+ if (this.isInitialized) {
787
+ console.warn("MitoSLSAdapter already initialized");
788
+ return;
789
+ }
790
+ this.store = context.store;
791
+ this.router = context.router;
792
+ if (!this.options.dsn) {
793
+ console.warn(
794
+ "MitoSLSAdapter: DSN not configured, RUM system will run in simulation mode"
795
+ );
796
+ }
797
+ try {
798
+ const slsConfigOverride = this.options.slsConfigOverride || {};
799
+ this.slsAdapter = new SLSWebTrackingAdapter({
800
+ ...slsConfig,
801
+ ...slsConfigOverride
802
+ });
803
+ await this.slsAdapter.init();
804
+ this.mitoInstance = (0, import_browser.init)({
805
+ dsn: this.options.dsn || void 0,
806
+ debug: this.options.debug,
807
+ maxBreadcrumbs: this.options.maxBreadcrumbs,
808
+ Vue: context.Vue || ((_a = this.options.vue) == null ? void 0 : _a.Vue),
809
+ framework: {
810
+ vue: true
811
+ },
812
+ beforeDataReport: this.handleDataReport,
813
+ silent: !this.options.debug,
814
+ enableUrlHash: true,
815
+ enableUserAgent: true,
816
+ enableHistory: true,
817
+ performance: {
818
+ enable: this.options.user.performance,
819
+ sampleRate: this.options.sampleRate.performance || 1
820
+ },
821
+ user: {
822
+ enableClickTrack: this.options.user.click,
823
+ clickTrackSampleRate: this.options.sampleRate.click,
824
+ ignoreSelector: this.options.user.sensitiveSelectors.join(", ")
825
+ },
826
+ api: {
827
+ enableApiMonitor: this.options.network.xhr,
828
+ apiMonitorSampleRate: this.options.sampleRate.xhr,
829
+ ignoreUrls: this.options.network.ignoreUrls,
830
+ requestSizeLimit: this.options.network.responseSizeLimit * 1024
831
+ }
832
+ });
833
+ this.setupVueIntegration();
834
+ this.setupRouterIntegration();
835
+ this.setupErrorHandling();
836
+ this.isInitialized = true;
837
+ if (this.options.debug) {
838
+ console.log("MitoSLSAdapter initialized successfully");
839
+ }
840
+ } catch (error) {
841
+ console.error("Failed to initialize MitoSLSAdapter:", error);
842
+ this.handleError(error);
843
+ }
844
+ }
845
+ setupVueIntegration() {
846
+ if (!this.store) {
847
+ console.warn("Vuex store not provided, some features may be limited");
848
+ return;
849
+ }
850
+ this.store.subscribe((mutation) => {
851
+ try {
852
+ if (this.shouldTrackMutation(mutation)) {
853
+ this.addBreadcrumb({
854
+ type: "vuex",
855
+ message: `Vuex: ${mutation.type}`,
856
+ category: "vuex",
857
+ data: {
858
+ mutation: mutation.type,
859
+ payload: mutation.payload
860
+ }
861
+ });
862
+ }
863
+ } catch (error) {
864
+ console.warn("Failed to track Vuex mutation:", error);
865
+ }
866
+ });
867
+ if (this.options.debug) {
868
+ console.log("Vue integration configured");
869
+ }
870
+ }
871
+ setupRouterIntegration() {
872
+ if (!this.router) {
873
+ console.warn("Vue router not provided, route tracking disabled");
874
+ return;
875
+ }
876
+ this.router.afterEach((to, from) => {
877
+ try {
878
+ this.handleRouteChange(to, from);
879
+ } catch (error) {
880
+ console.warn("Failed to handle route change:", error);
881
+ }
882
+ });
883
+ if (this.options.debug) {
884
+ console.log("Router integration configured");
885
+ }
886
+ }
887
+ setupErrorHandling() {
888
+ if (this.options.debug) {
889
+ console.log("Error handling configured");
890
+ }
891
+ }
892
+ handleDataReport(data) {
893
+ try {
894
+ if (this.options.debug) {
895
+ console.log("\u{1F50D} MitoJS Data Report:", {
896
+ type: data.type,
897
+ timestamp: data.t || Date.now(),
898
+ data
899
+ });
900
+ }
901
+ if (!shouldReport(data)) {
902
+ if (this.options.debug) {
903
+ console.log("\u23ED\uFE0F Data filtered by sampling rate:", data.type);
904
+ }
905
+ return false;
906
+ }
907
+ const slsData = transformDataForSLS(data, {
908
+ store: this.store,
909
+ router: this.router
910
+ });
911
+ this.sendToSLS(slsData);
912
+ return false;
913
+ } catch (error) {
914
+ console.error("Failed to handle data report:", error);
915
+ return false;
916
+ }
917
+ }
918
+ handleRouteChange(to, from) {
919
+ try {
920
+ const routeData = {
921
+ type: "route",
922
+ from: {
923
+ path: from.fullPath,
924
+ name: from.name,
925
+ params: from.params,
926
+ query: from.query
927
+ },
928
+ to: {
929
+ path: to.fullPath,
930
+ name: to.name,
931
+ params: to.params,
932
+ query: to.query
933
+ },
934
+ timestamp: Date.now()
935
+ };
936
+ this.addBreadcrumb({
937
+ type: "route",
938
+ message: `Route: ${from.fullPath} -> ${to.fullPath}`,
939
+ category: "navigation",
940
+ data: routeData
941
+ });
942
+ if (shouldReport(routeData)) {
943
+ const slsData = transformDataForSLS(routeData, {
944
+ store: this.store,
945
+ router: this.router
946
+ });
947
+ this.sendToSLS(slsData);
948
+ }
949
+ } catch (error) {
950
+ console.error("Failed to handle route change:", error);
951
+ }
952
+ }
953
+ handleError(error) {
954
+ try {
955
+ const errorData = {
956
+ type: "error",
957
+ message: (error == null ? void 0 : error.message) || "Unknown error",
958
+ stack: error == null ? void 0 : error.stack,
959
+ name: error == null ? void 0 : error.name,
960
+ timestamp: Date.now()
961
+ };
962
+ this.addBreadcrumb({
963
+ type: "error",
964
+ message: errorData.message,
965
+ category: "error",
966
+ data: errorData
967
+ });
968
+ if (shouldReport(errorData)) {
969
+ const slsData = transformDataForSLS(errorData, {
970
+ store: this.store,
971
+ router: this.router
972
+ });
973
+ this.sendToSLS(slsData);
974
+ }
975
+ } catch (e) {
976
+ console.error("Failed to handle error:", e);
977
+ }
978
+ }
979
+ async sendToSLS(data) {
980
+ try {
981
+ if (!this.slsAdapter) {
982
+ if (this.options.debug) {
983
+ console.log("\u{1F4DD} RUM Data [SIMULATION MODE]:", data);
984
+ }
985
+ return;
986
+ }
987
+ const slsLogData = this.transformDataForSLSLog(data);
988
+ if (this.options.debug) {
989
+ console.log("\u{1F527} Transformed SLS Log Data:", slsLogData);
990
+ }
991
+ await this.slsAdapter.sendLog(slsLogData);
992
+ if (this.options.debug) {
993
+ console.log("\u2705 RUM Data sent to SLS successfully");
994
+ }
995
+ } catch (error) {
996
+ console.error("\u274C Failed to send data to SLS:", error);
997
+ if (this.options.debug) {
998
+ console.log("\u{1F504} RUM Data [FALLBACK MODE]:", data);
999
+ }
1000
+ }
1001
+ }
1002
+ transformDataForSLSLog(data) {
1003
+ var _a;
1004
+ return {
1005
+ eventType: data.dataType || ((_a = data.event) == null ? void 0 : _a.type) || "unknown",
1006
+ category: this.getEventCategory(data.dataType),
1007
+ level: this.getEventLevel(data.dataType),
1008
+ ...data.event,
1009
+ ...data.dimensions,
1010
+ ...data.rawData
1011
+ };
1012
+ }
1013
+ getEventCategory(dataType) {
1014
+ switch (dataType) {
1015
+ case "error":
1016
+ return "error";
1017
+ case "performance":
1018
+ return "performance";
1019
+ case "click":
1020
+ case "route":
1021
+ return "user";
1022
+ case "xhr":
1023
+ return "general";
1024
+ default:
1025
+ return "general";
1026
+ }
1027
+ }
1028
+ getEventLevel(dataType) {
1029
+ switch (dataType) {
1030
+ case "error":
1031
+ return "error";
1032
+ case "xhr":
1033
+ return "warn";
1034
+ default:
1035
+ return "info";
1036
+ }
1037
+ }
1038
+ getUserInfoFromStore() {
1039
+ var _a, _b;
1040
+ try {
1041
+ const user = ((_b = (_a = this.store) == null ? void 0 : _a.state) == null ? void 0 : _b.user) || {};
1042
+ return {
1043
+ userId: user.userId || user.id,
1044
+ userName: user.userName || user.name,
1045
+ accountId: user.accountId
1046
+ };
1047
+ } catch (error) {
1048
+ console.warn("Failed to get user info from store:", error);
1049
+ return {};
1050
+ }
1051
+ }
1052
+ shouldTrackMutation(mutation) {
1053
+ const ignoredMutations = ["SET_LOADING", "SET_CURRENT_PAGE", "UPDATE_MOUSE_POSITION"];
1054
+ return !ignoredMutations.includes(mutation.type);
1055
+ }
1056
+ trackEvent(eventData) {
1057
+ try {
1058
+ const customData = {
1059
+ type: "custom",
1060
+ timestamp: Date.now(),
1061
+ ...eventData
1062
+ };
1063
+ this.addBreadcrumb({
1064
+ type: "custom",
1065
+ message: `Custom Event: ${eventData.name || "unknown"}`,
1066
+ category: "custom",
1067
+ data: customData
1068
+ });
1069
+ if (shouldReport(customData)) {
1070
+ const slsData = transformDataForSLS(customData, {
1071
+ store: this.store,
1072
+ router: this.router
1073
+ });
1074
+ this.sendToSLS(slsData);
1075
+ }
1076
+ } catch (error) {
1077
+ console.error("Failed to track custom event:", error);
1078
+ }
1079
+ }
1080
+ setUser(userInfo) {
1081
+ try {
1082
+ if (this.mitoInstance && this.mitoInstance.setUser) {
1083
+ this.mitoInstance.setUser({
1084
+ id: userInfo.userId,
1085
+ username: userInfo.userName,
1086
+ email: userInfo.email
1087
+ });
1088
+ }
1089
+ if (this.slsAdapter && userInfo.userId) {
1090
+ this.slsAdapter.setUserId(userInfo.userId);
1091
+ }
1092
+ } catch (error) {
1093
+ console.error("Failed to set user info:", error);
1094
+ }
1095
+ }
1096
+ getBreadcrumbs() {
1097
+ var _a, _b;
1098
+ try {
1099
+ return ((_b = (_a = this.mitoInstance) == null ? void 0 : _a.getBreadcrumbs) == null ? void 0 : _b.call(_a)) || [];
1100
+ } catch (error) {
1101
+ console.error("Failed to get breadcrumbs:", error);
1102
+ return [];
1103
+ }
1104
+ }
1105
+ destroy() {
1106
+ try {
1107
+ if (typeof window !== "undefined") {
1108
+ window.removeEventListener("error", this.handleError);
1109
+ window.removeEventListener(
1110
+ "unhandledrejection",
1111
+ this.handleError
1112
+ );
1113
+ }
1114
+ if (this.mitoInstance && this.mitoInstance.destroy) {
1115
+ this.mitoInstance.destroy();
1116
+ }
1117
+ if (this.slsAdapter) {
1118
+ this.slsAdapter.destroy();
1119
+ }
1120
+ this.isInitialized = false;
1121
+ if (this.options.debug) {
1122
+ console.log("MitoSLSAdapter destroyed");
1123
+ }
1124
+ } catch (error) {
1125
+ console.error("Failed to destroy MitoSLSAdapter:", error);
1126
+ }
1127
+ }
1128
+ };
1129
+ var instance = null;
1130
+ var getMitoAdapter = (options = {}) => {
1131
+ if (!instance) {
1132
+ instance = new MitoSLSAdapter(options);
1133
+ }
1134
+ return instance;
1135
+ };
1136
+ var initRUMCore = async (context, options = {}) => {
1137
+ const adapter = getMitoAdapter(options);
1138
+ await adapter.init(context);
1139
+ return adapter;
1140
+ };
1141
+ var getRUMCoreInstance = () => instance;
1142
+
1143
+ // src/vue2/plugin.vue2.ts
1144
+ var plugin_vue2_exports = {};
1145
+ __export(plugin_vue2_exports, {
1146
+ RUMPluginVue2: () => RUMPluginVue2,
1147
+ destroyRUM: () => destroyRUM,
1148
+ disableRUM: () => disableRUM,
1149
+ enableRUM: () => enableRUM,
1150
+ getBreadcrumbs: () => getBreadcrumbs,
1151
+ getRUMConfig: () => getRUMConfig,
1152
+ getRUMManager: () => getRUMManager,
1153
+ initRUMSystem: () => initRUMSystem,
1154
+ trackAction: () => trackAction,
1155
+ trackEvent: () => trackEvent,
1156
+ trackMetric: () => trackMetric,
1157
+ trackPerformance: () => trackPerformance
1158
+ });
1159
+
1160
+ // src/vue2/RUMManager.vue2.ts
1161
+ var RUMManagerVue2 = class {
1162
+ constructor() {
1163
+ this.adapter = null;
1164
+ this.isInitialized = false;
1165
+ this.isEnabled = true;
1166
+ this.context = {};
1167
+ }
1168
+ async init(context, options = {}) {
1169
+ try {
1170
+ if (!this.shouldEnableRUM()) {
1171
+ if (mitoConfig.debug) {
1172
+ console.log("RUM system is disabled");
1173
+ }
1174
+ return;
1175
+ }
1176
+ if (this.isInitialized) {
1177
+ if (mitoConfig.debug) {
1178
+ console.log("RUM system already initialized");
1179
+ }
1180
+ return;
1181
+ }
1182
+ this.context = {
1183
+ store: context.store,
1184
+ router: context.router,
1185
+ Vue: context.Vue,
1186
+ ...context
1187
+ };
1188
+ const mergedOptions = {
1189
+ ...mitoConfig,
1190
+ ...options,
1191
+ vue: {
1192
+ ...mitoConfig.vue,
1193
+ ...options.vue
1194
+ }
1195
+ };
1196
+ this.adapter = await initRUMCore(
1197
+ {
1198
+ store: this.context.store,
1199
+ router: this.context.router,
1200
+ Vue: this.context.Vue
1201
+ },
1202
+ mergedOptions
1203
+ );
1204
+ this.setUserInfo();
1205
+ this.setupUserStateListener();
1206
+ this.setupUserInteractionTracking();
1207
+ this.isInitialized = true;
1208
+ if (mitoConfig.debug) {
1209
+ console.log("RUM system initialized successfully");
1210
+ }
1211
+ } catch (error) {
1212
+ console.error("Failed to initialize RUM system:", error);
1213
+ }
1214
+ }
1215
+ shouldEnableRUM() {
1216
+ if (!this.isEnabled) {
1217
+ return false;
1218
+ }
1219
+ const env = getRUMEnv();
1220
+ const rumEnabled = env.VUE_APP_RUM_ENABLED;
1221
+ if (rumEnabled !== void 0) {
1222
+ return rumEnabled === "true";
1223
+ }
1224
+ const mode = env.MODE;
1225
+ const isProdEnv = mode === "prod" || mode === "production";
1226
+ return !isProdEnv;
1227
+ }
1228
+ setUserInfo() {
1229
+ if (!this.context.store) {
1230
+ return;
1231
+ }
1232
+ try {
1233
+ const userModule = this.context.store.state.user || {};
1234
+ const user = userModule.userInfo || userModule || {};
1235
+ if (this.adapter && user.userId) {
1236
+ this.adapter.setUser({
1237
+ userId: user.userId,
1238
+ userName: user.userName,
1239
+ accountId: user.accountId,
1240
+ roles: user.roles,
1241
+ email: user.email
1242
+ });
1243
+ }
1244
+ } catch (error) {
1245
+ console.warn("Failed to set user info:", error);
1246
+ }
1247
+ }
1248
+ setupUserStateListener() {
1249
+ if (!this.context.store) {
1250
+ return;
1251
+ }
1252
+ this.context.store.subscribe((mutation) => {
1253
+ if (mutation.type.includes("user")) {
1254
+ this.setUserInfo();
1255
+ }
1256
+ });
1257
+ }
1258
+ setupUserInteractionTracking() {
1259
+ if (typeof window === "undefined" || typeof document === "undefined") {
1260
+ return;
1261
+ }
1262
+ document.addEventListener(
1263
+ "click",
1264
+ (event) => {
1265
+ var _a, _b, _c;
1266
+ try {
1267
+ const originalTarget = event.target;
1268
+ const findClosest = (el, selector) => el && typeof el.closest === "function" ? el.closest(selector) : null;
1269
+ let target = findClosest(originalTarget, "[rum-id],[rum-name]");
1270
+ if (!target) {
1271
+ target = findClosest(
1272
+ originalTarget,
1273
+ 'button, a, [role="button"], [role="link"]'
1274
+ );
1275
+ }
1276
+ if (!target && originalTarget && window.getComputedStyle) {
1277
+ const style = window.getComputedStyle(originalTarget);
1278
+ if (style.cursor === "pointer") {
1279
+ target = originalTarget;
1280
+ }
1281
+ }
1282
+ if (!target) {
1283
+ return;
1284
+ }
1285
+ const getAttr = (el, name) => el && typeof el.getAttribute === "function" ? el.getAttribute(name) : null;
1286
+ let bizId = getAttr(target, "rum-id") || getAttr(target, "rum-name") || "";
1287
+ if (!bizId) {
1288
+ const tagName = target.tagName ? target.tagName.toLowerCase() : "element";
1289
+ const classList = (target.className || "").toString().split(/\s+/).filter((c) => c.trim());
1290
+ const primaryClass = classList[0] || "no-class";
1291
+ const getLabel = (el) => {
1292
+ if (!el)
1293
+ return "";
1294
+ const text = (el.textContent || "").trim();
1295
+ if (text)
1296
+ return text;
1297
+ const ariaLabel = getAttr(el, "aria-label");
1298
+ if (ariaLabel)
1299
+ return ariaLabel;
1300
+ const title = getAttr(el, "title");
1301
+ if (title)
1302
+ return title;
1303
+ const alt = getAttr(el, "alt");
1304
+ if (alt)
1305
+ return alt;
1306
+ const placeholder = getAttr(el, "placeholder");
1307
+ if (placeholder)
1308
+ return placeholder;
1309
+ const value = typeof el.value === "string" ? el.value.trim() : "";
1310
+ if (value)
1311
+ return value;
1312
+ return "";
1313
+ };
1314
+ const label = getLabel(target);
1315
+ const safeLabel = (label || primaryClass).replace(/\s+/g, "_").slice(0, 32) || "no_label";
1316
+ const route = ((_b = (_a = this.context) == null ? void 0 : _a.router) == null ? void 0 : _b.currentRoute) || {};
1317
+ const buildRouteKey = (r) => {
1318
+ try {
1319
+ if (!r)
1320
+ return "unknown_route";
1321
+ if (r.name) {
1322
+ return String(r.name);
1323
+ }
1324
+ if (Array.isArray(r.matched) && r.matched.length > 0) {
1325
+ const record = r.matched[r.matched.length - 1];
1326
+ if (record && record.path) {
1327
+ return record.path;
1328
+ }
1329
+ }
1330
+ if (r.path) {
1331
+ return r.path;
1332
+ }
1333
+ } catch {
1334
+ }
1335
+ return window.location.pathname || "unknown_route";
1336
+ };
1337
+ const routeKey = buildRouteKey(route);
1338
+ let indexSuffix = "";
1339
+ try {
1340
+ const parent = target.parentNode;
1341
+ if (parent && parent.children && parent.children.length) {
1342
+ const siblings = Array.from(parent.children).filter(
1343
+ (el) => el.tagName === target.tagName && el.className === target.className
1344
+ );
1345
+ const index = siblings.indexOf(target);
1346
+ if (index >= 0) {
1347
+ indexSuffix = `[${index}]`;
1348
+ }
1349
+ }
1350
+ } catch {
1351
+ }
1352
+ bizId = `${routeKey}|${tagName}.${primaryClass}${indexSuffix}|${safeLabel}`;
1353
+ }
1354
+ const targetInfo = {
1355
+ tagName: target.tagName,
1356
+ className: target.className,
1357
+ id: target.id,
1358
+ textContent: ((_c = target.textContent) == null ? void 0 : _c.substring(0, 50)) || "",
1359
+ selector: this.getCSSSelector(target)
1360
+ };
1361
+ this.trackAction("click", {
1362
+ type: "click",
1363
+ bizId,
1364
+ x: event.clientX,
1365
+ y: event.clientY,
1366
+ target: targetInfo,
1367
+ page: {
1368
+ url: window.location.href,
1369
+ title: document.title,
1370
+ path: window.location.pathname
1371
+ },
1372
+ timestamp: Date.now()
1373
+ });
1374
+ } catch (error) {
1375
+ console.warn("Failed to track click event:", error);
1376
+ }
1377
+ },
1378
+ true
1379
+ );
1380
+ document.addEventListener("visibilitychange", () => {
1381
+ });
1382
+ if (mitoConfig.debug) {
1383
+ console.log("User interaction tracking configured");
1384
+ }
1385
+ }
1386
+ getCSSSelector(element) {
1387
+ if (!element || element.nodeType !== Node.ELEMENT_NODE) {
1388
+ return "";
1389
+ }
1390
+ const path = [];
1391
+ let current = element;
1392
+ while (current && current.nodeType === Node.ELEMENT_NODE) {
1393
+ let selector = current.tagName.toLowerCase();
1394
+ if (current.id) {
1395
+ selector += `#${current.id}`;
1396
+ path.unshift(selector);
1397
+ break;
1398
+ }
1399
+ if (current.className) {
1400
+ const classes = current.className.split(" ").filter((c) => c.trim());
1401
+ if (classes.length > 0) {
1402
+ selector += `.${classes[0]}`;
1403
+ }
1404
+ }
1405
+ path.unshift(selector);
1406
+ current = current.parentElement;
1407
+ if (path.length > 5) {
1408
+ break;
1409
+ }
1410
+ }
1411
+ return path.join(" > ");
1412
+ }
1413
+ trackEvent(eventName, eventData = {}) {
1414
+ if (!this.checkRUMAvailable()) {
1415
+ return;
1416
+ }
1417
+ try {
1418
+ this.adapter.trackEvent({
1419
+ name: eventName,
1420
+ ...eventData
1421
+ });
1422
+ } catch (error) {
1423
+ console.error("Failed to track event:", error);
1424
+ }
1425
+ }
1426
+ trackPerformance(performanceData) {
1427
+ if (!this.checkRUMAvailable()) {
1428
+ return;
1429
+ }
1430
+ try {
1431
+ this.adapter.trackEvent({
1432
+ name: "performance",
1433
+ type: "performance",
1434
+ ...performanceData
1435
+ });
1436
+ } catch (error) {
1437
+ console.error("Failed to track performance:", error);
1438
+ }
1439
+ }
1440
+ trackAction(action, actionData = {}) {
1441
+ if (!this.checkRUMAvailable()) {
1442
+ return;
1443
+ }
1444
+ try {
1445
+ this.adapter.trackEvent({
1446
+ name: "user_action",
1447
+ action,
1448
+ ...actionData
1449
+ });
1450
+ } catch (error) {
1451
+ console.error("Failed to track action:", error);
1452
+ }
1453
+ }
1454
+ trackMetric(metricName, value, dimensions = {}) {
1455
+ if (!this.checkRUMAvailable()) {
1456
+ return;
1457
+ }
1458
+ try {
1459
+ this.adapter.trackEvent({
1460
+ name: "metric",
1461
+ metricName,
1462
+ value,
1463
+ dimensions
1464
+ });
1465
+ } catch (error) {
1466
+ console.error("Failed to track metric:", error);
1467
+ }
1468
+ }
1469
+ getBreadcrumbs() {
1470
+ if (!this.checkRUMAvailable()) {
1471
+ return [];
1472
+ }
1473
+ try {
1474
+ return this.adapter.getBreadcrumbs();
1475
+ } catch (error) {
1476
+ console.error("Failed to get breadcrumbs:", error);
1477
+ return [];
1478
+ }
1479
+ }
1480
+ enable() {
1481
+ this.isEnabled = true;
1482
+ if (mitoConfig.debug) {
1483
+ console.log("RUM system enabled");
1484
+ }
1485
+ }
1486
+ disable() {
1487
+ this.isEnabled = false;
1488
+ if (mitoConfig.debug) {
1489
+ console.log("RUM system disabled");
1490
+ }
1491
+ }
1492
+ checkRUMAvailable() {
1493
+ return this.isEnabled && this.isInitialized && !!this.adapter;
1494
+ }
1495
+ getConfig() {
1496
+ return {
1497
+ isInitialized: this.isInitialized,
1498
+ isEnabled: this.isEnabled,
1499
+ environment: mitoConfig.environment,
1500
+ debug: mitoConfig.debug,
1501
+ sls: {
1502
+ enabled: slsConfig.enabled,
1503
+ configured: true,
1504
+ project: slsConfig.project,
1505
+ logstore: slsConfig.logstore
1506
+ }
1507
+ };
1508
+ }
1509
+ destroy() {
1510
+ try {
1511
+ if (this.adapter) {
1512
+ this.adapter.destroy();
1513
+ this.adapter = null;
1514
+ }
1515
+ this.isInitialized = false;
1516
+ this.context = {};
1517
+ if (mitoConfig.debug) {
1518
+ console.log("RUM system destroyed");
1519
+ }
1520
+ } catch (error) {
1521
+ console.error("Failed to destroy RUM system:", error);
1522
+ }
1523
+ }
1524
+ };
1525
+
1526
+ // src/vue2/plugin.vue2.ts
1527
+ var rumManagerVue2 = new RUMManagerVue2();
1528
+ var initRUMSystem = (context, options = {}) => rumManagerVue2.init(context, options);
1529
+ var trackEvent = (eventName, eventData) => rumManagerVue2.trackEvent(eventName, eventData || {});
1530
+ var trackPerformance = (performanceData) => rumManagerVue2.trackPerformance(performanceData);
1531
+ var trackAction = (action, actionData) => rumManagerVue2.trackAction(action, actionData || {});
1532
+ var trackMetric = (metricName, value, dimensions) => rumManagerVue2.trackMetric(metricName, value, dimensions || {});
1533
+ var getBreadcrumbs = () => rumManagerVue2.getBreadcrumbs();
1534
+ var enableRUM = () => rumManagerVue2.enable();
1535
+ var disableRUM = () => rumManagerVue2.disable();
1536
+ var getRUMConfig = () => rumManagerVue2.getConfig();
1537
+ var destroyRUM = () => rumManagerVue2.destroy();
1538
+ var getRUMManager = () => rumManagerVue2;
1539
+ var RUMPluginVue2 = {
1540
+ install(Vue) {
1541
+ Vue.prototype.$rum = {
1542
+ trackEvent,
1543
+ trackPerformance,
1544
+ trackAction,
1545
+ trackMetric,
1546
+ getBreadcrumbs,
1547
+ enable: enableRUM,
1548
+ disable: disableRUM,
1549
+ getConfig: getRUMConfig
1550
+ };
1551
+ Vue.$rumManager = rumManagerVue2;
1552
+ }
1553
+ };
1554
+
1555
+ // src/vue3/plugin.vue3.ts
1556
+ var plugin_vue3_exports = {};
1557
+ __export(plugin_vue3_exports, {
1558
+ createRUMPluginVue3: () => createRUMPluginVue3,
1559
+ useRUM: () => useRUM
1560
+ });
1561
+ var import_vue = require("vue");
1562
+
1563
+ // src/vue3/RUMManager.vue3.ts
1564
+ var RUMManagerVue3 = class {
1565
+ constructor() {
1566
+ this.inner = new RUMManagerVue2();
1567
+ }
1568
+ init(context, options = {}) {
1569
+ return this.inner.init(context, options);
1570
+ }
1571
+ trackEvent(eventName, eventData = {}) {
1572
+ this.inner.trackEvent(eventName, eventData);
1573
+ }
1574
+ trackPerformance(performanceData) {
1575
+ this.inner.trackPerformance(performanceData);
1576
+ }
1577
+ trackAction(action, actionData = {}) {
1578
+ this.inner.trackAction(action, actionData);
1579
+ }
1580
+ trackMetric(metricName, value, dimensions = {}) {
1581
+ this.inner.trackMetric(metricName, value, dimensions);
1582
+ }
1583
+ getBreadcrumbs() {
1584
+ return this.inner.getBreadcrumbs();
1585
+ }
1586
+ enable() {
1587
+ this.inner.enable();
1588
+ }
1589
+ disable() {
1590
+ this.inner.disable();
1591
+ }
1592
+ getConfig() {
1593
+ return this.inner.getConfig();
1594
+ }
1595
+ destroy() {
1596
+ this.inner.destroy();
1597
+ }
1598
+ };
1599
+
1600
+ // src/vue3/plugin.vue3.ts
1601
+ function createRUMPluginVue3(options) {
1602
+ const manager = new RUMManagerVue3();
1603
+ return {
1604
+ install(app) {
1605
+ manager.init(
1606
+ { store: options.store, router: options.router },
1607
+ options.coreOptions || {}
1608
+ );
1609
+ app.config.globalProperties.$rum = {
1610
+ trackEvent: manager.trackEvent.bind(manager),
1611
+ trackPerformance: manager.trackPerformance.bind(manager),
1612
+ trackAction: manager.trackAction.bind(manager),
1613
+ trackMetric: manager.trackMetric.bind(manager),
1614
+ getBreadcrumbs: manager.getBreadcrumbs.bind(manager),
1615
+ enable: manager.enable.bind(manager),
1616
+ disable: manager.disable.bind(manager),
1617
+ getConfig: manager.getConfig.bind(manager)
1618
+ };
1619
+ app.provide("rum", manager);
1620
+ }
1621
+ };
1622
+ }
1623
+ function useRUM() {
1624
+ return (0, import_vue.inject)("rum");
1625
+ }
1626
+ // Annotate the CommonJS export names for ESM import in node:
1627
+ 0 && (module.exports = {
1628
+ MitoSLSAdapter,
1629
+ RUMPluginVue2,
1630
+ RUM_ENV,
1631
+ SLSWebTrackingAdapter,
1632
+ createRUMPluginVue3,
1633
+ destroyRUMVue2,
1634
+ disableRUMVue2,
1635
+ enableRUMVue2,
1636
+ getBreadcrumbsVue2,
1637
+ getMitoAdapter,
1638
+ getRUMConfigVue2,
1639
+ getRUMCoreInstance,
1640
+ getRUMEnv,
1641
+ getRUMManagerVue2,
1642
+ getUserInfo,
1643
+ initRUMCore,
1644
+ initRUMSystemVue2,
1645
+ mitoConfig,
1646
+ shouldReport,
1647
+ slsConfig,
1648
+ trackActionVue2,
1649
+ trackEventVue2,
1650
+ trackMetricVue2,
1651
+ trackPerformanceVue2,
1652
+ transformDataForSLS,
1653
+ useRUM,
1654
+ vue2,
1655
+ vue3
1656
+ });
1657
+ //# sourceMappingURL=index.js.map