@mushi-mushi/web 1.28.0 → 1.29.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
@@ -224,7 +224,7 @@ var en = {
224
224
  changelog: {
225
225
  whatsNew: "What's new in {version}"
226
226
  },
227
- poweredBy: "Powered by Mushi v{version}"
227
+ poweredBy: "Bug reports by Mushi"
228
228
  }
229
229
  };
230
230
 
@@ -414,7 +414,7 @@ var ja = {
414
414
  changelog: {
415
415
  whatsNew: "{version} \u306E\u65B0\u6A5F\u80FD"
416
416
  },
417
- poweredBy: "Mushi v{version}"
417
+ poweredBy: "\u30D0\u30B0\u5831\u544A\u306F Mushi \u3067"
418
418
  }
419
419
  };
420
420
 
@@ -604,7 +604,7 @@ var th = {
604
604
  changelog: {
605
605
  whatsNew: "\u0E21\u0E35\u0E2D\u0E30\u0E44\u0E23\u0E43\u0E2B\u0E21\u0E48\u0E43\u0E19 {version}"
606
606
  },
607
- poweredBy: "Powered by Mushi v{version}"
607
+ poweredBy: "\u0E23\u0E32\u0E22\u0E07\u0E32\u0E19\u0E1A\u0E31\u0E4A\u0E01\u0E42\u0E14\u0E22 Mushi"
608
608
  }
609
609
  };
610
610
 
@@ -794,7 +794,7 @@ var es = {
794
794
  changelog: {
795
795
  whatsNew: "Novedades de {version}"
796
796
  },
797
- poweredBy: "Con tecnolog\xEDa de Mushi v{version}"
797
+ poweredBy: "Reportes de errores con Mushi"
798
798
  }
799
799
  };
800
800
 
@@ -1865,6 +1865,19 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
1865
1865
  text-align: center;
1866
1866
  text-transform: uppercase;
1867
1867
  }
1868
+ .mushi-brand-link {
1869
+ color: inherit;
1870
+ text-decoration: none;
1871
+ text-underline-offset: 3px;
1872
+ }
1873
+ .mushi-brand-link:hover { color: ${inkMuted}; text-decoration: underline; }
1874
+ .mushi-brand-link:focus-visible {
1875
+ outline: 2px solid ${widgetAccent};
1876
+ outline-offset: 2px;
1877
+ border-radius: 2px;
1878
+ color: ${widgetAccent};
1879
+ text-decoration: underline;
1880
+ }
1868
1881
 
