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