@bbearai/core 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -273,6 +273,11 @@ function captureError(error, errorInfo) {
273
273
  }
274
274
 
275
275
  // src/client.ts
276
+ var formatPgError = (e) => {
277
+ if (!e || typeof e !== "object") return { raw: e };
278
+ const { message, code, details, hint } = e;
279
+ return { message, code, details, hint };
280
+ };
276
281
  var DEFAULT_SUPABASE_URL = "https://kyxgzjnqgvapvlnvqawz.supabase.co";
277
282
  var getEnvVar = (key) => {
278
283
  try {
@@ -442,7 +447,7 @@ var BugBearClient = class {
442
447
  )
443
448
  `).eq("project_id", this.config.projectId).eq("tester_id", testerInfo.id).in("status", ["pending", "in_progress"]).order("created_at", { ascending: true }).limit(100);
444
449
  if (error) {
445
- console.error("BugBear: Failed to fetch assignments", error);
450
+ console.error("BugBear: Failed to fetch assignments", formatPgError(error));
446
451
  return [];
447
452
  }
448
453
  const mapped = (data || []).map((item) => ({
@@ -670,7 +675,7 @@ var BugBearClient = class {
670
675
  }
671
676
  const { error } = await this.supabase.from("test_assignments").update(updateData).eq("id", assignmentId);
672
677
  if (error) {
673
- console.error("BugBear: Failed to skip assignment", error);
678
+ console.error("BugBear: Failed to skip assignment", formatPgError(error));
674
679
  return { success: false, error: error.message };
675
680
  }
676
681
  return { success: true };
@@ -849,7 +854,7 @@ var BugBearClient = class {
849
854
  p_tester_id: testerInfo.id
850
855
  });
851
856
  if (error) {
852
- console.error("BugBear: Failed to fetch tester stats", error);
857
+ console.error("BugBear: Failed to fetch tester stats", formatPgError(error));
853
858
  return null;
854
859
  }
855
860
  return data;
@@ -1000,7 +1005,7 @@ var BugBearClient = class {
1000
1005
  if (updates.platforms !== void 0) updateData.platforms = updates.platforms;
1001
1006
  const { error } = await this.supabase.from("testers").update(updateData).eq("id", testerInfo.id);
1002
1007
  if (error) {
1003
- console.error("BugBear: updateTesterProfile error", error);
1008
+ console.error("BugBear: updateTesterProfile error", formatPgError(error));
1004
1009
  return { success: false, error: error.message };
1005
1010
  }
1006
1011
  return { success: true };
@@ -1022,14 +1027,14 @@ var BugBearClient = class {
1022
1027
  */
1023
1028
  async isQAEnabled() {
1024
1029
  try {
1025
- const { data, error } = await this.supabase.from("projects").select("is_qa_enabled").eq("id", this.config.projectId).single();
1030
+ const { data, error } = await this.supabase.rpc("check_qa_enabled", {
1031
+ p_project_id: this.config.projectId
1032
+ });
1026
1033
  if (error) {
1027
- if (error.code !== "PGRST116") {
1028
- console.warn("BugBear: Could not check QA status", error.message || error.code || "Unknown error");
1029
- }
1034
+ console.warn("BugBear: Could not check QA status", error.message || error.code || "Unknown error");
1030
1035
  return true;
1031
1036
  }
1032
- return data?.is_qa_enabled ?? true;
1037
+ return data ?? true;
1033
1038
  } catch (err) {
1034
1039
  return true;
1035
1040
  }
@@ -1059,7 +1064,7 @@ var BugBearClient = class {
1059
1064
  upsert: false
1060
1065
  });
1061
1066
  if (error) {
1062
- console.error("BugBear: Failed to upload screenshot", error);
1067
+ console.error("BugBear: Failed to upload screenshot", formatPgError(error));
1063
1068
  return null;
1064
1069
  }
1065
1070
  const { data: { publicUrl } } = this.supabase.storage.from(bucket).getPublicUrl(path);
@@ -1090,7 +1095,7 @@ var BugBearClient = class {
1090
1095
  upsert: false
1091
1096
  });
1092
1097
  if (error) {
1093
- console.error("BugBear: Failed to upload image from URI", error);
1098
+ console.error("BugBear: Failed to upload image from URI", formatPgError(error));
1094
1099
  return null;
1095
1100
  }
1096
1101
  const { data: { publicUrl } } = this.supabase.storage.from(bucket).getPublicUrl(path);
@@ -1165,7 +1170,7 @@ var BugBearClient = class {
1165
1170
  }
1166
1171
  const { data, error } = await query;
1167
1172
  if (error) {
1168
- console.error("BugBear: Failed to fetch fix requests", error);
1173
+ console.error("BugBear: Failed to fetch fix requests", formatPgError(error));
1169
1174
  return [];
1170
1175
  }
1171
1176
  return (data || []).map((fr) => ({
@@ -1196,7 +1201,7 @@ var BugBearClient = class {
1196
1201
  p_tester_id: testerInfo.id
1197
1202
  });
1198
1203
  if (error) {
1199
- console.error("BugBear: Failed to fetch threads via RPC", error);
1204
+ console.error("BugBear: Failed to fetch threads via RPC", formatPgError(error));
1200
1205
  return [];
1201
1206
  }
1202
1207
  if (!data || data.length === 0) return [];
@@ -1240,7 +1245,7 @@ var BugBearClient = class {
1240
1245
  attachments
1241
1246
  `).eq("thread_id", threadId).order("created_at", { ascending: true }).limit(200);
1242
1247
  if (error) {
1243
- console.error("BugBear: Failed to fetch messages", error);
1248
+ console.error("BugBear: Failed to fetch messages", formatPgError(error));
1244
1249
  return [];
1245
1250
  }
1246
1251
  return (data || []).map((msg) => ({
@@ -1284,7 +1289,7 @@ var BugBearClient = class {
1284
1289
  }
1285
1290
  const { error } = await this.supabase.from("discussion_messages").insert(insertData);
1286
1291
  if (error) {
1287
- console.error("BugBear: Failed to send message", error);
1292
+ console.error("BugBear: Failed to send message", formatPgError(error));
1288
1293
  return false;
1289
1294
  }
1290
1295
  await this.markThreadAsRead(threadId);
@@ -1400,7 +1405,7 @@ var BugBearClient = class {
1400
1405
  p_platform: options.platform || null
1401
1406
  });
1402
1407
  if (error) {
1403
- console.error("BugBear: Failed to start session", error);
1408
+ console.error("BugBear: Failed to start session", formatPgError(error));
1404
1409
  return { success: false, error: error.message };
1405
1410
  }
1406
1411
  const session = await this.getSession(data);
@@ -1425,7 +1430,7 @@ var BugBearClient = class {
1425
1430
  p_routes_covered: options.routesCovered || null
1426
1431
  });
1427
1432
  if (error) {
1428
- console.error("BugBear: Failed to end session", error);
1433
+ console.error("BugBear: Failed to end session", formatPgError(error));
1429
1434
  return { success: false, error: error.message };
1430
1435
  }
1431
1436
  const session = this.transformSession(data);
@@ -1473,7 +1478,7 @@ var BugBearClient = class {
1473
1478
  if (!testerInfo) return [];
1474
1479
  const { data, error } = await this.supabase.from("qa_sessions").select("*").eq("project_id", this.config.projectId).eq("tester_id", testerInfo.id).order("started_at", { ascending: false }).limit(limit);
1475
1480
  if (error) {
1476
- console.error("BugBear: Failed to fetch session history", error);
1481
+ console.error("BugBear: Failed to fetch session history", formatPgError(error));
1477
1482
  return [];
1478
1483
  }
1479
1484
  return (data || []).map((s) => this.transformSession(s));
@@ -1501,7 +1506,7 @@ var BugBearClient = class {
1501
1506
  p_app_context: options.appContext || null
1502
1507
  });
1503
1508
  if (error) {
1504
- console.error("BugBear: Failed to add finding", error);
1509
+ console.error("BugBear: Failed to add finding", formatPgError(error));
1505
1510
  return { success: false, error: error.message };
1506
1511
  }
1507
1512
  const finding = this.transformFinding(data);
@@ -1519,7 +1524,7 @@ var BugBearClient = class {
1519
1524
  try {
1520
1525
  const { data, error } = await this.supabase.from("qa_findings").select("*").eq("session_id", sessionId).order("created_at", { ascending: true }).limit(100);
1521
1526
  if (error) {
1522
- console.error("BugBear: Failed to fetch findings", error);
1527
+ console.error("BugBear: Failed to fetch findings", formatPgError(error));
1523
1528
  return [];
1524
1529
  }
1525
1530
  return (data || []).map((f) => this.transformFinding(f));
@@ -1537,7 +1542,7 @@ var BugBearClient = class {
1537
1542
  p_finding_id: findingId
1538
1543
  });
1539
1544
  if (error) {
1540
- console.error("BugBear: Failed to convert finding", error);
1545
+ console.error("BugBear: Failed to convert finding", formatPgError(error));
1541
1546
  return { success: false, error: error.message };
1542
1547
  }
1543
1548
  return { success: true, bugId: data };
@@ -1558,7 +1563,7 @@ var BugBearClient = class {
1558
1563
  dismissed_at: (/* @__PURE__ */ new Date()).toISOString()
1559
1564
  }).eq("id", findingId);
1560
1565
  if (error) {
1561
- console.error("BugBear: Failed to dismiss finding", error);
1566
+ console.error("BugBear: Failed to dismiss finding", formatPgError(error));
1562
1567
  return { success: false, error: error.message };
1563
1568
  }
1564
1569
  return { success: true };
package/dist/index.mjs CHANGED
@@ -244,6 +244,11 @@ function captureError(error, errorInfo) {
244
244
  }
245
245
 
246
246
  // src/client.ts
247
+ var formatPgError = (e) => {
248
+ if (!e || typeof e !== "object") return { raw: e };
249
+ const { message, code, details, hint } = e;
250
+ return { message, code, details, hint };
251
+ };
247
252
  var DEFAULT_SUPABASE_URL = "https://kyxgzjnqgvapvlnvqawz.supabase.co";
248
253
  var getEnvVar = (key) => {
249
254
  try {
@@ -413,7 +418,7 @@ var BugBearClient = class {
413
418
  )
414
419
  `).eq("project_id", this.config.projectId).eq("tester_id", testerInfo.id).in("status", ["pending", "in_progress"]).order("created_at", { ascending: true }).limit(100);
415
420
  if (error) {
416
- console.error("BugBear: Failed to fetch assignments", error);
421
+ console.error("BugBear: Failed to fetch assignments", formatPgError(error));
417
422
  return [];
418
423
  }
419
424
  const mapped = (data || []).map((item) => ({
@@ -641,7 +646,7 @@ var BugBearClient = class {
641
646
  }
642
647
  const { error } = await this.supabase.from("test_assignments").update(updateData).eq("id", assignmentId);
643
648
  if (error) {
644
- console.error("BugBear: Failed to skip assignment", error);
649
+ console.error("BugBear: Failed to skip assignment", formatPgError(error));
645
650
  return { success: false, error: error.message };
646
651
  }
647
652
  return { success: true };
@@ -820,7 +825,7 @@ var BugBearClient = class {
820
825
  p_tester_id: testerInfo.id
821
826
  });
822
827
  if (error) {
823
- console.error("BugBear: Failed to fetch tester stats", error);
828
+ console.error("BugBear: Failed to fetch tester stats", formatPgError(error));
824
829
  return null;
825
830
  }
826
831
  return data;
@@ -971,7 +976,7 @@ var BugBearClient = class {
971
976
  if (updates.platforms !== void 0) updateData.platforms = updates.platforms;
972
977
  const { error } = await this.supabase.from("testers").update(updateData).eq("id", testerInfo.id);
973
978
  if (error) {
974
- console.error("BugBear: updateTesterProfile error", error);
979
+ console.error("BugBear: updateTesterProfile error", formatPgError(error));
975
980
  return { success: false, error: error.message };
976
981
  }
977
982
  return { success: true };
@@ -993,14 +998,14 @@ var BugBearClient = class {
993
998
  */
994
999
  async isQAEnabled() {
995
1000
  try {
996
- const { data, error } = await this.supabase.from("projects").select("is_qa_enabled").eq("id", this.config.projectId).single();
1001
+ const { data, error } = await this.supabase.rpc("check_qa_enabled", {
1002
+ p_project_id: this.config.projectId
1003
+ });
997
1004
  if (error) {
998
- if (error.code !== "PGRST116") {
999
- console.warn("BugBear: Could not check QA status", error.message || error.code || "Unknown error");
1000
- }
1005
+ console.warn("BugBear: Could not check QA status", error.message || error.code || "Unknown error");
1001
1006
  return true;
1002
1007
  }
1003
- return data?.is_qa_enabled ?? true;
1008
+ return data ?? true;
1004
1009
  } catch (err) {
1005
1010
  return true;
1006
1011
  }
@@ -1030,7 +1035,7 @@ var BugBearClient = class {
1030
1035
  upsert: false
1031
1036
  });
1032
1037
  if (error) {
1033
- console.error("BugBear: Failed to upload screenshot", error);
1038
+ console.error("BugBear: Failed to upload screenshot", formatPgError(error));
1034
1039
  return null;
1035
1040
  }
1036
1041
  const { data: { publicUrl } } = this.supabase.storage.from(bucket).getPublicUrl(path);
@@ -1061,7 +1066,7 @@ var BugBearClient = class {
1061
1066
  upsert: false
1062
1067
  });
1063
1068
  if (error) {
1064
- console.error("BugBear: Failed to upload image from URI", error);
1069
+ console.error("BugBear: Failed to upload image from URI", formatPgError(error));
1065
1070
  return null;
1066
1071
  }
1067
1072
  const { data: { publicUrl } } = this.supabase.storage.from(bucket).getPublicUrl(path);
@@ -1136,7 +1141,7 @@ var BugBearClient = class {
1136
1141
  }
1137
1142
  const { data, error } = await query;
1138
1143
  if (error) {
1139
- console.error("BugBear: Failed to fetch fix requests", error);
1144
+ console.error("BugBear: Failed to fetch fix requests", formatPgError(error));
1140
1145
  return [];
1141
1146
  }
1142
1147
  return (data || []).map((fr) => ({
@@ -1167,7 +1172,7 @@ var BugBearClient = class {
1167
1172
  p_tester_id: testerInfo.id
1168
1173
  });
1169
1174
  if (error) {
1170
- console.error("BugBear: Failed to fetch threads via RPC", error);
1175
+ console.error("BugBear: Failed to fetch threads via RPC", formatPgError(error));
1171
1176
  return [];
1172
1177
  }
1173
1178
  if (!data || data.length === 0) return [];
@@ -1211,7 +1216,7 @@ var BugBearClient = class {
1211
1216
  attachments
1212
1217
  `).eq("thread_id", threadId).order("created_at", { ascending: true }).limit(200);
1213
1218
  if (error) {
1214
- console.error("BugBear: Failed to fetch messages", error);
1219
+ console.error("BugBear: Failed to fetch messages", formatPgError(error));
1215
1220
  return [];
1216
1221
  }
1217
1222
  return (data || []).map((msg) => ({
@@ -1255,7 +1260,7 @@ var BugBearClient = class {
1255
1260
  }
1256
1261
  const { error } = await this.supabase.from("discussion_messages").insert(insertData);
1257
1262
  if (error) {
1258
- console.error("BugBear: Failed to send message", error);
1263
+ console.error("BugBear: Failed to send message", formatPgError(error));
1259
1264
  return false;
1260
1265
  }
1261
1266
  await this.markThreadAsRead(threadId);
@@ -1371,7 +1376,7 @@ var BugBearClient = class {
1371
1376
  p_platform: options.platform || null
1372
1377
  });
1373
1378
  if (error) {
1374
- console.error("BugBear: Failed to start session", error);
1379
+ console.error("BugBear: Failed to start session", formatPgError(error));
1375
1380
  return { success: false, error: error.message };
1376
1381
  }
1377
1382
  const session = await this.getSession(data);
@@ -1396,7 +1401,7 @@ var BugBearClient = class {
1396
1401
  p_routes_covered: options.routesCovered || null
1397
1402
  });
1398
1403
  if (error) {
1399
- console.error("BugBear: Failed to end session", error);
1404
+ console.error("BugBear: Failed to end session", formatPgError(error));
1400
1405
  return { success: false, error: error.message };
1401
1406
  }
1402
1407
  const session = this.transformSession(data);
@@ -1444,7 +1449,7 @@ var BugBearClient = class {
1444
1449
  if (!testerInfo) return [];
1445
1450
  const { data, error } = await this.supabase.from("qa_sessions").select("*").eq("project_id", this.config.projectId).eq("tester_id", testerInfo.id).order("started_at", { ascending: false }).limit(limit);
1446
1451
  if (error) {
1447
- console.error("BugBear: Failed to fetch session history", error);
1452
+ console.error("BugBear: Failed to fetch session history", formatPgError(error));
1448
1453
  return [];
1449
1454
  }
1450
1455
  return (data || []).map((s) => this.transformSession(s));
@@ -1472,7 +1477,7 @@ var BugBearClient = class {
1472
1477
  p_app_context: options.appContext || null
1473
1478
  });
1474
1479
  if (error) {
1475
- console.error("BugBear: Failed to add finding", error);
1480
+ console.error("BugBear: Failed to add finding", formatPgError(error));
1476
1481
  return { success: false, error: error.message };
1477
1482
  }
1478
1483
  const finding = this.transformFinding(data);
@@ -1490,7 +1495,7 @@ var BugBearClient = class {
1490
1495
  try {
1491
1496
  const { data, error } = await this.supabase.from("qa_findings").select("*").eq("session_id", sessionId).order("created_at", { ascending: true }).limit(100);
1492
1497
  if (error) {
1493
- console.error("BugBear: Failed to fetch findings", error);
1498
+ console.error("BugBear: Failed to fetch findings", formatPgError(error));
1494
1499
  return [];
1495
1500
  }
1496
1501
  return (data || []).map((f) => this.transformFinding(f));
@@ -1508,7 +1513,7 @@ var BugBearClient = class {
1508
1513
  p_finding_id: findingId
1509
1514
  });
1510
1515
  if (error) {
1511
- console.error("BugBear: Failed to convert finding", error);
1516
+ console.error("BugBear: Failed to convert finding", formatPgError(error));
1512
1517
  return { success: false, error: error.message };
1513
1518
  }
1514
1519
  return { success: true, bugId: data };
@@ -1529,7 +1534,7 @@ var BugBearClient = class {
1529
1534
  dismissed_at: (/* @__PURE__ */ new Date()).toISOString()
1530
1535
  }).eq("id", findingId);
1531
1536
  if (error) {
1532
- console.error("BugBear: Failed to dismiss finding", error);
1537
+ console.error("BugBear: Failed to dismiss finding", formatPgError(error));
1533
1538
  return { success: false, error: error.message };
1534
1539
  }
1535
1540
  return { success: true };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbearai/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Core utilities and types for BugBear QA platform",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",