@githumbi/grabby 0.1.2 → 0.2.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.
@@ -2872,13 +2872,14 @@ function createCoachMark() {
2872
2872
  // src/core/sync/outbox.ts
2873
2873
  var STORE_KEY = "grabby:v1:outbox";
2874
2874
  var BACKOFF = [2e3, 1e4, 3e4, 12e4, 3e5, 6e5];
2875
- var MAX_ATTEMPTS = 20;
2875
+ var GIVE_UP_AFTER_MS = 14 * 24 * 60 * 60 * 1e3;
2876
2876
  var KEEPALIVE_MAX = 6e4;
2877
2877
  function loadJobs() {
2878
2878
  try {
2879
2879
  const raw = localStorage.getItem(STORE_KEY);
2880
2880
  const jobs = raw ? JSON.parse(raw) : [];
2881
- return Array.isArray(jobs) ? jobs.filter((j) => typeof j.id === "string" && (j.kind === "comment" || j.kind === "shot")) : [];
2881
+ if (!Array.isArray(jobs)) return [];
2882
+ return jobs.filter((j) => typeof j.id === "string" && (j.kind === "comment" || j.kind === "shot")).map((j) => typeof j.created === "number" ? j : { ...j, created: Date.now() });
2882
2883
  } catch {
2883
2884
  return [];
2884
2885
  }
@@ -2906,7 +2907,7 @@ function createOutbox(deps) {
2906
2907
  }
2907
2908
  function add(id, kind) {
2908
2909
  if (jobs.some((j) => j.id === id && j.kind === kind)) return;
2909
- jobs.push({ id, kind, attempts: 0, next: 0 });
2910
+ jobs.push({ id, kind, attempts: 0, next: 0, created: Date.now() });
2910
2911
  save();
2911
2912
  schedule(0);
2912
2913
  }
@@ -2975,14 +2976,14 @@ function createOutbox(deps) {
2975
2976
  } catch {
2976
2977
  outcome = "retry";
2977
2978
  }
2978
- if (outcome === "retry" && job.attempts + 1 < MAX_ATTEMPTS) {
2979
+ if (outcome === "retry" && Date.now() - job.created < GIVE_UP_AFTER_MS) {
2979
2980
  job.attempts += 1;
2980
2981
  job.next = Date.now() + BACKOFF[Math.min(job.attempts - 1, BACKOFF.length - 1)];
2981
2982
  if (job.kind === "comment") deps.onState(job.id, "pending");
2982
2983
  } else {
2983
2984
  jobs = jobs.filter((j) => j !== job);
2984
2985
  if (job.kind === "comment" && outcome === "done") deps.onState(job.id, "sent");
2985
- if (job.kind === "comment" && outcome === "retry") deps.onState(job.id, "failed", "gave up after repeated failures");
2986
+ if (job.kind === "comment" && outcome === "retry") deps.onState(job.id, "failed", "could not reach the feedback server for 14 days");
2986
2987
  }
2987
2988
  save();
2988
2989
  }