1869
1882
  .mushi-step-indicator {
1870
1883
  display: flex;
@@ -2715,7 +2728,7 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
2715
2728
 
2716
2729
  // src/version.ts
2717
2730
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
2718
- var MUSHI_SDK_VERSION = "1.28.0" ;
2731
+ var MUSHI_SDK_VERSION = "1.29.0" ;
2719
2732
  var ASSISTANT_SESSION_STORAGE_KEY = "mushi-assistant-session-v1";
2720
2733
  function loadAssistantSession() {
2721
2734
  try {
@@ -2873,6 +2886,12 @@ function formatRelativeTime(iso) {
2873
2886
  function pad2(n) {
2874
2887
  return n < 10 ? `0${n}` : String(n);
2875
2888
  }
2889
+ var BRAND_FOOTER_URL = "https://kensaur.us/mushi-mushi/";
2890
+ var BRAND_FOOTER_UTM = "utm_source=widget&utm_medium=powered-by";
2891
+ function buildBrandFooterHref(ref) {
2892
+ const base = `${BRAND_FOOTER_URL}?${BRAND_FOOTER_UTM}`;
2893
+ return ref && /^[0-9a-f]{6,64}$/.test(ref) ? `${base}&ref=${ref}` : base;
2894
+ }
2876
2895
  var TOTAL_STEPS = 3;
2877
2896
  var STEP_NUMBER = {
2878
2897
  category: 1,
@@ -3019,8 +3038,9 @@ function renderOutdatedBanner(ctx) {
3019
3038
  `;
3020
3039
  }
3021
3040
  function renderBrandFooter(ctx) {
3022
- if (ctx.config.brandFooter === false) return "";
3023
- return `<div class="mushi-brand-footer">${escapeHtml(ctx.locale.flows.poweredBy.replace("{version}", ctx.sdkVersion))}</div>`;
3041
+ if (ctx.config.brandFooter !== true) return "";
3042
+ const href = buildBrandFooterHref(ctx.brandRef);
3043
+ return `<div class="mushi-brand-footer"><a class="mushi-brand-link" href="${escapeHtml(href)}" target="_blank" rel="noopener noreferrer" data-action="brand-footer">${escapeHtml(ctx.locale.flows.poweredBy)}<span aria-hidden="true"> \u2197</span></a></div>`;
3024
3044
  }
3025
3045
  function renderHeader(ctx, opts) {
3026
3046
  const t = ctx.locale;
@@ -3857,6 +3877,9 @@ var MushiWidget = class _MushiWidget {
3857
3877
  nudgeEl = null;
3858
3878
  nudgeTimer = null;
3859
3879
  sdkFreshness = null;
3880
+ /** Brand-footer ref (SDK sets it once hashed) + once-per-instance impression latch. */
3881
+ brandRef = null;
3882
+ brandImpressionSent = false;
3860
3883
  reporterReports = [];
3861
3884
  featureBoard = [];
3862
3885
  reporterComments = [];
@@ -4365,6 +4388,11 @@ var MushiWidget = class _MushiWidget {
4365
4388
  this.sdkFreshness = info;
4366
4389
  if (this.isOpen) this.render();
4367
4390
  }
4391
+ setBrandRef(ref) {
4392
+ if (this.brandRef === ref) return;
4393
+ this.brandRef = ref;
4394
+ if (this.isOpen) this.render();
4395
+ }
4368
4396
  setRewardsState(state) {
4369
4397
  this.rewardsState = state;
4370
4398
  if (this.isOpen) this.render();
@@ -4914,6 +4942,10 @@ var MushiWidget = class _MushiWidget {
4914
4942
  panel.innerHTML = `${renderOutdatedBanner(ctx)}${renderStep(ctx)}${renderBrandFooter(ctx)}`;
4915
4943
  this.shadow.appendChild(panel);
4916
4944
  this.attachHandlers(panel);
4945
+ if (!this.brandImpressionSent && this.config.brandFooter === true) {
4946
+ this.brandImpressionSent = true;
4947
+ this.callbacks.onBrandFooterImpression?.();
4948
+ }
4917
4949
  this.trapFocus(panel);
4918
4950
  this.restoreFormDrafts(panel);
4919
4951
  this.attachViewportHandlers(panel);
@@ -5250,13 +5282,17 @@ var MushiWidget = class _MushiWidget {
5250
5282
  assistantError: this.assistantError,
5251
5283
  showAllCategories: this.showAllCategories,
5252
5284
  showMoreNav: this.showMoreNav,
5253
- pageFaviconHref: core.readPageFaviconHref()
5285
+ pageFaviconHref: core.readPageFaviconHref(),
5286
+ brandRef: this.brandRef
5254
5287
  };
5255
5288
  }
5256
5289
  attachHandlers(panel) {
5257
5290
  const t = this.locale;
5258
5291
  bindFaviconFallbacks(panel);
5259
5292
  panel.querySelector('[data-action="close"]')?.addEventListener("click", () => this.close());
5293
+ panel.querySelector('[data-action="brand-footer"]')?.addEventListener("click", () => {
5294
+ this.callbacks.onBrandFooterClick?.();
5295
+ });
5260
5296
  panel.querySelector('[data-action="back"]')?.addEventListener("click", () => {
5261
5297
  if (this.step === "intent") {
5262
5298
  this.step = "category";
@@ -5842,7 +5878,8 @@ function mergeRuntimeCapture(host, runtime) {
5842
5878
  }
5843
5879
  return merged;
5844
5880
  }
5845
- function mergeRuntimeConfig(config, runtime) {
5881
+ var HOST_WINS_WIDGET_KEYS = ["brandFooter"];
5882
+ function mergeRuntimeConfig(config, runtime, host = config) {
5846
5883
  const nativeTrigger = runtime.native?.triggerMode;
5847
5884
  const runtimeLauncher = runtime.widget?.launcher;
5848
5885
  const hostTrigger = config.widget?.trigger;
@@ -5871,7 +5908,11 @@ function mergeRuntimeConfig(config, runtime) {
5871
5908
  if (runtime.widget) {
5872
5909
  for (const [key, value] of Object.entries(runtime.widget)) {
5873
5910
  if (key === "trigger" || key === "launcher") continue;
5874
- if (value !== void 0 && value !== null) definedRuntimeWidget[key] = value;
5911
+ if (value === void 0 || value === null) continue;
5912
+ if (HOST_WINS_WIDGET_KEYS.includes(key) && host.widget?.[key] !== void 0) {
5913
+ continue;
5914
+ }
5915
+ definedRuntimeWidget[key] = value;
5875
5916
  }
5876
5917
  }
5877
5918
  return {
@@ -7539,8 +7580,6 @@ function createDiscoveryCapture(opts) {
7539
7580
  }
7540
7581
  };
7541
7582
  }
7542
-
7543
- // src/capture/replay.ts
7544
7583
  var DEFAULT_MAX_MS = 3e4;
7545
7584
  var MAX_EVENTS = 400;
7546
7585
  var RRWEB_META = 4;
@@ -7598,15 +7637,33 @@ function createLiteReplay(maxMs) {
7598
7637
  }
7599
7638
  };
7600
7639
  }
7640
+ var DEFAULT_REDACT_SELECTORS2 = ['input[type="password"]', "[data-mushi-redact]"];
7601
7641
  var rrwebModule = null;
7602
- async function loadRrweb() {
7642
+ var warnedMissingRrweb = false;
7643
+ function asRrweb(mod) {
7644
+ if (!mod || typeof mod !== "object") return null;
7645
+ const direct = mod;
7646
+ if (typeof direct.record === "function") return direct;
7647
+ if (direct.default && typeof direct.default.record === "function") return direct.default;
7648
+ return null;
7649
+ }
7650
+ async function loadRrweb(loader) {
7651
+ if (rrwebModule) return rrwebModule;
7652
+ if (typeof loader === "function") {
7653
+ try {
7654
+ rrwebModule = asRrweb(await loader());
7655
+ if (rrwebModule) return rrwebModule;
7656
+ } catch {
7657
+ }
7658
+ }
7659
+ rrwebModule = asRrweb(globalThis.rrweb);
7603
7660
  if (rrwebModule) return rrwebModule;
7604
7661
  try {
7605
7662
  const specifier = "rrweb";
7606
- rrwebModule = await import(
7663
+ rrwebModule = asRrweb(await import(
7607
7664
  /* @vite-ignore */
7608
7665
  specifier
7609
- );
7666
+ ));
7610
7667
  return rrwebModule;
7611
7668
  } catch {
7612
7669
  return null;
@@ -7614,15 +7671,22 @@ async function loadRrweb() {
7614
7671
  }
7615
7672
  async function createReplayCapture(opts) {
7616
7673
  const maxMs = opts.maxDurationMs ?? DEFAULT_MAX_MS;
7617
- const rrweb = await loadRrweb();
7674
+ if (opts.mode === "lite") return createLiteReplay(maxMs);
7675
+ const rrweb = await loadRrweb(opts.loadRrweb);
7618
7676
  if (!rrweb?.record) {
7677
+ if (!warnedMissingRrweb) {
7678
+ warnedMissingRrweb = true;
7679
+ core.createLogger({ scope: "mushi" }).warn(
7680
+ "capture.replay is 'rrweb' but rrweb could not be loaded, so replay is recording clicks only. Install rrweb and pass capture: { rrweb: () => import('rrweb') }."
7681
+ );
7682
+ }
7619
7683
  return createLiteReplay(maxMs);
7620
7684
  }
7621
7685
  const record = rrweb.record;
7622
7686
  const events = [];
7623
7687
  let stopFn = null;
7624
7688
  let recording = false;
7625
- const maskSelectors = ['input[type="password"]', ...opts.redactSelectors ?? []];
7689
+ const redactSelectors = [.../* @__PURE__ */ new Set([...DEFAULT_REDACT_SELECTORS2, ...opts.redactSelectors ?? []])];
7626
7690
  const stop = () => {
7627
7691
  stopFn?.();
7628
7692
  stopFn = null;
@@ -7638,13 +7702,8 @@ async function createReplayCapture(opts) {
7638
7702
  trimReplayBuffer(events, maxMs, MAX_EVENTS);
7639
7703
  },
7640
7704
  maskAllInputs: true,
7641
- // Mask rendered DOM text too — without this, rrweb records every
7642
- // visible label (emails, names) as plaintext. Hosts that need richer
7643
- // capture can opt out via their own rrweb integration.
7644
- maskAllText: true,
7645
- maskTextSelector: maskSelectors.join(","),
7646
- // Re-emit a full snapshot roughly once per retained window so trimming
7647
- // never leaves incrementals without a base snapshot.
7705
+ maskTextSelector: "*",
7706
+ blockSelector: redactSelectors.join(","),
7648
7707
  checkoutEveryNms: maxMs,
7649
7708
  sampling: { mousemove: false, mouseInteraction: true, scroll: 150, media: 800 }
7650
7709
  }) ?? null;
@@ -8335,17 +8394,42 @@ function createInstance(config) {
8335
8394
  sdkPackage: MUSHI_SDK_PACKAGE,
8336
8395
  sdkVersion: MUSHI_SDK_VERSION
8337
8396
  });
8338
- if (bootstrapConfig["trackSessions"] !== false) {
8397
+ let unsubPageViewHistory = null;
8398
+ if (bootstrapConfig.trackSessions !== false) {
8339
8399
  core.initSessionTracker({
8340
8400
  client: apiClient2,
8341
8401
  sdkVersion: MUSHI_SDK_VERSION,
8342
- reporterTokenHash: core.getReporterToken(bootstrapConfig.projectId) ?? null
8402
+ reporterToken: core.getReporterToken(bootstrapConfig.projectId) ?? null,
8403
+ projectId: bootstrapConfig.projectId,
8404
+ analytics: bootstrapConfig.analytics,
8405
+ // This package owns the history patch (history-patch.ts):
8406
+ // installAutoBreadcrumbs() captures History.prototype.pushState (the
8407
+ // native) and assigns its own wrapper to history.pushState, which
8408
+ // silently discarded core's page-view wrapper — so no SPA page view
8409
+ // was ever recorded from this SDK. Report views through the shared
8410
+ // patch instead of stacking a second wrapper.
8411
+ patchHistory: false
8343
8412
  });
8413
+ try {
8414
+ unsubPageViewHistory = subscribeHistory({
8415
+ onPush: () => core.trackPageView(),
8416
+ onPop: () => core.trackPageView()
8417
+ });
8418
+ } catch {
8419
+ }
8344
8420
  }
8345
8421
  const preFilter = core.createPreFilter(bootstrapConfig.preFilter);
8346
8422
  const offlineQueue = core.createOfflineQueue(bootstrapConfig.offline);
8347
8423
  const rateLimiter = core.createRateLimiter({ maxBurst: 10, refillRate: 1, refillIntervalMs: 5e3 });
8348
8424
  const piiScrubber = core.createPiiScrubber();
8425
+ core.initEventTracker({
8426
+ client: apiClient2,
8427
+ projectId: bootstrapConfig.projectId,
8428
+ sdkVersion: MUSHI_SDK_VERSION,
8429
+ config: bootstrapConfig.analytics,
8430
+ scrub: (s) => piiScrubber.scrub(s),
8431
+ getSessionId: core.getSessionId
8432
+ });
8349
8433
  function scrubBreadcrumbsForWire(crumbs) {
8350
8434
  return crumbs.map((c) => {
8351
8435
  const next = { ...c };
@@ -8525,6 +8609,8 @@ function createInstance(config) {
8525
8609
  if ((replayMode === "rrweb" || replayMode === "lite") && (replaySampled || replayOnErrorSampled)) {
8526
8610
  const generation = ++replayGeneration;
8527
8611
  void createReplayCapture({
8612
+ mode: replayMode,
8613
+ loadRrweb: bootstrapConfig.capture?.rrweb,
8528
8614
  redactSelectors: activeConfig.privacy?.redactSelectors
8529
8615
  }).then((cap) => {
8530
8616
  if (generation !== replayGeneration) {
@@ -8664,6 +8750,7 @@ function createInstance(config) {
8664
8750
  widget.setScreenshotAttached(pendingScreenshot !== null);
8665
8751
  widget.setScreenshotPreview(pendingScreenshot);
8666
8752
  }
8753
+ const brandRefReady = core.sha256Hex(projectId).then((hex) => hex.slice(0, 12)).catch(() => null);
8667
8754
  widget = new MushiWidget(bootstrapConfig.widget, {
8668
8755
  onSubmit: async ({ category, userCategory, description, intent }) => {
8669
8756
  log.info("Report submitted", { category, userCategory, intent });
@@ -8678,6 +8765,18 @@ function createInstance(config) {
8678
8765
  replayCap?.start();
8679
8766
  emit("widget:opened");
8680
8767
  },
8768
+ // Growth loop (plan-gtm C §5); the tracker already honours DNT/consent/enabled.
8769
+ onBrandFooterImpression: () => {
8770
+ void brandRefReady.then((ref) => {
8771
+ core.trackEvent("loop_impression", { placement: "widget" }, ref ? { reserved: { $ref: ref } } : void 0);
8772
+ });
8773
+ },
8774
+ onBrandFooterClick: () => {
8775
+ void brandRefReady.then((ref) => {
8776
+ core.trackEvent("loop_click", { placement: "widget" }, ref ? { reserved: { $ref: ref } } : void 0);
8777
+ return core.flushEvents();
8778
+ });
8779
+ },
8681
8780
  onClose: () => {
8682
8781
  log.debug("Widget closed");
8683
8782
  if (pendingProactiveTrigger) {
@@ -8896,6 +8995,7 @@ function createInstance(config) {
8896
8995
  return res.ok ? res.data ?? null : null;
8897
8996
  }
8898
8997
  }, MUSHI_SDK_VERSION);
8998
+ void brandRefReady.then((ref) => widget.setBrandRef(ref));
8899
8999
  syncCaptureModules();
8900
9000
  if (typeof document !== "undefined") {
8901
9001
  if (document.readyState === "loading") {
@@ -8974,7 +9074,7 @@ function createInstance(config) {
8974
9074
  log.debug("Runtime SDK config disabled; using bootstrap config", { version: runtime.version });
8975
9075
  return;
8976
9076
  }
8977
- activeConfig = mergeRuntimeConfig(activeConfig, runtime);
9077
+ activeConfig = mergeRuntimeConfig(activeConfig, runtime, bootstrapConfig);
8978
9078
  syncCaptureModules();
8979
9079
  if (runtime.widget) widget.updateConfig(activeConfig.widget);
8980
9080
  if (reporterNotificationsEnabled) startReporterInboxPolling();
@@ -9342,6 +9442,7 @@ function createInstance(config) {
9342
9442
  destroy() {
9343
9443
  proactiveTriggers?.destroy();
9344
9444
  proactiveManager?.reset();
9445
+ core.destroyEventTracker();
9345
9446
  widget.destroy();
9346
9447
  consoleCap?.destroy();
9347
9448
  networkCap?.destroy();
@@ -9358,6 +9459,8 @@ function createInstance(config) {
9358
9459
  replayCap = null;
9359
9460
  offlineQueue.stopAutoSync();
9360
9461
  stopReporterInboxPolling();
9462
+ unsubPageViewHistory?.();
9463
+ unsubPageViewHistory = null;
9361
9464
  core.destroySessionTracker();
9362
9465
  breadcrumbs.clear();
9363
9466
  listeners.clear();
@@ -9504,6 +9607,7 @@ function createInstance(config) {
9504
9607
  level: "info",
9505
9608
  message: `Mushi.identify(${userId})`
9506
9609
  });
9610
+ core.updateEventIdentity(userId, traits ?? null);
9507
9611
  wireRewardsForIdentifiedUser(
9508
9612
  userId,
9509
9613
  traits ? {
@@ -9596,6 +9700,16 @@ function createInstance(config) {
9596
9700
  if (!activeConfig.rewards?.enabled) return;
9597
9701
  enqueue({ action, metadata });
9598
9702
  },
9703
+ // ─── Product analytics (Users & Funnels) ──────────────────────────
9704
+ track(event, properties) {
9705
+ return core.trackEvent(event, properties);
9706
+ },
9707
+ setConsent(state) {
9708
+ core.setEventConsent(state);
9709
+ },
9710
+ getAnonymousId() {
9711
+ return core.getEventAnonymousId();
9712
+ },
9599
9713
  pulseTrigger() {
9600
9714
  widget.pulseTrigger?.();
9601
9715
  },
@@ -9906,6 +10020,10 @@ function createNoopInstance() {
9906
10020
  getTier: async () => null,
9907
10021
  recordActivity: () => {
9908
10022
  },
10023
+ track: () => false,
10024
+ setConsent: () => {
10025
+ },
10026
+ getAnonymousId: () => null,
9909
10027
  pulseTrigger: () => {
9910
10028
  },
9911
10029
  listMyReports: async () => [],