bugstash 0.1.5 → 0.1.7

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.cjs CHANGED
@@ -532,13 +532,30 @@ async function captureScreenshot() {
532
532
  }
533
533
 
534
534
  // src/api.ts
535
- var endpoint = "http://localhost:4000";
535
+ var PRIMARY_ENDPOINT = "https://bugstash-backend.azurewebsites.net";
536
+ var FALLBACK_ENDPOINT = "https://api.bugstash.com";
537
+ var endpoint = PRIMARY_ENDPOINT;
538
+ var _usingFallback = false;
536
539
  function setEndpoint(url) {
537
540
  endpoint = url.replace(/\/$/, "");
541
+ _usingFallback = false;
538
542
  }
539
543
  function getEndpoint() {
540
544
  return endpoint;
541
545
  }
546
+ async function fetchWithFallback(url, init) {
547
+ try {
548
+ const res = await fetch(url, init);
549
+ return res;
550
+ } catch (err) {
551
+ if (_usingFallback) throw err;
552
+ _usingFallback = true;
553
+ const previousEndpoint = endpoint;
554
+ endpoint = FALLBACK_ENDPOINT;
555
+ const fallbackUrl = url.replace(previousEndpoint, FALLBACK_ENDPOINT);
556
+ return fetch(fallbackUrl, init);
557
+ }
558
+ }
542
559
  var STORAGE_KEY = "bugstash_auth";
543
560
  function getStoredAuth() {
544
561
  try {
@@ -570,7 +587,7 @@ async function authHeaders() {
570
587
  if (!auth) return { "Content-Type": "application/json" };
571
588
  if (auth.tokens.expiresAt < Date.now() + 6e4) {
572
589
  try {
573
- const res = await fetch(`${endpoint}/api/auth/refresh`, {
590
+ const res = await fetchWithFallback(`${endpoint}/api/auth/refresh`, {
574
591
  method: "POST",
575
592
  headers: { "Content-Type": "application/json" },
576
593
  body: JSON.stringify({ refreshToken: auth.tokens.refreshToken })
@@ -592,7 +609,7 @@ async function authHeaders() {
592
609
  }
593
610
  async function login(email, password, projectId2) {
594
611
  try {
595
- const res = await fetch(`${endpoint}/api/auth/login`, {
612
+ const res = await fetchWithFallback(`${endpoint}/api/auth/login`, {
596
613
  method: "POST",
597
614
  headers: { "Content-Type": "application/json" },
598
615
  body: JSON.stringify({ email, password, projectId: projectId2 })
@@ -612,7 +629,7 @@ async function logout() {
612
629
  async function submitReport(report) {
613
630
  try {
614
631
  const headers = await authHeaders();
615
- const res = await fetch(`${endpoint}/api/reports`, {
632
+ const res = await fetchWithFallback(`${endpoint}/api/reports`, {
616
633
  method: "POST",
617
634
  headers,
618
635
  body: JSON.stringify(report)
@@ -625,7 +642,7 @@ async function submitReport(report) {
625
642
  async function fetchPagePins(projectId2, pathname) {
626
643
  try {
627
644
  const headers = await authHeaders();
628
- const res = await fetch(`${endpoint}/api/pins/by-page?projectId=${projectId2}&pathname=${encodeURIComponent(pathname)}`, { headers });
645
+ const res = await fetchWithFallback(`${endpoint}/api/pins/by-page?projectId=${projectId2}&pathname=${encodeURIComponent(pathname)}`, { headers });
629
646
  return await res.json();
630
647
  } catch {
631
648
  return { success: false, error: "Network error" };
@@ -634,7 +651,7 @@ async function fetchPagePins(projectId2, pathname) {
634
651
  async function createPin(pin) {
635
652
  try {
636
653
  const headers = await authHeaders();
637
- const res = await fetch(`${endpoint}/api/pins`, {
654
+ const res = await fetchWithFallback(`${endpoint}/api/pins`, {
638
655
  method: "POST",
639
656
  headers,
640
657
  body: JSON.stringify(pin)
@@ -647,7 +664,7 @@ async function createPin(pin) {
647
664
  async function updatePin(pinId, updates) {
648
665
  try {
649
666
  const headers = await authHeaders();
650
- const res = await fetch(`${endpoint}/api/pins/${pinId}`, {
667
+ const res = await fetchWithFallback(`${endpoint}/api/pins/${pinId}`, {
651
668
  method: "PUT",
652
669
  headers,
653
670
  body: JSON.stringify(updates)
@@ -660,7 +677,7 @@ async function updatePin(pinId, updates) {
660
677
  async function deletePin(pinId) {
661
678
  try {
662
679
  const headers = await authHeaders();
663
- const res = await fetch(`${endpoint}/api/pins/${pinId}`, {
680
+ const res = await fetchWithFallback(`${endpoint}/api/pins/${pinId}`, {
664
681
  method: "DELETE",
665
682
  headers
666
683
  });
@@ -672,7 +689,7 @@ async function deletePin(pinId) {
672
689
  async function fetchComments(pinId) {
673
690
  try {
674
691
  const headers = await authHeaders();
675
- const res = await fetch(`${endpoint}/api/pins/${pinId}/comments`, { headers });
692
+ const res = await fetchWithFallback(`${endpoint}/api/pins/${pinId}/comments`, { headers });
676
693
  return await res.json();
677
694
  } catch {
678
695
  return { success: false, error: "Network error" };
@@ -681,7 +698,7 @@ async function fetchComments(pinId) {
681
698
  async function createComment(pinId, body, mentions = []) {
682
699
  try {
683
700
  const headers = await authHeaders();
684
- const res = await fetch(`${endpoint}/api/pins/${pinId}/comments`, {
701
+ const res = await fetchWithFallback(`${endpoint}/api/pins/${pinId}/comments`, {
685
702
  method: "POST",
686
703
  headers,
687
704
  body: JSON.stringify({ body, mentions })
@@ -694,7 +711,7 @@ async function createComment(pinId, body, mentions = []) {
694
711
  async function fetchProjectMembers(projectId2) {
695
712
  try {
696
713
  const headers = await authHeaders();
697
- const res = await fetch(`${endpoint}/api/members/for-project/${projectId2}`, { headers });
714
+ const res = await fetchWithFallback(`${endpoint}/api/members/for-project/${projectId2}`, { headers });
698
715
  return await res.json();
699
716
  } catch {
700
717
  return { success: false, error: "Network error" };
@@ -4512,7 +4529,7 @@ function bindTabContent() {
4512
4529
  if (container2) annotator = setupAnnotation(container2, screenshotData);
4513
4530
  } else {
4514
4531
  if (titleEl) titleEl.textContent = "Screenshot unavailable";
4515
- if (subEl) subEl.textContent = "Install html2canvas package for screenshot support";
4532
+ if (subEl) subEl.textContent = "Could not capture screenshot on this page";
4516
4533
  }
4517
4534
  });
4518
4535
  modal.querySelector("[data-bs-form]")?.addEventListener("submit", async (e) => {