@mushi-mushi/web 1.7.5 → 1.7.6

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
@@ -3142,6 +3142,15 @@ var optedIn = false;
3142
3142
  var tierCache = null;
3143
3143
  var tierCacheTime = 0;
3144
3144
  var TIER_CACHE_TTL = 5 * 60 * 1e3;
3145
+ var rewardsApiBackoffUntil = 0;
3146
+ var REWARDS_4XX_BACKOFF_MS = 15 * 60 * 1e3;
3147
+ function isRewardsApiBackedOff() {
3148
+ return Date.now() < rewardsApiBackoffUntil;
3149
+ }
3150
+ function noteRewardsApiFailure(code) {
3151
+ if (!code?.startsWith("HTTP_4")) return;
3152
+ rewardsApiBackoffUntil = Date.now() + REWARDS_4XX_BACKOFF_MS;
3153
+ }
3145
3154
  var seenRoutes = /* @__PURE__ */ new Set();
3146
3155
  function getConsentKey(projectId) {
3147
3156
  return `mushi_rewards_consent_${projectId}`;
@@ -3246,14 +3255,22 @@ async function flush(ctx) {
3246
3255
  } catch {
3247
3256
  }
3248
3257
  }
3258
+ if (isRewardsApiBackedOff()) return;
3249
3259
  const batch = pendingEvents.splice(0, 100);
3250
3260
  try {
3251
- await ctx.client.submitActivity(currentUserId, batch, {
3261
+ const result = await ctx.client.submitActivity(currentUserId, batch, {
3252
3262
  userTraits: currentUserTraits ?? void 0,
3253
3263
  reporterTokenHash: reporterTokenHash ?? void 0,
3254
3264
  optedIn: true,
3255
3265
  hostJwt: hostJwt ?? void 0
3256
3266
  });
3267
+ if (!result.ok) {
3268
+ noteRewardsApiFailure(result.error?.code);
3269
+ const permanent = result.error?.code?.startsWith("HTTP_4");
3270
+ if (!permanent) {
3271
+ pendingEvents.unshift(...batch.slice(0, 50));
3272
+ }
3273
+ }
3257
3274
  } catch {
3258
3275
  pendingEvents.unshift(...batch.slice(0, 50));
3259
3276
  }
@@ -3264,13 +3281,14 @@ async function getTier(userId) {
3264
3281
  return fetchAndCacheTier(userId);
3265
3282
  }
3266
3283
  async function fetchAndCacheTier(userId) {
3267
- if (!apiClient) return null;
3284
+ if (!apiClient || isRewardsApiBackedOff()) return null;
3268
3285
  const res = await apiClient.getMyTier(userId);
3269
3286
  if (res.ok && res.data) {
3270
3287
  tierCache = res.data;
3271
3288
  tierCacheTime = Date.now();
3272
3289
  return tierCache;
3273
3290
  }
3291
+ noteRewardsApiFailure(res.error?.code);
3274
3292
  return null;
3275
3293
  }
3276
3294
  var routeObserver = null;
@@ -4763,7 +4781,7 @@ function createProactiveManager(config = {}) {
4763
4781
 
4764
4782
  // src/version.ts
4765
4783
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
4766
- var MUSHI_SDK_VERSION = "1.7.5" ;
4784
+ var MUSHI_SDK_VERSION = "1.7.6" ;
4767
4785
 
4768
4786
  // src/mushi.ts
4769
4787
  var instance = null;
@@ -4944,15 +4962,26 @@ function createInstance(config) {
4944
4962
  });
4945
4963
  let detachAutoBreadcrumbs = null;
4946
4964
  detachAutoBreadcrumbs = installAutoBreadcrumbs(breadcrumbs);
4965
+ async function autoCaptureScreenshot(when) {
4966
+ const mode = activeConfig.capture?.screenshot;
4967
+ if (!screenshotCap || mode === "off" || pendingScreenshot) return;
4968
+ if (when === "open" && mode !== "auto") return;
4969
+ if (when === "submit" && mode !== "on-report" && mode !== "auto") return;
4970
+ log.debug("Auto-capturing screenshot", { when, mode });
4971
+ pendingScreenshot = await screenshotCap.take();
4972
+ widget.setScreenshotAttached(pendingScreenshot !== null);
4973
+ }
4947
4974
  widget = new MushiWidget(bootstrapConfig.widget, {
4948
4975
  onSubmit: async ({ category, description, intent }) => {
4949
4976
  log.info("Report submitted", { category, intent });
4950
4977
  proactiveManager?.recordSubmission();
4978
+ await autoCaptureScreenshot("submit");
4951
4979
  const outcome = await submitReport(category, description, intent);
4952
4980
  return outcome ?? { reportId: null, queuedOffline: true };
4953
4981
  },
4954
4982
  onOpen: () => {
4955
4983
  log.debug("Widget opened");
4984
+ void autoCaptureScreenshot("open");
4956
4985
  emit("widget:opened");
4957
4986
  },
4958
4987
  onClose: () => {