@mushi-mushi/core 1.22.5 → 1.25.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.d.cts CHANGED
@@ -322,7 +322,7 @@ interface MushiWidgetAnchor {
322
322
  bottom?: string;
323
323
  left?: string;
324
324
  }
325
- type MushiPreset = 'production-calm' | 'beta-loud' | 'internal-debug' | 'manual-only';
325
+ type MushiPreset = 'production-calm' | 'beta-loud' | 'internal-debug' | 'manual-only' | 'minimal' | 'standard' | 'full';
326
326
  interface MushiWidgetSmartHideConfig {
327
327
  onMobile?: 'edge-tab' | 'hide' | false;
328
328
  onScroll?: 'shrink' | 'hide' | false;
@@ -1390,6 +1390,10 @@ interface MushiApiClient {
1390
1390
  postDiscoveryEvent(event: MushiDiscoveryEventPayload): Promise<MushiApiResponse<{
1391
1391
  accepted: boolean;
1392
1392
  }>>;
1393
+ /** POST /v1/sdk/session — lightweight session lifecycle event (best-effort). */
1394
+ postSessionEvent(payload: MushiSessionEventPayload): Promise<MushiApiResponse<{
1395
+ accepted: boolean;
1396
+ }>>;
1393
1397
  listReporterReports(reporterToken: string): Promise<MushiApiResponse<{
1394
1398
  reports: MushiReporterReport[];
1395
1399
  }>>;
@@ -1520,6 +1524,28 @@ interface MushiDiscoveryEventPayload {
1520
1524
  sdk_version?: string;
1521
1525
  observed_at: string;
1522
1526
  }
1527
+ /** Payload for /v1/sdk/session — lightweight session lifecycle tracking.
1528
+ * Best-effort, no offline queue. Privacy-safe: no PII by default;
1529
+ * `user_id_hash` is the same device-fingerprint hash used elsewhere. */
1530
+ interface MushiSessionEventPayload {
1531
+ /** Lifecycle event kind. */
1532
+ kind: 'session_start' | 'session_heartbeat' | 'session_end' | 'page_view';
1533
+ session_id: string;
1534
+ /** ISO timestamp of the event. */
1535
+ ts: string;
1536
+ /** Entry route for session_start; current route for page_view. */
1537
+ route?: string | null;
1538
+ /** document.referrer on session_start. */
1539
+ referrer?: string | null;
1540
+ /** Total page views in this session so far (updated on heartbeat/end). */
1541
+ page_view_count?: number;
1542
+ /** Device fingerprint hash — same token used in reports. */
1543
+ reporter_token_hash?: string | null;
1544
+ /** user_id_hash when the host app called Mushi.identify(). */
1545
+ user_id_hash?: string | null;
1546
+ user_agent?: string | null;
1547
+ sdk_version?: string;
1548
+ }
1523
1549
  interface MushiApiResponse<T> {
1524
1550
  ok: boolean;
1525
1551
  data?: T;
@@ -1740,6 +1766,56 @@ interface ResolvedEnvConfig {
1740
1766
  * can cleanly spread: `{ ...resolveEnvConfig(), ...explicitConfig }`.
1741
1767
  */
1742
1768
  declare function resolveEnvConfig(): ResolvedEnvConfig;
1769
+ interface EnvNearMiss {
1770
+ field: 'projectId' | 'apiKey';
1771
+ /** The variable that IS set, e.g. `VITE_MUSHI_API_KEY`. */
1772
+ key: string;
1773
+ /** Where it was found. */
1774
+ via: 'import.meta.env' | 'process.env';
1775
+ }
1776
+ interface EnvConfigDiagnostics {
1777
+ resolved: ResolvedEnvConfig;
1778
+ /** Required fields that did not resolve. */
1779
+ missing: Array<'projectId' | 'apiKey'>;
1780
+ /**
1781
+ * Variables that exist under a prefix this runtime does not read (e.g.
1782
+ * `VITE_MUSHI_API_KEY` set but only `process.env` is available). The #1
1783
+ * cause of "I set the env var but Mushi silently does nothing".
1784
+ */
1785
+ nearMisses: EnvNearMiss[];
1786
+ /** Ready-to-print explanation, or null when nothing is wrong. */
1787
+ message: string | null;
1788
+ }
1789
+ /**
1790
+ * Explains WHY zero-config resolution failed instead of failing silently.
1791
+ *
1792
+ * Dynamic env access is fine here: this runs only on the diagnostic path
1793
+ * (after resolution already failed), where we scan whatever env object the
1794
+ * runtime actually exposes — in dev/SSR that is the full `process.env`, which
1795
+ * is exactly where mis-prefixed variables are still visible. In a production
1796
+ * client bundle a mis-prefixed var is simply absent, so we fall back to
1797
+ * naming the expected variable for the detected runtime.
1798
+ */
1799
+ declare function diagnoseEnvConfig(): EnvConfigDiagnostics;
1800
+
1801
+ /**
1802
+ * Expand `config.preset` into the nested option objects, with the user's
1803
+ * explicit config winning on every key. Pure — returns a new object when a
1804
+ * preset applies, or the input untouched for `standard` / no preset / an
1805
+ * unknown value.
1806
+ *
1807
+ * The merge is deliberately per-sub-object (not a generic recursive deep
1808
+ * merge) to avoid corrupting array/RegExp fields such as `capture.ignoreUrls`;
1809
+ * only `proactive.cooldown` needs a second nested spread.
1810
+ */
1811
+ declare function expandPreset(config: MushiConfig): MushiConfig;
1812
+ /**
1813
+ * Runtime config sanity check that fails LOUD but never throws — a
1814
+ * mis-configured host should see a `console.error` at init, not a crash. Warns
1815
+ * on unknown top-level keys (usually a typo or a stale option name) and on an
1816
+ * invalid `preset` value. Honours `MUSHI_SILENT`.
1817
+ */
1818
+ declare function validateConfig(config: MushiConfig): void;
1743
1819
 
1744
1820
  interface PreFilterResult {
1745
1821
  passed: boolean;
@@ -1882,6 +1958,48 @@ declare function getDeviceFingerprintHash(): Promise<string | null>;
1882
1958
 
1883
1959
  declare function getSessionId(): string;
1884
1960
 
1961
+ /**
1962
+ * FILE: packages/core/src/session-tracker.ts
1963
+ * PURPOSE: Lightweight session-lifecycle tracking for the Mushi SDK.
1964
+ *
1965
+ * Emits best-effort events to /v1/sdk/session so the console can show per-
1966
+ * project activity analytics (DAU/WAU, page views, identified vs. anonymous
1967
+ * user split, top routes). Mirrors the postDiscoveryEvent pattern: 1 retry,
1968
+ * no offline queue, fire-and-forget after visibility-change.
1969
+ *
1970
+ * Privacy:
1971
+ * - No PII by default. `reporter_token_hash` is the same opaque device
1972
+ * fingerprint already used in reports. `user_id_hash` is only set when
1973
+ * the host app calls Mushi.identify().
1974
+ * - Respects the SDK-level `trackSessions: false` opt-out option.
1975
+ * - Respects a DNT / Global Privacy Control header at the SDK init layer;
1976
+ * callers should check `shouldRespectDnt()` before calling `initSession`.
1977
+ */
1978
+
1979
+ interface SessionTrackerOptions {
1980
+ client: MushiApiClient;
1981
+ sdkVersion?: string;
1982
+ reporterTokenHash?: string | null;
1983
+ userIdHash?: string | null;
1984
+ }
1985
+ /**
1986
+ * Initialise the session tracker. Call once at SDK init for web environments.
1987
+ * Subsequent calls on the same page are no-ops (idempotent).
1988
+ *
1989
+ * Emits: session_start immediately, heartbeats every minute, session_end on
1990
+ * visibilitychange/pagehide, and page_view on history API navigation.
1991
+ */
1992
+ declare function initSessionTracker(opts: SessionTrackerOptions): void;
1993
+ /**
1994
+ * Record a page view manually — call from framework router hooks where the
1995
+ * history patch may fire too early (e.g. React Router v7 loader transitions).
1996
+ */
1997
+ declare function trackPageView(route?: string): void;
1998
+ /** Update the user identity after a Mushi.identify() call. */
1999
+ declare function updateSessionIdentity(userIdHash: string | null): void;
2000
+ /** Tear down timers (e.g. in tests or SSR environments). */
2001
+ declare function destroySessionTracker(): void;
2002
+
1885
2003
  interface RateLimiterConfig {
1886
2004
  maxBurst?: number;
1887
2005
  refillRate?: number;
@@ -2385,4 +2503,4 @@ declare function projectInitialsThemeIndex(projectId: string): number;
2385
2503
  */
2386
2504
  declare function readPageFaviconHref(): string | null;
2387
2505
 
2388
- export { type ApiClientOptions, type BreadcrumbBuffer, type BreadcrumbBufferOptions, DEFAULT_API_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT, type LogEntry, type LogFormat, type LogLevel, type Logger, type LoggerOptions, MAX_REPORT_PAYLOAD_BYTES, MAX_SCREENSHOT_DATA_URL_BYTES, MUSHI_ACCENT_SHADOW, MUSHI_BANNER_BRAND_BORDER, MUSHI_BANNER_NEON, MUSHI_COLORS_DARK, MUSHI_COLORS_LIGHT, MUSHI_COPY, MUSHI_GEOMETRY, MUSHI_IDENTITY_TOKEN_PREFIX, MUSHI_INTERNAL_HEADER, MUSHI_INTERNAL_INIT_MARKER, MUSHI_INVERSE, MUSHI_MOTION, MUSHI_ON_ACCENT, MUSHI_PROJECT_HEADER, MUSHI_RADIUS, MUSHI_REPORTER_STATUS, MUSHI_SDK_PACKAGE_HEADER, MUSHI_SDK_VERSION_HEADER, MUSHI_SPACING, MUSHI_TIER_COLORS, MUSHI_TYPE, MUSHI_USER_TOKEN_HEADER, MUSHI_Z, type MushiActivityEvent, type MushiApiCascadeConfig, type MushiApiClient, type MushiApiResponse, type MushiAssistantConfig, type MushiAssistantReply, type MushiAssistantStep, type MushiBannerConfig, type MushiBannerLink, type MushiBetaChangelogEntry, type MushiBetaModeConfig, type MushiBreadcrumb, type MushiCaptureConfig, type MushiCaptureEventInput, type MushiCaptureExceptionOptions, type MushiColorPalette, type MushiConfig, type MushiConsoleEntry, type MushiCooldownConfig, type MushiCrossAppReport, type MushiCustomCategory, type MushiDiagnosticsResult, type MushiDiscoverInventoryConfig, type MushiDiscoveryEventPayload, type MushiEnvironment, type MushiEventHandler, type MushiEventType, type MushiHallOfFameEntry, type MushiIdentityClaims, type MushiIntegrationsConfig, type MushiInternalRequestKind, type MushiLeaderboardEntry, type MushiNetworkEntry, type MushiOfflineConfig, type MushiOnDeviceClassifier, type MushiOnDeviceClassifierInput, type MushiOnDeviceClassifierResult, type MushiPageContext, type MushiPerformanceMetrics, type MushiPreFilterConfig, type MushiPreset, type MushiPrivacyConfig, type MushiProactiveConfig, type MushiRegion, type MushiReport, type MushiReportBuilder, type MushiReportCategory, type MushiReportStatus, type MushiReporterComment, type MushiReporterReport, type MushiReputationResult, type MushiRewardsConfig, type MushiRuntimeSdkConfig, type MushiSDKInstance, type MushiSdkVersionInfo, type MushiSelectedElement, type MushiSentryConfig, type MushiSentryContext, type MushiTesterReputation, type MushiThemeMode, type MushiTierResult, type MushiTimelineEntry, type MushiTimelineKind, type MushiTokenSnapshot, type MushiTracePropagationConfig, type MushiUrlMatcher, type MushiWidgetAnchor, type MushiWidgetConfig, type NormalisedException, type OfflineQueue, type PayloadGuardResult, type PiiScrubberConfig, type PreFilterResult, type ProjectFaviconSource, REGION_ENDPOINTS, type RateLimiter, type RateLimiterConfig, type ResolvedEnvConfig, buildIdentityClaims, buildSdkIngestHeaders, captureEnvironment, checkReportPayloadSize, createApiClient, createBreadcrumbBuffer, createLogger, createOfflineQueue, createPiiScrubber, createPreFilter, createRateLimiter, estimateJsonBytes, faviconUrlCandidates, formatBytes, getDeviceFingerprintHash, getReporterToken, getSessionId, githubRepoDomainHint, hmacSha256Hex, isLikelyGenericFavicon, isUntrustedFaviconUrl, mushiPalette, mushiTokens, newUuid, noopLogger, normaliseThrown, originToDomain, parseIdentityToken, projectFaviconUrlCandidates, projectInitials, projectInitialsThemeIndex, readPageFaviconHref, resolveEnvConfig, resolveProjectDomain, resolveProjectFaviconDomains, resolveRegionEndpoint, resolveWidgetAccent, safeWidgetHex, scrubPii, sha256Hex };
2506
+ export { type ApiClientOptions, type BreadcrumbBuffer, type BreadcrumbBufferOptions, DEFAULT_API_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT, type EnvConfigDiagnostics, type EnvNearMiss, type LogEntry, type LogFormat, type LogLevel, type Logger, type LoggerOptions, MAX_REPORT_PAYLOAD_BYTES, MAX_SCREENSHOT_DATA_URL_BYTES, MUSHI_ACCENT_SHADOW, MUSHI_BANNER_BRAND_BORDER, MUSHI_BANNER_NEON, MUSHI_COLORS_DARK, MUSHI_COLORS_LIGHT, MUSHI_COPY, MUSHI_GEOMETRY, MUSHI_IDENTITY_TOKEN_PREFIX, MUSHI_INTERNAL_HEADER, MUSHI_INTERNAL_INIT_MARKER, MUSHI_INVERSE, MUSHI_MOTION, MUSHI_ON_ACCENT, MUSHI_PROJECT_HEADER, MUSHI_RADIUS, MUSHI_REPORTER_STATUS, MUSHI_SDK_PACKAGE_HEADER, MUSHI_SDK_VERSION_HEADER, MUSHI_SPACING, MUSHI_TIER_COLORS, MUSHI_TYPE, MUSHI_USER_TOKEN_HEADER, MUSHI_Z, type MushiActivityEvent, type MushiApiCascadeConfig, type MushiApiClient, type MushiApiResponse, type MushiAssistantConfig, type MushiAssistantReply, type MushiAssistantStep, type MushiBannerConfig, type MushiBannerLink, type MushiBetaChangelogEntry, type MushiBetaModeConfig, type MushiBreadcrumb, type MushiCaptureConfig, type MushiCaptureEventInput, type MushiCaptureExceptionOptions, type MushiColorPalette, type MushiConfig, type MushiConsoleEntry, type MushiCooldownConfig, type MushiCrossAppReport, type MushiCustomCategory, type MushiDiagnosticsResult, type MushiDiscoverInventoryConfig, type MushiDiscoveryEventPayload, type MushiEnvironment, type MushiEventHandler, type MushiEventType, type MushiHallOfFameEntry, type MushiIdentityClaims, type MushiIntegrationsConfig, type MushiInternalRequestKind, type MushiLeaderboardEntry, type MushiNetworkEntry, type MushiOfflineConfig, type MushiOnDeviceClassifier, type MushiOnDeviceClassifierInput, type MushiOnDeviceClassifierResult, type MushiPageContext, type MushiPerformanceMetrics, type MushiPreFilterConfig, type MushiPreset, type MushiPrivacyConfig, type MushiProactiveConfig, type MushiRegion, type MushiReport, type MushiReportBuilder, type MushiReportCategory, type MushiReportStatus, type MushiReporterComment, type MushiReporterReport, type MushiReputationResult, type MushiRewardsConfig, type MushiRuntimeSdkConfig, type MushiSDKInstance, type MushiSdkVersionInfo, type MushiSelectedElement, type MushiSentryConfig, type MushiSentryContext, type MushiSessionEventPayload, type MushiTesterReputation, type MushiThemeMode, type MushiTierResult, type MushiTimelineEntry, type MushiTimelineKind, type MushiTokenSnapshot, type MushiTracePropagationConfig, type MushiUrlMatcher, type MushiWidgetAnchor, type MushiWidgetConfig, type NormalisedException, type OfflineQueue, type PayloadGuardResult, type PiiScrubberConfig, type PreFilterResult, type ProjectFaviconSource, REGION_ENDPOINTS, type RateLimiter, type RateLimiterConfig, type ResolvedEnvConfig, type SessionTrackerOptions, buildIdentityClaims, buildSdkIngestHeaders, captureEnvironment, checkReportPayloadSize, createApiClient, createBreadcrumbBuffer, createLogger, createOfflineQueue, createPiiScrubber, createPreFilter, createRateLimiter, destroySessionTracker, diagnoseEnvConfig, estimateJsonBytes, expandPreset, faviconUrlCandidates, formatBytes, getDeviceFingerprintHash, getReporterToken, getSessionId, githubRepoDomainHint, hmacSha256Hex, initSessionTracker, isLikelyGenericFavicon, isUntrustedFaviconUrl, mushiPalette, mushiTokens, newUuid, noopLogger, normaliseThrown, originToDomain, parseIdentityToken, projectFaviconUrlCandidates, projectInitials, projectInitialsThemeIndex, readPageFaviconHref, resolveEnvConfig, resolveProjectDomain, resolveProjectFaviconDomains, resolveRegionEndpoint, resolveWidgetAccent, safeWidgetHex, scrubPii, sha256Hex, trackPageView, updateSessionIdentity, validateConfig };
package/dist/index.d.ts CHANGED
@@ -322,7 +322,7 @@ interface MushiWidgetAnchor {
322
322
  bottom?: string;
323
323
  left?: string;
324
324
  }
325
- type MushiPreset = 'production-calm' | 'beta-loud' | 'internal-debug' | 'manual-only';
325
+ type MushiPreset = 'production-calm' | 'beta-loud' | 'internal-debug' | 'manual-only' | 'minimal' | 'standard' | 'full';
326
326
  interface MushiWidgetSmartHideConfig {
327
327
  onMobile?: 'edge-tab' | 'hide' | false;
328
328
  onScroll?: 'shrink' | 'hide' | false;
@@ -1390,6 +1390,10 @@ interface MushiApiClient {
1390
1390
  postDiscoveryEvent(event: MushiDiscoveryEventPayload): Promise<MushiApiResponse<{
1391
1391
  accepted: boolean;
1392
1392
  }>>;
1393
+ /** POST /v1/sdk/session — lightweight session lifecycle event (best-effort). */
1394
+ postSessionEvent(payload: MushiSessionEventPayload): Promise<MushiApiResponse<{
1395
+ accepted: boolean;
1396
+ }>>;
1393
1397
  listReporterReports(reporterToken: string): Promise<MushiApiResponse<{
1394
1398
  reports: MushiReporterReport[];
1395
1399
  }>>;
@@ -1520,6 +1524,28 @@ interface MushiDiscoveryEventPayload {
1520
1524
  sdk_version?: string;
1521
1525
  observed_at: string;
1522
1526
  }
1527
+ /** Payload for /v1/sdk/session — lightweight session lifecycle tracking.
1528
+ * Best-effort, no offline queue. Privacy-safe: no PII by default;
1529
+ * `user_id_hash` is the same device-fingerprint hash used elsewhere. */
1530
+ interface MushiSessionEventPayload {
1531
+ /** Lifecycle event kind. */
1532
+ kind: 'session_start' | 'session_heartbeat' | 'session_end' | 'page_view';
1533
+ session_id: string;
1534
+ /** ISO timestamp of the event. */
1535
+ ts: string;
1536
+ /** Entry route for session_start; current route for page_view. */
1537
+ route?: string | null;
1538
+ /** document.referrer on session_start. */
1539
+ referrer?: string | null;
1540
+ /** Total page views in this session so far (updated on heartbeat/end). */
1541
+ page_view_count?: number;
1542
+ /** Device fingerprint hash — same token used in reports. */
1543
+ reporter_token_hash?: string | null;
1544
+ /** user_id_hash when the host app called Mushi.identify(). */
1545
+ user_id_hash?: string | null;
1546
+ user_agent?: string | null;
1547
+ sdk_version?: string;
1548
+ }
1523
1549
  interface MushiApiResponse<T> {
1524
1550
  ok: boolean;
1525
1551
  data?: T;
@@ -1740,6 +1766,56 @@ interface ResolvedEnvConfig {
1740
1766
  * can cleanly spread: `{ ...resolveEnvConfig(), ...explicitConfig }`.
1741
1767
  */
1742
1768
  declare function resolveEnvConfig(): ResolvedEnvConfig;
1769
+ interface EnvNearMiss {
1770
+ field: 'projectId' | 'apiKey';
1771
+ /** The variable that IS set, e.g. `VITE_MUSHI_API_KEY`. */
1772
+ key: string;
1773
+ /** Where it was found. */
1774
+ via: 'import.meta.env' | 'process.env';
1775
+ }
1776
+ interface EnvConfigDiagnostics {
1777
+ resolved: ResolvedEnvConfig;
1778
+ /** Required fields that did not resolve. */
1779
+ missing: Array<'projectId' | 'apiKey'>;
1780
+ /**
1781
+ * Variables that exist under a prefix this runtime does not read (e.g.
1782
+ * `VITE_MUSHI_API_KEY` set but only `process.env` is available). The #1
1783
+ * cause of "I set the env var but Mushi silently does nothing".
1784
+ */
1785
+ nearMisses: EnvNearMiss[];
1786
+ /** Ready-to-print explanation, or null when nothing is wrong. */
1787
+ message: string | null;
1788
+ }
1789
+ /**
1790
+ * Explains WHY zero-config resolution failed instead of failing silently.
1791
+ *
1792
+ * Dynamic env access is fine here: this runs only on the diagnostic path
1793
+ * (after resolution already failed), where we scan whatever env object the
1794
+ * runtime actually exposes — in dev/SSR that is the full `process.env`, which
1795
+ * is exactly where mis-prefixed variables are still visible. In a production
1796
+ * client bundle a mis-prefixed var is simply absent, so we fall back to
1797
+ * naming the expected variable for the detected runtime.
1798
+ */
1799
+ declare function diagnoseEnvConfig(): EnvConfigDiagnostics;
1800
+
1801
+ /**
1802
+ * Expand `config.preset` into the nested option objects, with the user's
1803
+ * explicit config winning on every key. Pure — returns a new object when a
1804
+ * preset applies, or the input untouched for `standard` / no preset / an
1805
+ * unknown value.
1806
+ *
1807
+ * The merge is deliberately per-sub-object (not a generic recursive deep
1808
+ * merge) to avoid corrupting array/RegExp fields such as `capture.ignoreUrls`;
1809
+ * only `proactive.cooldown` needs a second nested spread.
1810
+ */
1811
+ declare function expandPreset(config: MushiConfig): MushiConfig;
1812
+ /**
1813
+ * Runtime config sanity check that fails LOUD but never throws — a
1814
+ * mis-configured host should see a `console.error` at init, not a crash. Warns
1815
+ * on unknown top-level keys (usually a typo or a stale option name) and on an
1816
+ * invalid `preset` value. Honours `MUSHI_SILENT`.
1817
+ */
1818
+ declare function validateConfig(config: MushiConfig): void;
1743
1819
 
1744
1820
  interface PreFilterResult {
1745
1821
  passed: boolean;
@@ -1882,6 +1958,48 @@ declare function getDeviceFingerprintHash(): Promise<string | null>;
1882
1958
 
1883
1959
  declare function getSessionId(): string;
1884
1960
 
1961
+ /**
1962
+ * FILE: packages/core/src/session-tracker.ts
1963
+ * PURPOSE: Lightweight session-lifecycle tracking for the Mushi SDK.
1964
+ *
1965
+ * Emits best-effort events to /v1/sdk/session so the console can show per-
1966
+ * project activity analytics (DAU/WAU, page views, identified vs. anonymous
1967
+ * user split, top routes). Mirrors the postDiscoveryEvent pattern: 1 retry,
1968
+ * no offline queue, fire-and-forget after visibility-change.
1969
+ *
1970
+ * Privacy:
1971
+ * - No PII by default. `reporter_token_hash` is the same opaque device
1972
+ * fingerprint already used in reports. `user_id_hash` is only set when
1973
+ * the host app calls Mushi.identify().
1974
+ * - Respects the SDK-level `trackSessions: false` opt-out option.
1975
+ * - Respects a DNT / Global Privacy Control header at the SDK init layer;
1976
+ * callers should check `shouldRespectDnt()` before calling `initSession`.
1977
+ */
1978
+
1979
+ interface SessionTrackerOptions {
1980
+ client: MushiApiClient;
1981
+ sdkVersion?: string;
1982
+ reporterTokenHash?: string | null;
1983
+ userIdHash?: string | null;
1984
+ }
1985
+ /**
1986
+ * Initialise the session tracker. Call once at SDK init for web environments.
1987
+ * Subsequent calls on the same page are no-ops (idempotent).
1988
+ *
1989
+ * Emits: session_start immediately, heartbeats every minute, session_end on
1990
+ * visibilitychange/pagehide, and page_view on history API navigation.
1991
+ */
1992
+ declare function initSessionTracker(opts: SessionTrackerOptions): void;
1993
+ /**
1994
+ * Record a page view manually — call from framework router hooks where the
1995
+ * history patch may fire too early (e.g. React Router v7 loader transitions).
1996
+ */
1997
+ declare function trackPageView(route?: string): void;
1998
+ /** Update the user identity after a Mushi.identify() call. */
1999
+ declare function updateSessionIdentity(userIdHash: string | null): void;
2000
+ /** Tear down timers (e.g. in tests or SSR environments). */
2001
+ declare function destroySessionTracker(): void;
2002
+
1885
2003
  interface RateLimiterConfig {
1886
2004
  maxBurst?: number;
1887
2005
  refillRate?: number;
@@ -2385,4 +2503,4 @@ declare function projectInitialsThemeIndex(projectId: string): number;
2385
2503
  */
2386
2504
  declare function readPageFaviconHref(): string | null;
2387
2505
 
2388
- export { type ApiClientOptions, type BreadcrumbBuffer, type BreadcrumbBufferOptions, DEFAULT_API_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT, type LogEntry, type LogFormat, type LogLevel, type Logger, type LoggerOptions, MAX_REPORT_PAYLOAD_BYTES, MAX_SCREENSHOT_DATA_URL_BYTES, MUSHI_ACCENT_SHADOW, MUSHI_BANNER_BRAND_BORDER, MUSHI_BANNER_NEON, MUSHI_COLORS_DARK, MUSHI_COLORS_LIGHT, MUSHI_COPY, MUSHI_GEOMETRY, MUSHI_IDENTITY_TOKEN_PREFIX, MUSHI_INTERNAL_HEADER, MUSHI_INTERNAL_INIT_MARKER, MUSHI_INVERSE, MUSHI_MOTION, MUSHI_ON_ACCENT, MUSHI_PROJECT_HEADER, MUSHI_RADIUS, MUSHI_REPORTER_STATUS, MUSHI_SDK_PACKAGE_HEADER, MUSHI_SDK_VERSION_HEADER, MUSHI_SPACING, MUSHI_TIER_COLORS, MUSHI_TYPE, MUSHI_USER_TOKEN_HEADER, MUSHI_Z, type MushiActivityEvent, type MushiApiCascadeConfig, type MushiApiClient, type MushiApiResponse, type MushiAssistantConfig, type MushiAssistantReply, type MushiAssistantStep, type MushiBannerConfig, type MushiBannerLink, type MushiBetaChangelogEntry, type MushiBetaModeConfig, type MushiBreadcrumb, type MushiCaptureConfig, type MushiCaptureEventInput, type MushiCaptureExceptionOptions, type MushiColorPalette, type MushiConfig, type MushiConsoleEntry, type MushiCooldownConfig, type MushiCrossAppReport, type MushiCustomCategory, type MushiDiagnosticsResult, type MushiDiscoverInventoryConfig, type MushiDiscoveryEventPayload, type MushiEnvironment, type MushiEventHandler, type MushiEventType, type MushiHallOfFameEntry, type MushiIdentityClaims, type MushiIntegrationsConfig, type MushiInternalRequestKind, type MushiLeaderboardEntry, type MushiNetworkEntry, type MushiOfflineConfig, type MushiOnDeviceClassifier, type MushiOnDeviceClassifierInput, type MushiOnDeviceClassifierResult, type MushiPageContext, type MushiPerformanceMetrics, type MushiPreFilterConfig, type MushiPreset, type MushiPrivacyConfig, type MushiProactiveConfig, type MushiRegion, type MushiReport, type MushiReportBuilder, type MushiReportCategory, type MushiReportStatus, type MushiReporterComment, type MushiReporterReport, type MushiReputationResult, type MushiRewardsConfig, type MushiRuntimeSdkConfig, type MushiSDKInstance, type MushiSdkVersionInfo, type MushiSelectedElement, type MushiSentryConfig, type MushiSentryContext, type MushiTesterReputation, type MushiThemeMode, type MushiTierResult, type MushiTimelineEntry, type MushiTimelineKind, type MushiTokenSnapshot, type MushiTracePropagationConfig, type MushiUrlMatcher, type MushiWidgetAnchor, type MushiWidgetConfig, type NormalisedException, type OfflineQueue, type PayloadGuardResult, type PiiScrubberConfig, type PreFilterResult, type ProjectFaviconSource, REGION_ENDPOINTS, type RateLimiter, type RateLimiterConfig, type ResolvedEnvConfig, buildIdentityClaims, buildSdkIngestHeaders, captureEnvironment, checkReportPayloadSize, createApiClient, createBreadcrumbBuffer, createLogger, createOfflineQueue, createPiiScrubber, createPreFilter, createRateLimiter, estimateJsonBytes, faviconUrlCandidates, formatBytes, getDeviceFingerprintHash, getReporterToken, getSessionId, githubRepoDomainHint, hmacSha256Hex, isLikelyGenericFavicon, isUntrustedFaviconUrl, mushiPalette, mushiTokens, newUuid, noopLogger, normaliseThrown, originToDomain, parseIdentityToken, projectFaviconUrlCandidates, projectInitials, projectInitialsThemeIndex, readPageFaviconHref, resolveEnvConfig, resolveProjectDomain, resolveProjectFaviconDomains, resolveRegionEndpoint, resolveWidgetAccent, safeWidgetHex, scrubPii, sha256Hex };
2506
+ export { type ApiClientOptions, type BreadcrumbBuffer, type BreadcrumbBufferOptions, DEFAULT_API_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT, type EnvConfigDiagnostics, type EnvNearMiss, type LogEntry, type LogFormat, type LogLevel, type Logger, type LoggerOptions, MAX_REPORT_PAYLOAD_BYTES, MAX_SCREENSHOT_DATA_URL_BYTES, MUSHI_ACCENT_SHADOW, MUSHI_BANNER_BRAND_BORDER, MUSHI_BANNER_NEON, MUSHI_COLORS_DARK, MUSHI_COLORS_LIGHT, MUSHI_COPY, MUSHI_GEOMETRY, MUSHI_IDENTITY_TOKEN_PREFIX, MUSHI_INTERNAL_HEADER, MUSHI_INTERNAL_INIT_MARKER, MUSHI_INVERSE, MUSHI_MOTION, MUSHI_ON_ACCENT, MUSHI_PROJECT_HEADER, MUSHI_RADIUS, MUSHI_REPORTER_STATUS, MUSHI_SDK_PACKAGE_HEADER, MUSHI_SDK_VERSION_HEADER, MUSHI_SPACING, MUSHI_TIER_COLORS, MUSHI_TYPE, MUSHI_USER_TOKEN_HEADER, MUSHI_Z, type MushiActivityEvent, type MushiApiCascadeConfig, type MushiApiClient, type MushiApiResponse, type MushiAssistantConfig, type MushiAssistantReply, type MushiAssistantStep, type MushiBannerConfig, type MushiBannerLink, type MushiBetaChangelogEntry, type MushiBetaModeConfig, type MushiBreadcrumb, type MushiCaptureConfig, type MushiCaptureEventInput, type MushiCaptureExceptionOptions, type MushiColorPalette, type MushiConfig, type MushiConsoleEntry, type MushiCooldownConfig, type MushiCrossAppReport, type MushiCustomCategory, type MushiDiagnosticsResult, type MushiDiscoverInventoryConfig, type MushiDiscoveryEventPayload, type MushiEnvironment, type MushiEventHandler, type MushiEventType, type MushiHallOfFameEntry, type MushiIdentityClaims, type MushiIntegrationsConfig, type MushiInternalRequestKind, type MushiLeaderboardEntry, type MushiNetworkEntry, type MushiOfflineConfig, type MushiOnDeviceClassifier, type MushiOnDeviceClassifierInput, type MushiOnDeviceClassifierResult, type MushiPageContext, type MushiPerformanceMetrics, type MushiPreFilterConfig, type MushiPreset, type MushiPrivacyConfig, type MushiProactiveConfig, type MushiRegion, type MushiReport, type MushiReportBuilder, type MushiReportCategory, type MushiReportStatus, type MushiReporterComment, type MushiReporterReport, type MushiReputationResult, type MushiRewardsConfig, type MushiRuntimeSdkConfig, type MushiSDKInstance, type MushiSdkVersionInfo, type MushiSelectedElement, type MushiSentryConfig, type MushiSentryContext, type MushiSessionEventPayload, type MushiTesterReputation, type MushiThemeMode, type MushiTierResult, type MushiTimelineEntry, type MushiTimelineKind, type MushiTokenSnapshot, type MushiTracePropagationConfig, type MushiUrlMatcher, type MushiWidgetAnchor, type MushiWidgetConfig, type NormalisedException, type OfflineQueue, type PayloadGuardResult, type PiiScrubberConfig, type PreFilterResult, type ProjectFaviconSource, REGION_ENDPOINTS, type RateLimiter, type RateLimiterConfig, type ResolvedEnvConfig, type SessionTrackerOptions, buildIdentityClaims, buildSdkIngestHeaders, captureEnvironment, checkReportPayloadSize, createApiClient, createBreadcrumbBuffer, createLogger, createOfflineQueue, createPiiScrubber, createPreFilter, createRateLimiter, destroySessionTracker, diagnoseEnvConfig, estimateJsonBytes, expandPreset, faviconUrlCandidates, formatBytes, getDeviceFingerprintHash, getReporterToken, getSessionId, githubRepoDomainHint, hmacSha256Hex, initSessionTracker, isLikelyGenericFavicon, isUntrustedFaviconUrl, mushiPalette, mushiTokens, newUuid, noopLogger, normaliseThrown, originToDomain, parseIdentityToken, projectFaviconUrlCandidates, projectInitials, projectInitialsThemeIndex, readPageFaviconHref, resolveEnvConfig, resolveProjectDomain, resolveProjectFaviconDomains, resolveRegionEndpoint, resolveWidgetAccent, safeWidgetHex, scrubPii, sha256Hex, trackPageView, updateSessionIdentity, validateConfig };