@mushi-mushi/web 1.41.0 → 1.42.0-next.20261205140616

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/README.md CHANGED
@@ -44,7 +44,7 @@ Building in Lovable or Bolt with no terminal? A script tag works too: [Mushi Mus
44
44
  | **Privacy** | A built-in PII scrubber, selector masking for screenshots, and opt-in session replay. |
45
45
  | **Stays out of the way** | Zero-size host with `pointer-events: none`, keyboard-first, respects reduced motion. |
46
46
  | **Runtime config** | Change the widget from the console without a deploy. Values you set in code win. |
47
- | **Size** | CI caps the core bundle at 96 KB gzipped (105 KB uncompressed). Screenshot capture, screenshot markup and the Your reports views load only when used. |
47
+ | **Size** | CI caps the core bundle at 96.5 KB gzipped (105 KB uncompressed). Screenshot capture, screenshot markup and the Your reports views load only when used. |
48
48
 
49
49
  ## Recipes
50
50
 
package/dist/index.cjs CHANGED
@@ -7773,7 +7773,48 @@ function readCaptureMode(w = typeof window !== "undefined" ? window : void 0) {
7773
7773
 
7774
7774
  // src/version.ts
7775
7775
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
7776
- var MUSHI_SDK_VERSION = "1.41.0" ;
7776
+ var MUSHI_SDK_VERSION = "1.42.0-next.20261205140616" ;
7777
+
7778
+ // src/widget-pause.ts
7779
+ var WIDGET_PAUSE_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
7780
+ function pausedForVersion(paused, version) {
7781
+ if (!paused || typeof paused !== "object") return false;
7782
+ const versions = paused.versions;
7783
+ if (!Array.isArray(versions) || versions.length === 0) return true;
7784
+ return versions.includes(version);
7785
+ }
7786
+ function pauseKey(projectId) {
7787
+ return `mushi:widget-paused:${projectId}`;
7788
+ }
7789
+ function readWidgetPause(projectId, now = Date.now()) {
7790
+ if (typeof localStorage === "undefined") return false;
7791
+ try {
7792
+ const raw = localStorage.getItem(pauseKey(projectId));
7793
+ if (!raw) return false;
7794
+ const at = Number(JSON.parse(raw).at);
7795
+ if (!Number.isFinite(at) || now - at > WIDGET_PAUSE_MAX_AGE_MS || at > now + 6e4) {
7796
+ localStorage.removeItem(pauseKey(projectId));
7797
+ return false;
7798
+ }
7799
+ return true;
7800
+ } catch {
7801
+ return false;
7802
+ }
7803
+ }
7804
+ function writeWidgetPause(projectId, now = Date.now()) {
7805
+ if (typeof localStorage === "undefined") return;
7806
+ try {
7807
+ localStorage.setItem(pauseKey(projectId), JSON.stringify({ at: now }));
7808
+ } catch {
7809
+ }
7810
+ }
7811
+ function clearWidgetPause(projectId) {
7812
+ if (typeof localStorage === "undefined") return;
7813
+ try {
7814
+ localStorage.removeItem(pauseKey(projectId));
7815
+ } catch {
7816
+ }
7817
+ }
7777
7818
  function resolveReportAppVersion(config, environment) {
7778
7819
  if (config.appVersion) return config.appVersion;
7779
7820
  const vercelId = config.integrations?.vercel?.analyticsId;
@@ -7802,6 +7843,10 @@ var Mushi = class {
7802
7843
  if (resolved.enabled === false) {
7803
7844
  return createNoopInstance();
7804
7845
  }
7846
+ if (shouldUseRuntimeConfig(resolved) && readWidgetPause(resolved.projectId)) {
7847
+ recheckWidgetPause(resolved);
7848
+ return createNoopInstance();
7849
+ }
7805
7850
  instance = createInstance(resolved);
7806
7851
  return instance;
7807
7852
  }
@@ -8717,11 +8762,19 @@ function createInstance(config) {
8717
8762
  else stopReporterInboxPolling();
8718
8763
  log.debug("Applied runtime SDK config", { version: runtime.version });
8719
8764
  }
8765
+ let publicHandle = null;
8720
8766
  if (shouldUseRuntimeConfig(config)) {
8721
8767
  const cached = readCachedRuntimeConfig(config.projectId);
8722
8768
  if (cached) applyRuntimeConfig(cached);
8723
8769
  apiClient2.getSdkConfig(trackSessionsMode === "on-demand" ? { fresh: true } : void 0).then((result) => {
8724
8770
  if (result.ok && result.data) {
8771
+ if (pausedForVersion(result.data.paused, MUSHI_SDK_VERSION)) {
8772
+ writeWidgetPause(config.projectId);
8773
+ log.info("Widget turned off from the Mushi console; unmounting", { version: MUSHI_SDK_VERSION });
8774
+ if (publicHandle && instance === publicHandle) Mushi.destroy();
8775
+ return;
8776
+ }
8777
+ clearWidgetPause(config.projectId);
8725
8778
  cacheRuntimeConfig(config.projectId, result.data);
8726
8779
  applyRuntimeConfig(result.data);
8727
8780
  if (result.data.enabled !== false) maybeStartSessionTracking(result.data.journeys ?? null);
@@ -9514,11 +9567,33 @@ function createInstance(config) {
9514
9567
  };
9515
9568
  }
9516
9569
  });
9517
- return isolatePublicApi(sdk);
9570
+ publicHandle = isolatePublicApi(sdk);
9571
+ return publicHandle;
9518
9572
  }
9519
9573
  function resolveApiEndpoint(config) {
9520
9574
  return config.apiEndpoint ?? core.DEFAULT_API_ENDPOINT;
9521
9575
  }
9576
+ function recheckWidgetPause(config) {
9577
+ try {
9578
+ const cfg = core.expandPreset(config);
9579
+ const client = core.createApiClient({
9580
+ projectId: cfg.projectId,
9581
+ apiKey: cfg.apiKey,
9582
+ ...cfg.apiEndpoint ? { apiEndpoint: cfg.apiEndpoint } : {},
9583
+ ...cfg.tunnel ? { tunnel: cfg.tunnel } : {},
9584
+ maxRetries: 0,
9585
+ sdkPackage: MUSHI_SDK_PACKAGE,
9586
+ sdkVersion: MUSHI_SDK_VERSION
9587
+ });
9588
+ client.getSdkConfig({ fresh: true }).then((result) => {
9589
+ if (!result.ok || !result.data) return;
9590
+ if (pausedForVersion(result.data.paused, MUSHI_SDK_VERSION)) writeWidgetPause(cfg.projectId);
9591
+ else clearWidgetPause(cfg.projectId);
9592
+ }).catch(() => {
9593
+ });
9594
+ } catch {
9595
+ }
9596
+ }
9522
9597
  function shouldUseRuntimeConfig(config) {
9523
9598
  return config.runtimeConfig !== false;
9524
9599
  }