@mushi-mushi/web 1.21.1 → 1.22.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.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.1" ;
2556
+ var MUSHI_SDK_VERSION = "1.22.1" ;
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();
@@ -7414,6 +7421,9 @@ var Mushi = class {
7414
7421
  core.createLogger({ scope: "mushi", level: "warn", format: "pretty" }).warn("Already initialized \u2014 call destroy() first to reinitialize");
7415
7422
  return instance;
7416
7423
  }
7424
+ if (typeof document === "undefined" || typeof window === "undefined") {
7425
+ return createNoopInstance();
7426
+ }
7417
7427
  const resolved = { ...core.resolveEnvConfig(), ...config };
7418
7428
  if (!resolved.projectId) {
7419
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");
@@ -7450,6 +7460,9 @@ function createInstance(config) {
7450
7460
  projectId: bootstrapConfig.projectId,
7451
7461
  apiKey: bootstrapConfig.apiKey,
7452
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 } : {},
7453
7466
  getUserToken: () => userToken,
7454
7467
  sdkPackage: MUSHI_SDK_PACKAGE,
7455
7468
  sdkVersion: MUSHI_SDK_VERSION
@@ -7644,6 +7657,7 @@ function createInstance(config) {
7644
7657
  let reporterPollTimer = null;
7645
7658
  let reporterPollVisibleHandler = null;
7646
7659
  let userInfo = null;
7660
+ let lastIdentifySig = null;
7647
7661
  const customMetadata = {};
7648
7662
  const stickyTags = {};
7649
7663
  const breadcrumbs = core.createBreadcrumbBuffer({ max: 50 });
@@ -7716,7 +7730,7 @@ function createInstance(config) {
7716
7730
  screenshotCaptureInFlight = true;
7717
7731
  try {
7718
7732
  const result = await provider();
7719
- return result ?? null;
7733
+ if (result) return result;
7720
7734
  } catch (err) {
7721
7735
  log.warn("screenshotProvider threw, falling back to built-in capturer", {
7722
7736
  error: err instanceof Error ? err.message : String(err)
@@ -7985,6 +7999,10 @@ function createInstance(config) {
7985
7999
  proactiveTriggers = setupProactiveTriggers(
7986
8000
  {
7987
8001
  onTrigger: (type, context) => {
8002
+ if (typeof navigator !== "undefined" && !navigator.onLine) {
8003
+ log.debug("Proactive trigger suppressed: offline", { type });
8004
+ return;
8005
+ }
7988
8006
  if (!proactiveManager.shouldShow(type)) {
7989
8007
  log.debug("Proactive trigger suppressed by fatigue prevention", { type });
7990
8008
  return;
@@ -8499,6 +8517,9 @@ function createInstance(config) {
8499
8517
  });
8500
8518
  },
8501
8519
  identify(userId, traits) {
8520
+ const sig = `${userId}::${traits ? JSON.stringify(traits) : ""}`;
8521
+ if (sig === lastIdentifySig) return;
8522
+ lastIdentifySig = sig;
8502
8523
  userInfo = { id: userId, ...traits?.email ? { email: traits.email } : {}, ...traits?.name ? { name: traits.name } : {} };
8503
8524
  widget.setIdentifiedUser(
8504
8525
  userInfo.name || userInfo.email ? { name: userInfo.name, email: userInfo.email } : null
@@ -8527,6 +8548,10 @@ function createInstance(config) {
8527
8548
  if (userToken) {
8528
8549
  const claims = core.parseIdentityToken(userToken);
8529
8550
  if (claims?.sub) {
8551
+ if (userInfo?.id === claims.sub) {
8552
+ breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken() refreshed" });
8553
+ return;
8554
+ }
8530
8555
  userInfo = {
8531
8556
  id: claims.sub,
8532
8557
  ...claims.email ? { email: claims.email } : {},
@@ -8543,6 +8568,7 @@ function createInstance(config) {
8543
8568
  breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken()" });
8544
8569
  } else {
8545
8570
  userInfo = null;
8571
+ lastIdentifySig = null;
8546
8572
  widget.setIdentifiedUser(null);
8547
8573
  breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken(null)" });
8548
8574
  }
@@ -8670,7 +8696,55 @@ function createInstance(config) {
8670
8696
  }
8671
8697
  }
8672
8698
  }
8673
- 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);
8674
8748
  }
8675
8749
  function mergeRuntimeConfig(config, runtime) {
8676
8750
  const nativeTrigger = runtime.native?.triggerMode;