@bbearai/core 0.2.9 → 0.2.11

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.d.mts CHANGED
@@ -116,6 +116,8 @@ interface HostUserInfo {
116
116
  id: string;
117
117
  /** User's email address */
118
118
  email: string;
119
+ /** User's display name (optional, used for reporter identity) */
120
+ name?: string;
119
121
  }
120
122
  interface BugBearConfig {
121
123
  /** Your BugBear project ID */
package/dist/index.d.ts CHANGED
@@ -116,6 +116,8 @@ interface HostUserInfo {
116
116
  id: string;
117
117
  /** User's email address */
118
118
  email: string;
119
+ /** User's display name (optional, used for reporter identity) */
120
+ name?: string;
119
121
  }
120
122
  interface BugBearConfig {
121
123
  /** Your BugBear project ID */
package/dist/index.js CHANGED
@@ -29,6 +29,174 @@ module.exports = __toCommonJS(index_exports);
29
29
 
30
30
  // src/client.ts
31
31
  var import_supabase_js = require("@supabase/supabase-js");
32
+
33
+ // src/capture.ts
34
+ var MAX_CONSOLE_LOGS = 50;
35
+ var MAX_NETWORK_REQUESTS = 20;
36
+ var ContextCaptureManager = class {
37
+ constructor() {
38
+ this.consoleLogs = [];
39
+ this.networkRequests = [];
40
+ this.originalConsole = {};
41
+ this.isCapturing = false;
42
+ }
43
+ /**
44
+ * Start capturing console logs and network requests
45
+ */
46
+ startCapture() {
47
+ if (this.isCapturing) return;
48
+ this.isCapturing = true;
49
+ this.captureConsole();
50
+ this.captureFetch();
51
+ }
52
+ /**
53
+ * Stop capturing and restore original functions
54
+ */
55
+ stopCapture() {
56
+ if (!this.isCapturing) return;
57
+ this.isCapturing = false;
58
+ if (this.originalConsole.log) console.log = this.originalConsole.log;
59
+ if (this.originalConsole.warn) console.warn = this.originalConsole.warn;
60
+ if (this.originalConsole.error) console.error = this.originalConsole.error;
61
+ if (this.originalConsole.info) console.info = this.originalConsole.info;
62
+ if (this.originalFetch && typeof window !== "undefined") {
63
+ window.fetch = this.originalFetch;
64
+ }
65
+ }
66
+ /**
67
+ * Get captured context for a bug report
68
+ */
69
+ getEnhancedContext() {
70
+ return {
71
+ consoleLogs: [...this.consoleLogs],
72
+ networkRequests: [...this.networkRequests],
73
+ performanceMetrics: this.getPerformanceMetrics(),
74
+ environment: this.getEnvironmentInfo()
75
+ };
76
+ }
77
+ /**
78
+ * Clear captured data
79
+ */
80
+ clear() {
81
+ this.consoleLogs = [];
82
+ this.networkRequests = [];
83
+ }
84
+ /**
85
+ * Add a log entry manually (for custom logging)
86
+ */
87
+ addLog(level, message, args) {
88
+ this.consoleLogs.push({
89
+ level,
90
+ message,
91
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
92
+ args
93
+ });
94
+ if (this.consoleLogs.length > MAX_CONSOLE_LOGS) {
95
+ this.consoleLogs = this.consoleLogs.slice(-MAX_CONSOLE_LOGS);
96
+ }
97
+ }
98
+ /**
99
+ * Add a network request manually
100
+ */
101
+ addNetworkRequest(request) {
102
+ this.networkRequests.push(request);
103
+ if (this.networkRequests.length > MAX_NETWORK_REQUESTS) {
104
+ this.networkRequests = this.networkRequests.slice(-MAX_NETWORK_REQUESTS);
105
+ }
106
+ }
107
+ captureConsole() {
108
+ if (typeof console === "undefined") return;
109
+ const levels = ["log", "warn", "error", "info"];
110
+ levels.forEach((level) => {
111
+ this.originalConsole[level] = console[level];
112
+ console[level] = (...args) => {
113
+ this.originalConsole[level]?.apply(console, args);
114
+ try {
115
+ const message = args.map((arg) => {
116
+ if (typeof arg === "string") return arg;
117
+ try {
118
+ return JSON.stringify(arg);
119
+ } catch {
120
+ return String(arg);
121
+ }
122
+ }).join(" ");
123
+ this.addLog(level, message.slice(0, 500));
124
+ } catch {
125
+ }
126
+ };
127
+ });
128
+ }
129
+ captureFetch() {
130
+ if (typeof window === "undefined" || typeof fetch === "undefined") return;
131
+ this.originalFetch = window.fetch;
132
+ const self = this;
133
+ window.fetch = async function(input, init) {
134
+ const startTime = Date.now();
135
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
136
+ const method = init?.method || "GET";
137
+ try {
138
+ const response = await self.originalFetch.call(window, input, init);
139
+ self.addNetworkRequest({
140
+ method,
141
+ url: url.slice(0, 200),
142
+ // Limit URL length
143
+ status: response.status,
144
+ duration: Date.now() - startTime,
145
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
146
+ });
147
+ return response;
148
+ } catch (error) {
149
+ self.addNetworkRequest({
150
+ method,
151
+ url: url.slice(0, 200),
152
+ duration: Date.now() - startTime,
153
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
154
+ error: error instanceof Error ? error.message : "Unknown error"
155
+ });
156
+ throw error;
157
+ }
158
+ };
159
+ }
160
+ getPerformanceMetrics() {
161
+ if (typeof window === "undefined" || typeof performance === "undefined") return void 0;
162
+ const metrics = {};
163
+ try {
164
+ const navigation = performance.getEntriesByType("navigation")[0];
165
+ if (navigation) {
166
+ metrics.pageLoadTime = Math.round(navigation.loadEventEnd - navigation.startTime);
167
+ }
168
+ } catch {
169
+ }
170
+ try {
171
+ const memory = performance.memory;
172
+ if (memory) {
173
+ metrics.memoryUsage = Math.round(memory.usedJSHeapSize / 1024 / 1024);
174
+ }
175
+ } catch {
176
+ }
177
+ return Object.keys(metrics).length > 0 ? metrics : void 0;
178
+ }
179
+ getEnvironmentInfo() {
180
+ if (typeof window === "undefined" || typeof navigator === "undefined") return void 0;
181
+ return {
182
+ language: navigator.language,
183
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
184
+ cookiesEnabled: navigator.cookieEnabled,
185
+ localStorage: typeof localStorage !== "undefined",
186
+ online: navigator.onLine
187
+ };
188
+ }
189
+ };
190
+ var contextCapture = new ContextCaptureManager();
191
+ function captureError(error, errorInfo) {
192
+ return {
193
+ errorMessage: error.message,
194
+ errorStack: error.stack,
195
+ componentStack: errorInfo?.componentStack
196
+ };
197
+ }
198
+
199
+ // src/client.ts
32
200
  var DEFAULT_SUPABASE_URL = "https://kyxgzjnqgvapvlnvqawz.supabase.co";
33
201
  var getEnvVar = (key) => {
34
202
  try {
@@ -105,6 +273,8 @@ var BugBearClient = class {
105
273
  project_id: this.config.projectId,
106
274
  reporter_id: userInfo.id,
107
275
  // User ID from host app (required)
276
+ reporter_name: testerInfo?.name || userInfo.name || null,
277
+ reporter_email: userInfo.email || null,
108
278
  tester_id: testerInfo?.id || null,
109
279
  // Tester record ID (optional)
110
280
  report_type: report.type,
@@ -118,6 +288,7 @@ var BugBearClient = class {
118
288
  app_context: report.appContext,
119
289
  device_info: report.deviceInfo || this.getDeviceInfo(),
120
290
  navigation_history: this.getNavigationHistory(),
291
+ enhanced_context: report.enhancedContext || contextCapture.getEnhancedContext(),
121
292
  assignment_id: report.assignmentId,
122
293
  test_case_id: report.testCaseId
123
294
  };
@@ -180,7 +351,7 @@ var BugBearClient = class {
180
351
  console.error("BugBear: Failed to fetch assignments", error);
181
352
  return [];
182
353
  }
183
- return (data || []).map((item) => ({
354
+ const mapped = (data || []).map((item) => ({
184
355
  id: item.id,
185
356
  status: item.status,
186
357
  startedAt: item.started_at,
@@ -213,6 +384,12 @@ var BugBearClient = class {
213
384
  } : void 0
214
385
  }
215
386
  }));
387
+ mapped.sort((a, b) => {
388
+ if (a.isVerification && !b.isVerification) return -1;
389
+ if (!a.isVerification && b.isVerification) return 1;
390
+ return 0;
391
+ });
392
+ return mapped;
216
393
  } catch (err) {
217
394
  console.error("BugBear: Error fetching assignments", err);
218
395
  return [];
@@ -1345,172 +1522,6 @@ var BugBearClient = class {
1345
1522
  function createBugBear(config) {
1346
1523
  return new BugBearClient(config);
1347
1524
  }
1348
-
1349
- // src/capture.ts
1350
- var MAX_CONSOLE_LOGS = 50;
1351
- var MAX_NETWORK_REQUESTS = 20;
1352
- var ContextCaptureManager = class {
1353
- constructor() {
1354
- this.consoleLogs = [];
1355
- this.networkRequests = [];
1356
- this.originalConsole = {};
1357
- this.isCapturing = false;
1358
- }
1359
- /**
1360
- * Start capturing console logs and network requests
1361
- */
1362
- startCapture() {
1363
- if (this.isCapturing) return;
1364
- this.isCapturing = true;
1365
- this.captureConsole();
1366
- this.captureFetch();
1367
- }
1368
- /**
1369
- * Stop capturing and restore original functions
1370
- */
1371
- stopCapture() {
1372
- if (!this.isCapturing) return;
1373
- this.isCapturing = false;
1374
- if (this.originalConsole.log) console.log = this.originalConsole.log;
1375
- if (this.originalConsole.warn) console.warn = this.originalConsole.warn;
1376
- if (this.originalConsole.error) console.error = this.originalConsole.error;
1377
- if (this.originalConsole.info) console.info = this.originalConsole.info;
1378
- if (this.originalFetch && typeof window !== "undefined") {
1379
- window.fetch = this.originalFetch;
1380
- }
1381
- }
1382
- /**
1383
- * Get captured context for a bug report
1384
- */
1385
- getEnhancedContext() {
1386
- return {
1387
- consoleLogs: [...this.consoleLogs],
1388
- networkRequests: [...this.networkRequests],
1389
- performanceMetrics: this.getPerformanceMetrics(),
1390
- environment: this.getEnvironmentInfo()
1391
- };
1392
- }
1393
- /**
1394
- * Clear captured data
1395
- */
1396
- clear() {
1397
- this.consoleLogs = [];
1398
- this.networkRequests = [];
1399
- }
1400
- /**
1401
- * Add a log entry manually (for custom logging)
1402
- */
1403
- addLog(level, message, args) {
1404
- this.consoleLogs.push({
1405
- level,
1406
- message,
1407
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1408
- args
1409
- });
1410
- if (this.consoleLogs.length > MAX_CONSOLE_LOGS) {
1411
- this.consoleLogs = this.consoleLogs.slice(-MAX_CONSOLE_LOGS);
1412
- }
1413
- }
1414
- /**
1415
- * Add a network request manually
1416
- */
1417
- addNetworkRequest(request) {
1418
- this.networkRequests.push(request);
1419
- if (this.networkRequests.length > MAX_NETWORK_REQUESTS) {
1420
- this.networkRequests = this.networkRequests.slice(-MAX_NETWORK_REQUESTS);
1421
- }
1422
- }
1423
- captureConsole() {
1424
- if (typeof console === "undefined") return;
1425
- const levels = ["log", "warn", "error", "info"];
1426
- levels.forEach((level) => {
1427
- this.originalConsole[level] = console[level];
1428
- console[level] = (...args) => {
1429
- this.originalConsole[level]?.apply(console, args);
1430
- try {
1431
- const message = args.map((arg) => {
1432
- if (typeof arg === "string") return arg;
1433
- try {
1434
- return JSON.stringify(arg);
1435
- } catch {
1436
- return String(arg);
1437
- }
1438
- }).join(" ");
1439
- this.addLog(level, message.slice(0, 500));
1440
- } catch {
1441
- }
1442
- };
1443
- });
1444
- }
1445
- captureFetch() {
1446
- if (typeof window === "undefined" || typeof fetch === "undefined") return;
1447
- this.originalFetch = window.fetch;
1448
- const self = this;
1449
- window.fetch = async function(input, init) {
1450
- const startTime = Date.now();
1451
- const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
1452
- const method = init?.method || "GET";
1453
- try {
1454
- const response = await self.originalFetch.call(window, input, init);
1455
- self.addNetworkRequest({
1456
- method,
1457
- url: url.slice(0, 200),
1458
- // Limit URL length
1459
- status: response.status,
1460
- duration: Date.now() - startTime,
1461
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1462
- });
1463
- return response;
1464
- } catch (error) {
1465
- self.addNetworkRequest({
1466
- method,
1467
- url: url.slice(0, 200),
1468
- duration: Date.now() - startTime,
1469
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1470
- error: error instanceof Error ? error.message : "Unknown error"
1471
- });
1472
- throw error;
1473
- }
1474
- };
1475
- }
1476
- getPerformanceMetrics() {
1477
- if (typeof window === "undefined" || typeof performance === "undefined") return void 0;
1478
- const metrics = {};
1479
- try {
1480
- const navigation = performance.getEntriesByType("navigation")[0];
1481
- if (navigation) {
1482
- metrics.pageLoadTime = Math.round(navigation.loadEventEnd - navigation.startTime);
1483
- }
1484
- } catch {
1485
- }
1486
- try {
1487
- const memory = performance.memory;
1488
- if (memory) {
1489
- metrics.memoryUsage = Math.round(memory.usedJSHeapSize / 1024 / 1024);
1490
- }
1491
- } catch {
1492
- }
1493
- return Object.keys(metrics).length > 0 ? metrics : void 0;
1494
- }
1495
- getEnvironmentInfo() {
1496
- if (typeof window === "undefined" || typeof navigator === "undefined") return void 0;
1497
- return {
1498
- language: navigator.language,
1499
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
1500
- cookiesEnabled: navigator.cookieEnabled,
1501
- localStorage: typeof localStorage !== "undefined",
1502
- online: navigator.onLine
1503
- };
1504
- }
1505
- };
1506
- var contextCapture = new ContextCaptureManager();
1507
- function captureError(error, errorInfo) {
1508
- return {
1509
- errorMessage: error.message,
1510
- errorStack: error.stack,
1511
- componentStack: errorInfo?.componentStack
1512
- };
1513
- }
1514
1525
  // Annotate the CommonJS export names for ESM import in node:
1515
1526
  0 && (module.exports = {
1516
1527
  BugBearClient,
package/dist/index.mjs CHANGED
@@ -1,5 +1,173 @@
1
1
  // src/client.ts
2
2
  import { createClient } from "@supabase/supabase-js";
3
+
4
+ // src/capture.ts
5
+ var MAX_CONSOLE_LOGS = 50;
6
+ var MAX_NETWORK_REQUESTS = 20;
7
+ var ContextCaptureManager = class {
8
+ constructor() {
9
+ this.consoleLogs = [];
10
+ this.networkRequests = [];
11
+ this.originalConsole = {};
12
+ this.isCapturing = false;
13
+ }
14
+ /**
15
+ * Start capturing console logs and network requests
16
+ */
17
+ startCapture() {
18
+ if (this.isCapturing) return;
19
+ this.isCapturing = true;
20
+ this.captureConsole();
21
+ this.captureFetch();
22
+ }
23
+ /**
24
+ * Stop capturing and restore original functions
25
+ */
26
+ stopCapture() {
27
+ if (!this.isCapturing) return;
28
+ this.isCapturing = false;
29
+ if (this.originalConsole.log) console.log = this.originalConsole.log;
30
+ if (this.originalConsole.warn) console.warn = this.originalConsole.warn;
31
+ if (this.originalConsole.error) console.error = this.originalConsole.error;
32
+ if (this.originalConsole.info) console.info = this.originalConsole.info;
33
+ if (this.originalFetch && typeof window !== "undefined") {
34
+ window.fetch = this.originalFetch;
35
+ }
36
+ }
37
+ /**
38
+ * Get captured context for a bug report
39
+ */
40
+ getEnhancedContext() {
41
+ return {
42
+ consoleLogs: [...this.consoleLogs],
43
+ networkRequests: [...this.networkRequests],
44
+ performanceMetrics: this.getPerformanceMetrics(),
45
+ environment: this.getEnvironmentInfo()
46
+ };
47
+ }
48
+ /**
49
+ * Clear captured data
50
+ */
51
+ clear() {
52
+ this.consoleLogs = [];
53
+ this.networkRequests = [];
54
+ }
55
+ /**
56
+ * Add a log entry manually (for custom logging)
57
+ */
58
+ addLog(level, message, args) {
59
+ this.consoleLogs.push({
60
+ level,
61
+ message,
62
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
63
+ args
64
+ });
65
+ if (this.consoleLogs.length > MAX_CONSOLE_LOGS) {
66
+ this.consoleLogs = this.consoleLogs.slice(-MAX_CONSOLE_LOGS);
67
+ }
68
+ }
69
+ /**
70
+ * Add a network request manually
71
+ */
72
+ addNetworkRequest(request) {
73
+ this.networkRequests.push(request);
74
+ if (this.networkRequests.length > MAX_NETWORK_REQUESTS) {
75
+ this.networkRequests = this.networkRequests.slice(-MAX_NETWORK_REQUESTS);
76
+ }
77
+ }
78
+ captureConsole() {
79
+ if (typeof console === "undefined") return;
80
+ const levels = ["log", "warn", "error", "info"];
81
+ levels.forEach((level) => {
82
+ this.originalConsole[level] = console[level];
83
+ console[level] = (...args) => {
84
+ this.originalConsole[level]?.apply(console, args);
85
+ try {
86
+ const message = args.map((arg) => {
87
+ if (typeof arg === "string") return arg;
88
+ try {
89
+ return JSON.stringify(arg);
90
+ } catch {
91
+ return String(arg);
92
+ }
93
+ }).join(" ");
94
+ this.addLog(level, message.slice(0, 500));
95
+ } catch {
96
+ }
97
+ };
98
+ });
99
+ }
100
+ captureFetch() {
101
+ if (typeof window === "undefined" || typeof fetch === "undefined") return;
102
+ this.originalFetch = window.fetch;
103
+ const self = this;
104
+ window.fetch = async function(input, init) {
105
+ const startTime = Date.now();
106
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
107
+ const method = init?.method || "GET";
108
+ try {
109
+ const response = await self.originalFetch.call(window, input, init);
110
+ self.addNetworkRequest({
111
+ method,
112
+ url: url.slice(0, 200),
113
+ // Limit URL length
114
+ status: response.status,
115
+ duration: Date.now() - startTime,
116
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
117
+ });
118
+ return response;
119
+ } catch (error) {
120
+ self.addNetworkRequest({
121
+ method,
122
+ url: url.slice(0, 200),
123
+ duration: Date.now() - startTime,
124
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
125
+ error: error instanceof Error ? error.message : "Unknown error"
126
+ });
127
+ throw error;
128
+ }
129
+ };
130
+ }
131
+ getPerformanceMetrics() {
132
+ if (typeof window === "undefined" || typeof performance === "undefined") return void 0;
133
+ const metrics = {};
134
+ try {
135
+ const navigation = performance.getEntriesByType("navigation")[0];
136
+ if (navigation) {
137
+ metrics.pageLoadTime = Math.round(navigation.loadEventEnd - navigation.startTime);
138
+ }
139
+ } catch {
140
+ }
141
+ try {
142
+ const memory = performance.memory;
143
+ if (memory) {
144
+ metrics.memoryUsage = Math.round(memory.usedJSHeapSize / 1024 / 1024);
145
+ }
146
+ } catch {
147
+ }
148
+ return Object.keys(metrics).length > 0 ? metrics : void 0;
149
+ }
150
+ getEnvironmentInfo() {
151
+ if (typeof window === "undefined" || typeof navigator === "undefined") return void 0;
152
+ return {
153
+ language: navigator.language,
154
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
155
+ cookiesEnabled: navigator.cookieEnabled,
156
+ localStorage: typeof localStorage !== "undefined",
157
+ online: navigator.onLine
158
+ };
159
+ }
160
+ };
161
+ var contextCapture = new ContextCaptureManager();
162
+ function captureError(error, errorInfo) {
163
+ return {
164
+ errorMessage: error.message,
165
+ errorStack: error.stack,
166
+ componentStack: errorInfo?.componentStack
167
+ };
168
+ }
169
+
170
+ // src/client.ts
3
171
  var DEFAULT_SUPABASE_URL = "https://kyxgzjnqgvapvlnvqawz.supabase.co";
4
172
  var getEnvVar = (key) => {
5
173
  try {
@@ -76,6 +244,8 @@ var BugBearClient = class {
76
244
  project_id: this.config.projectId,
77
245
  reporter_id: userInfo.id,
78
246
  // User ID from host app (required)
247
+ reporter_name: testerInfo?.name || userInfo.name || null,
248
+ reporter_email: userInfo.email || null,
79
249
  tester_id: testerInfo?.id || null,
80
250
  // Tester record ID (optional)
81
251
  report_type: report.type,
@@ -89,6 +259,7 @@ var BugBearClient = class {
89
259
  app_context: report.appContext,
90
260
  device_info: report.deviceInfo || this.getDeviceInfo(),
91
261
  navigation_history: this.getNavigationHistory(),
262
+ enhanced_context: report.enhancedContext || contextCapture.getEnhancedContext(),
92
263
  assignment_id: report.assignmentId,
93
264
  test_case_id: report.testCaseId
94
265
  };
@@ -151,7 +322,7 @@ var BugBearClient = class {
151
322
  console.error("BugBear: Failed to fetch assignments", error);
152
323
  return [];
153
324
  }
154
- return (data || []).map((item) => ({
325
+ const mapped = (data || []).map((item) => ({
155
326
  id: item.id,
156
327
  status: item.status,
157
328
  startedAt: item.started_at,
@@ -184,6 +355,12 @@ var BugBearClient = class {
184
355
  } : void 0
185
356
  }
186
357
  }));
358
+ mapped.sort((a, b) => {
359
+ if (a.isVerification && !b.isVerification) return -1;
360
+ if (!a.isVerification && b.isVerification) return 1;
361
+ return 0;
362
+ });
363
+ return mapped;
187
364
  } catch (err) {
188
365
  console.error("BugBear: Error fetching assignments", err);
189
366
  return [];
@@ -1316,172 +1493,6 @@ var BugBearClient = class {
1316
1493
  function createBugBear(config) {
1317
1494
  return new BugBearClient(config);
1318
1495
  }
1319
-
1320
- // src/capture.ts
1321
- var MAX_CONSOLE_LOGS = 50;
1322
- var MAX_NETWORK_REQUESTS = 20;
1323
- var ContextCaptureManager = class {
1324
- constructor() {
1325
- this.consoleLogs = [];
1326
- this.networkRequests = [];
1327
- this.originalConsole = {};
1328
- this.isCapturing = false;
1329
- }
1330
- /**
1331
- * Start capturing console logs and network requests
1332
- */
1333
- startCapture() {
1334
- if (this.isCapturing) return;
1335
- this.isCapturing = true;
1336
- this.captureConsole();
1337
- this.captureFetch();
1338
- }
1339
- /**
1340
- * Stop capturing and restore original functions
1341
- */
1342
- stopCapture() {
1343
- if (!this.isCapturing) return;
1344
- this.isCapturing = false;
1345
- if (this.originalConsole.log) console.log = this.originalConsole.log;
1346
- if (this.originalConsole.warn) console.warn = this.originalConsole.warn;
1347
- if (this.originalConsole.error) console.error = this.originalConsole.error;
1348
- if (this.originalConsole.info) console.info = this.originalConsole.info;
1349
- if (this.originalFetch && typeof window !== "undefined") {
1350
- window.fetch = this.originalFetch;
1351
- }
1352
- }
1353
- /**
1354
- * Get captured context for a bug report
1355
- */
1356
- getEnhancedContext() {
1357
- return {
1358
- consoleLogs: [...this.consoleLogs],
1359
- networkRequests: [...this.networkRequests],
1360
- performanceMetrics: this.getPerformanceMetrics(),
1361
- environment: this.getEnvironmentInfo()
1362
- };
1363
- }
1364
- /**
1365
- * Clear captured data
1366
- */
1367
- clear() {
1368
- this.consoleLogs = [];
1369
- this.networkRequests = [];
1370
- }
1371
- /**
1372
- * Add a log entry manually (for custom logging)
1373
- */
1374
- addLog(level, message, args) {
1375
- this.consoleLogs.push({
1376
- level,
1377
- message,
1378
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1379
- args
1380
- });
1381
- if (this.consoleLogs.length > MAX_CONSOLE_LOGS) {
1382
- this.consoleLogs = this.consoleLogs.slice(-MAX_CONSOLE_LOGS);
1383
- }
1384
- }
1385
- /**
1386
- * Add a network request manually
1387
- */
1388
- addNetworkRequest(request) {
1389
- this.networkRequests.push(request);
1390
- if (this.networkRequests.length > MAX_NETWORK_REQUESTS) {
1391
- this.networkRequests = this.networkRequests.slice(-MAX_NETWORK_REQUESTS);
1392
- }
1393
- }
1394
- captureConsole() {
1395
- if (typeof console === "undefined") return;
1396
- const levels = ["log", "warn", "error", "info"];
1397
- levels.forEach((level) => {
1398
- this.originalConsole[level] = console[level];
1399
- console[level] = (...args) => {
1400
- this.originalConsole[level]?.apply(console, args);
1401
- try {
1402
- const message = args.map((arg) => {
1403
- if (typeof arg === "string") return arg;
1404
- try {
1405
- return JSON.stringify(arg);
1406
- } catch {
1407
- return String(arg);
1408
- }
1409
- }).join(" ");
1410
- this.addLog(level, message.slice(0, 500));
1411
- } catch {
1412
- }
1413
- };
1414
- });
1415
- }
1416
- captureFetch() {
1417
- if (typeof window === "undefined" || typeof fetch === "undefined") return;
1418
- this.originalFetch = window.fetch;
1419
- const self = this;
1420
- window.fetch = async function(input, init) {
1421
- const startTime = Date.now();
1422
- const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
1423
- const method = init?.method || "GET";
1424
- try {
1425
- const response = await self.originalFetch.call(window, input, init);
1426
- self.addNetworkRequest({
1427
- method,
1428
- url: url.slice(0, 200),
1429
- // Limit URL length
1430
- status: response.status,
1431
- duration: Date.now() - startTime,
1432
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1433
- });
1434
- return response;
1435
- } catch (error) {
1436
- self.addNetworkRequest({
1437
- method,
1438
- url: url.slice(0, 200),
1439
- duration: Date.now() - startTime,
1440
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1441
- error: error instanceof Error ? error.message : "Unknown error"
1442
- });
1443
- throw error;
1444
- }
1445
- };
1446
- }
1447
- getPerformanceMetrics() {
1448
- if (typeof window === "undefined" || typeof performance === "undefined") return void 0;
1449
- const metrics = {};
1450
- try {
1451
- const navigation = performance.getEntriesByType("navigation")[0];
1452
- if (navigation) {
1453
- metrics.pageLoadTime = Math.round(navigation.loadEventEnd - navigation.startTime);
1454
- }
1455
- } catch {
1456
- }
1457
- try {
1458
- const memory = performance.memory;
1459
- if (memory) {
1460
- metrics.memoryUsage = Math.round(memory.usedJSHeapSize / 1024 / 1024);
1461
- }
1462
- } catch {
1463
- }
1464
- return Object.keys(metrics).length > 0 ? metrics : void 0;
1465
- }
1466
- getEnvironmentInfo() {
1467
- if (typeof window === "undefined" || typeof navigator === "undefined") return void 0;
1468
- return {
1469
- language: navigator.language,
1470
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
1471
- cookiesEnabled: navigator.cookieEnabled,
1472
- localStorage: typeof localStorage !== "undefined",
1473
- online: navigator.onLine
1474
- };
1475
- }
1476
- };
1477
- var contextCapture = new ContextCaptureManager();
1478
- function captureError(error, errorInfo) {
1479
- return {
1480
- errorMessage: error.message,
1481
- errorStack: error.stack,
1482
- componentStack: errorInfo?.componentStack
1483
- };
1484
- }
1485
1496
  export {
1486
1497
  BugBearClient,
1487
1498
  captureError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbearai/core",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "Core utilities and types for BugBear QA platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",