@mushi-mushi/web 1.21.0 → 1.22.0

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
@@ -2553,7 +2553,7 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
2553
2553
 
2554
2554
  // src/version.ts
2555
2555
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
2556
- var MUSHI_SDK_VERSION = "1.21.0" ;
2556
+ var MUSHI_SDK_VERSION = "1.22.0" ;
2557
2557
  var CATEGORY_ICONS = {
2558
2558
  bug: "\u26A0\uFE0F",
2559
2559
  slow: "\u{1F40C}",
@@ -3669,6 +3669,8 @@ var MushiWidget = class _MushiWidget {
3669
3669
  return this.host.isConnected;
3670
3670
  }
3671
3671
  updateConfig(config = {}) {
3672
+ const prevTrigger = this.config.trigger;
3673
+ const prevBannerConfig = JSON.stringify(this.config.bannerConfig ?? null);
3672
3674
  this.config = {
3673
3675
  ...this.config,
3674
3676
  ...config.position ? { position: config.position } : {},
@@ -3706,6 +3708,11 @@ var MushiWidget = class _MushiWidget {
3706
3708
  ...config.categories !== void 0 ? { categories: config.categories } : {}
3707
3709
  };
3708
3710
  this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
3711
+ const triggerBecameBanner = this.config.trigger === "banner" && prevTrigger !== "banner";
3712
+ const bannerConfigChanged = JSON.stringify(this.config.bannerConfig ?? null) !== prevBannerConfig;
3713
+ if (triggerBecameBanner || bannerConfigChanged) {
3714
+ this.bannerDismissed = false;
3715
+ }
3709
3716
  if (this.host.isConnected) this.syncHostChromeState();
3710
3717
  this.syncAttachedLaunchers();
3711
3718
  this.syncSmartHide();
@@ -5576,7 +5583,10 @@ var routeObserver = null;
5576
5583
  var clickHandler = null;
5577
5584
  var origPushState = null;
5578
5585
  var lastRoute = "";
5586
+ var listenersInstalled = false;
5579
5587
  function installActivityListeners(projectId) {
5588
+ if (listenersInstalled) return;
5589
+ listenersInstalled = true;
5580
5590
  const emitRoute = () => {
5581
5591
  const route = location.pathname;
5582
5592
  if (route === lastRoute) return;
@@ -7411,6 +7421,9 @@ var Mushi = class {
7411
7421
  core.createLogger({ scope: "mushi", level: "warn", format: "pretty" }).warn("Already initialized \u2014 call destroy() first to reinitialize");
7412
7422
  return instance;
7413
7423
  }
7424
+ if (typeof document === "undefined" || typeof window === "undefined") {
7425
+ return createNoopInstance();
7426
+ }
7414
7427
  const resolved = { ...core.resolveEnvConfig(), ...config };
7415
7428
  if (!resolved.projectId) {
7416
7429
  throw new Error("[mushi] projectId is required \u2014 set NEXT_PUBLIC_MUSHI_PROJECT_ID / VITE_MUSHI_PROJECT_ID / MUSHI_PROJECT_ID or pass it explicitly");
@@ -7447,6 +7460,9 @@ function createInstance(config) {
7447
7460
  projectId: bootstrapConfig.projectId,
7448
7461
  apiKey: bootstrapConfig.apiKey,
7449
7462
  ...bootstrapConfig.apiEndpoint ? { apiEndpoint: bootstrapConfig.apiEndpoint } : {},
7463
+ ...typeof bootstrapConfig.timeout === "number" ? { timeout: bootstrapConfig.timeout } : {},
7464
+ ...typeof bootstrapConfig.maxRetries === "number" ? { maxRetries: bootstrapConfig.maxRetries } : {},
7465
+ ...bootstrapConfig.circuitBreaker ? { circuitBreaker: bootstrapConfig.circuitBreaker } : {},
7450
7466
  getUserToken: () => userToken,
7451
7467
  sdkPackage: MUSHI_SDK_PACKAGE,
7452
7468
  sdkVersion: MUSHI_SDK_VERSION
@@ -7641,6 +7657,7 @@ function createInstance(config) {
7641
7657
  let reporterPollTimer = null;
7642
7658
  let reporterPollVisibleHandler = null;
7643
7659
  let userInfo = null;
7660
+ let lastIdentifySig = null;
7644
7661
  const customMetadata = {};
7645
7662
  const stickyTags = {};
7646
7663
  const breadcrumbs = core.createBreadcrumbBuffer({ max: 50 });
@@ -7713,7 +7730,7 @@ function createInstance(config) {
7713
7730
  screenshotCaptureInFlight = true;
7714
7731
  try {
7715
7732
  const result = await provider();
7716
- return result ?? null;
7733
+ if (result) return result;
7717
7734
  } catch (err) {
7718
7735
  log.warn("screenshotProvider threw, falling back to built-in capturer", {
7719
7736
  error: err instanceof Error ? err.message : String(err)
@@ -7982,6 +7999,10 @@ function createInstance(config) {
7982
7999
  proactiveTriggers = setupProactiveTriggers(
7983
8000
  {
7984
8001
  onTrigger: (type, context) => {
8002
+ if (typeof navigator !== "undefined" && !navigator.onLine) {
8003
+ log.debug("Proactive trigger suppressed: offline", { type });
8004
+ return;
8005
+ }
7985
8006
  if (!proactiveManager.shouldShow(type)) {
7986
8007
  log.debug("Proactive trigger suppressed by fatigue prevention", { type });
7987
8008
  return;
@@ -8496,6 +8517,9 @@ function createInstance(config) {
8496
8517
  });
8497
8518
  },
8498
8519
  identify(userId, traits) {
8520
+ const sig = `${userId}::${traits ? JSON.stringify(traits) : ""}`;
8521
+ if (sig === lastIdentifySig) return;
8522
+ lastIdentifySig = sig;
8499
8523
  userInfo = { id: userId, ...traits?.email ? { email: traits.email } : {}, ...traits?.name ? { name: traits.name } : {} };
8500
8524
  widget.setIdentifiedUser(
8501
8525
  userInfo.name || userInfo.email ? { name: userInfo.name, email: userInfo.email } : null
@@ -8524,6 +8548,10 @@ function createInstance(config) {
8524
8548
  if (userToken) {
8525
8549
  const claims = core.parseIdentityToken(userToken);
8526
8550
  if (claims?.sub) {
8551
+ if (userInfo?.id === claims.sub) {
8552
+ breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken() refreshed" });
8553
+ return;
8554
+ }
8527
8555
  userInfo = {
8528
8556
  id: claims.sub,
8529
8557
  ...claims.email ? { email: claims.email } : {},
@@ -8540,6 +8568,7 @@ function createInstance(config) {
8540
8568
  breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken()" });
8541
8569
  } else {
8542
8570
  userInfo = null;
8571
+ lastIdentifySig = null;
8543
8572
  widget.setIdentifiedUser(null);
8544
8573
  breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken(null)" });
8545
8574
  }
@@ -8667,7 +8696,55 @@ function createInstance(config) {
8667
8696
  }
8668
8697
  }
8669
8698
  }
8670
- return sdk;
8699
+ const PUBLIC_API_FALLBACKS = {
8700
+ on: () => {
8701
+ },
8702
+ // returns a no-op unsubscribe
8703
+ isOpen: false,
8704
+ getBreadcrumbs: [],
8705
+ captureEvent: null,
8706
+ captureException: null,
8707
+ getReputation: null,
8708
+ getTier: null,
8709
+ listMyReports: [],
8710
+ listMyComments: [],
8711
+ getHallOfFame: [],
8712
+ replyToReport: null,
8713
+ submitFeedbackSignal: null,
8714
+ reopenReport: null
8715
+ };
8716
+ const noteSdkError = (method, err) => {
8717
+ const message = err instanceof Error ? err.message : String(err);
8718
+ log.debug(`Mushi.${method}() failed (swallowed)`, { error: message });
8719
+ try {
8720
+ breadcrumbs.add({ category: "custom", level: "warning", message: `mushi.${method}() threw`, data: { error: message } });
8721
+ } catch {
8722
+ }
8723
+ };
8724
+ const isolatePublicApi = (raw) => new Proxy(raw, {
8725
+ get(target, prop, receiver) {
8726
+ const value = Reflect.get(target, prop, receiver);
8727
+ if (typeof value !== "function") return value;
8728
+ const method = String(prop);
8729
+ const resolveFallback = () => method === "diagnose" ? diagnoseWithoutInstance() : method in PUBLIC_API_FALLBACKS ? PUBLIC_API_FALLBACKS[method] : void 0;
8730
+ return (...args) => {
8731
+ try {
8732
+ const result = value.apply(target, args);
8733
+ if (result && typeof result.then === "function") {
8734
+ return result.catch((err) => {
8735
+ noteSdkError(method, err);
8736
+ return resolveFallback();
8737
+ });
8738
+ }
8739
+ return result;
8740
+ } catch (err) {
8741
+ noteSdkError(method, err);
8742
+ return resolveFallback();
8743
+ }
8744
+ };
8745
+ }
8746
+ });
8747
+ return isolatePublicApi(sdk);
8671
8748
  }
8672
8749
  function mergeRuntimeConfig(config, runtime) {
8673
8750
  const nativeTrigger = runtime.native?.triggerMode;