@mushi-mushi/core 1.22.4 → 1.23.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;
@@ -1740,6 +1740,56 @@ interface ResolvedEnvConfig {
1740
1740
  * can cleanly spread: `{ ...resolveEnvConfig(), ...explicitConfig }`.
1741
1741
  */
1742
1742
  declare function resolveEnvConfig(): ResolvedEnvConfig;
1743
+ interface EnvNearMiss {
1744
+ field: 'projectId' | 'apiKey';
1745
+ /** The variable that IS set, e.g. `VITE_MUSHI_API_KEY`. */
1746
+ key: string;
1747
+ /** Where it was found. */
1748
+ via: 'import.meta.env' | 'process.env';
1749
+ }
1750
+ interface EnvConfigDiagnostics {
1751
+ resolved: ResolvedEnvConfig;
1752
+ /** Required fields that did not resolve. */
1753
+ missing: Array<'projectId' | 'apiKey'>;
1754
+ /**
1755
+ * Variables that exist under a prefix this runtime does not read (e.g.
1756
+ * `VITE_MUSHI_API_KEY` set but only `process.env` is available). The #1
1757
+ * cause of "I set the env var but Mushi silently does nothing".
1758
+ */
1759
+ nearMisses: EnvNearMiss[];
1760
+ /** Ready-to-print explanation, or null when nothing is wrong. */
1761
+ message: string | null;
1762
+ }
1763
+ /**
1764
+ * Explains WHY zero-config resolution failed instead of failing silently.
1765
+ *
1766
+ * Dynamic env access is fine here: this runs only on the diagnostic path
1767
+ * (after resolution already failed), where we scan whatever env object the
1768
+ * runtime actually exposes — in dev/SSR that is the full `process.env`, which
1769
+ * is exactly where mis-prefixed variables are still visible. In a production
1770
+ * client bundle a mis-prefixed var is simply absent, so we fall back to
1771
+ * naming the expected variable for the detected runtime.
1772
+ */
1773
+ declare function diagnoseEnvConfig(): EnvConfigDiagnostics;
1774
+
1775
+ /**
1776
+ * Expand `config.preset` into the nested option objects, with the user's
1777
+ * explicit config winning on every key. Pure — returns a new object when a
1778
+ * preset applies, or the input untouched for `standard` / no preset / an
1779
+ * unknown value.
1780
+ *
1781
+ * The merge is deliberately per-sub-object (not a generic recursive deep
1782
+ * merge) to avoid corrupting array/RegExp fields such as `capture.ignoreUrls`;
1783
+ * only `proactive.cooldown` needs a second nested spread.
1784
+ */
1785
+ declare function expandPreset(config: MushiConfig): MushiConfig;
1786
+ /**
1787
+ * Runtime config sanity check that fails LOUD but never throws — a
1788
+ * mis-configured host should see a `console.error` at init, not a crash. Warns
1789
+ * on unknown top-level keys (usually a typo or a stale option name) and on an
1790
+ * invalid `preset` value. Honours `MUSHI_SILENT`.
1791
+ */
1792
+ declare function validateConfig(config: MushiConfig): void;
1743
1793
 
1744
1794
  interface PreFilterResult {
1745
1795
  passed: boolean;
@@ -2385,4 +2435,4 @@ declare function projectInitialsThemeIndex(projectId: string): number;
2385
2435
  */
2386
2436
  declare function readPageFaviconHref(): string | null;
2387
2437
 
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 };
2438
+ 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 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, diagnoseEnvConfig, estimateJsonBytes, expandPreset, 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, 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;
@@ -1740,6 +1740,56 @@ interface ResolvedEnvConfig {
1740
1740
  * can cleanly spread: `{ ...resolveEnvConfig(), ...explicitConfig }`.
1741
1741
  */
1742
1742
  declare function resolveEnvConfig(): ResolvedEnvConfig;
1743
+ interface EnvNearMiss {
1744
+ field: 'projectId' | 'apiKey';
1745
+ /** The variable that IS set, e.g. `VITE_MUSHI_API_KEY`. */
1746
+ key: string;
1747
+ /** Where it was found. */
1748
+ via: 'import.meta.env' | 'process.env';
1749
+ }
1750
+ interface EnvConfigDiagnostics {
1751
+ resolved: ResolvedEnvConfig;
1752
+ /** Required fields that did not resolve. */
1753
+ missing: Array<'projectId' | 'apiKey'>;
1754
+ /**
1755
+ * Variables that exist under a prefix this runtime does not read (e.g.
1756
+ * `VITE_MUSHI_API_KEY` set but only `process.env` is available). The #1
1757
+ * cause of "I set the env var but Mushi silently does nothing".
1758
+ */
1759
+ nearMisses: EnvNearMiss[];
1760
+ /** Ready-to-print explanation, or null when nothing is wrong. */
1761
+ message: string | null;
1762
+ }
1763
+ /**
1764
+ * Explains WHY zero-config resolution failed instead of failing silently.
1765
+ *
1766
+ * Dynamic env access is fine here: this runs only on the diagnostic path
1767
+ * (after resolution already failed), where we scan whatever env object the
1768
+ * runtime actually exposes — in dev/SSR that is the full `process.env`, which
1769
+ * is exactly where mis-prefixed variables are still visible. In a production
1770
+ * client bundle a mis-prefixed var is simply absent, so we fall back to
1771
+ * naming the expected variable for the detected runtime.
1772
+ */
1773
+ declare function diagnoseEnvConfig(): EnvConfigDiagnostics;
1774
+
1775
+ /**
1776
+ * Expand `config.preset` into the nested option objects, with the user's
1777
+ * explicit config winning on every key. Pure — returns a new object when a
1778
+ * preset applies, or the input untouched for `standard` / no preset / an
1779
+ * unknown value.
1780
+ *
1781
+ * The merge is deliberately per-sub-object (not a generic recursive deep
1782
+ * merge) to avoid corrupting array/RegExp fields such as `capture.ignoreUrls`;
1783
+ * only `proactive.cooldown` needs a second nested spread.
1784
+ */
1785
+ declare function expandPreset(config: MushiConfig): MushiConfig;
1786
+ /**
1787
+ * Runtime config sanity check that fails LOUD but never throws — a
1788
+ * mis-configured host should see a `console.error` at init, not a crash. Warns
1789
+ * on unknown top-level keys (usually a typo or a stale option name) and on an
1790
+ * invalid `preset` value. Honours `MUSHI_SILENT`.
1791
+ */
1792
+ declare function validateConfig(config: MushiConfig): void;
1743
1793
 
1744
1794
  interface PreFilterResult {
1745
1795
  passed: boolean;
@@ -2385,4 +2435,4 @@ declare function projectInitialsThemeIndex(projectId: string): number;
2385
2435
  */
2386
2436
  declare function readPageFaviconHref(): string | null;
2387
2437
 
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 };
2438
+ 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 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, diagnoseEnvConfig, estimateJsonBytes, expandPreset, 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, validateConfig };
package/dist/index.js CHANGED
@@ -599,6 +599,219 @@ function resolveEnvConfig() {
599
599
  if (apiEndpoint) result.apiEndpoint = apiEndpoint;
600
600
  return result;
601
601
  }
602
+ var ENV_PREFIXES = ["VITE_", "NEXT_PUBLIC_", "NUXT_PUBLIC_", "EXPO_PUBLIC_", ""];
603
+ var FIELD_SUFFIX = {
604
+ projectId: "MUSHI_PROJECT_ID",
605
+ apiKey: "MUSHI_API_KEY"
606
+ };
607
+ function diagnoseEnvConfig() {
608
+ const resolved = resolveEnvConfig();
609
+ const missing = [];
610
+ if (!resolved.projectId) missing.push("projectId");
611
+ if (!resolved.apiKey) missing.push("apiKey");
612
+ if (missing.length === 0) {
613
+ return { resolved, missing, nearMisses: [], message: null };
614
+ }
615
+ const importMetaEnv = (() => {
616
+ try {
617
+ const env = import.meta.env;
618
+ return typeof env === "object" && env !== null ? env : null;
619
+ } catch {
620
+ return null;
621
+ }
622
+ })();
623
+ const processEnv = (() => {
624
+ try {
625
+ return typeof process !== "undefined" && process.env ? process.env : null;
626
+ } catch {
627
+ return null;
628
+ }
629
+ })();
630
+ const nearMisses = [];
631
+ for (const field of missing) {
632
+ for (const prefix of ENV_PREFIXES) {
633
+ const key = `${prefix}${FIELD_SUFFIX[field]}`;
634
+ if (importMetaEnv && importMetaEnv[key]) {
635
+ nearMisses.push({ field, key, via: "import.meta.env" });
636
+ } else if (processEnv && processEnv[key]) {
637
+ nearMisses.push({ field, key, via: "process.env" });
638
+ }
639
+ }
640
+ }
641
+ const expectedPrefix = importMetaEnv ? "VITE_MUSHI_*" : "NEXT_PUBLIC_MUSHI_* (Next.js), EXPO_PUBLIC_MUSHI_* (Expo), or MUSHI_* (Node / React Native)";
642
+ const lines = [`[mushi] Missing ${missing.join(" and ")} \u2014 the SDK will not initialize.`];
643
+ for (const m of nearMisses) {
644
+ lines.push(
645
+ `[mushi] Found ${m.key} in ${m.via}, but this runtime did not resolve it \u2014 it is either the wrong prefix for your bundler or not exposed to the client bundle.`
646
+ );
647
+ }
648
+ lines.push(`[mushi] This runtime reads: ${expectedPrefix}. Set the matching variable(s) and restart your dev server.`);
649
+ if (nearMisses.length === 0) {
650
+ lines.push(
651
+ `[mushi] If you already set the variable, check the prefix: a mis-prefixed var is stripped from client bundles and resolves to undefined with no error.`
652
+ );
653
+ }
654
+ return { resolved, missing, nearMisses, message: lines.join("\n") };
655
+ }
656
+
657
+ // src/presets.ts
658
+ var KNOWN_PRESETS = [
659
+ "production-calm",
660
+ "beta-loud",
661
+ "internal-debug",
662
+ "manual-only",
663
+ "minimal",
664
+ "standard",
665
+ "full"
666
+ ];
667
+ var KNOWN_CONFIG_KEYS = [
668
+ "projectId",
669
+ "apiKey",
670
+ "apiEndpoint",
671
+ "timeout",
672
+ "maxRetries",
673
+ "circuitBreaker",
674
+ "preset",
675
+ "runtimeConfig",
676
+ "sentry",
677
+ "widget",
678
+ "capture",
679
+ "privacy",
680
+ "proactive",
681
+ "preFilter",
682
+ "integrations",
683
+ "offline",
684
+ "rewards",
685
+ "assistant",
686
+ "debug",
687
+ "enabled",
688
+ "appVersion",
689
+ "beforeSendFeedback",
690
+ "onCrashedLastRun"
691
+ ];
692
+ function presetDefaults(preset) {
693
+ switch (preset) {
694
+ case "manual-only":
695
+ return {
696
+ widget: { trigger: "manual", outdatedBanner: "console-only" },
697
+ capture: { console: true, network: true, performance: false, screenshot: "on-report", elementSelector: false },
698
+ proactive: { rageClick: false, longTask: false, apiCascade: false, errorBoundary: false }
699
+ };
700
+ case "beta-loud":
701
+ return {
702
+ widget: { trigger: "auto", outdatedBanner: "banner" },
703
+ capture: { console: true, network: true, performance: true, screenshot: "auto", elementSelector: true },
704
+ proactive: { rageClick: true, longTask: true, apiCascade: true, errorBoundary: true }
705
+ };
706
+ case "internal-debug":
707
+ return {
708
+ widget: { trigger: "auto", outdatedBanner: "banner", brandFooter: true },
709
+ capture: { console: true, network: true, performance: true, screenshot: "auto", elementSelector: true },
710
+ proactive: {
711
+ rageClick: true,
712
+ longTask: true,
713
+ apiCascade: true,
714
+ errorBoundary: true,
715
+ cooldown: { maxProactivePerSession: 10, dismissCooldownHours: 0, suppressAfterDismissals: 99 }
716
+ }
717
+ };
718
+ case "production-calm":
719
+ return {
720
+ widget: { trigger: "auto", outdatedBanner: "console-only" },
721
+ capture: { console: true, network: true, performance: false, screenshot: "on-report", elementSelector: false },
722
+ proactive: { rageClick: false, longTask: false, apiCascade: false, errorBoundary: false }
723
+ };
724
+ // Lean posture: widget on, console capture only, screenshot on-report,
725
+ // no network/performance/replay, no proactive nudges.
726
+ case "minimal":
727
+ return {
728
+ widget: { trigger: "auto" },
729
+ capture: {
730
+ console: true,
731
+ network: false,
732
+ performance: false,
733
+ screenshot: "on-report",
734
+ replay: "off",
735
+ elementSelector: false
736
+ },
737
+ proactive: { rageClick: false, longTask: false, apiCascade: false, errorBoundary: false }
738
+ };
739
+ // Everything-on posture: full capture (incl. self-contained `lite` replay)
740
+ // and every proactive trigger.
741
+ case "full":
742
+ return {
743
+ widget: { trigger: "auto" },
744
+ capture: {
745
+ console: true,
746
+ network: true,
747
+ performance: true,
748
+ screenshot: "auto",
749
+ replay: "lite",
750
+ elementSelector: true
751
+ },
752
+ proactive: { rageClick: true, longTask: true, apiCascade: true, errorBoundary: true }
753
+ };
754
+ // 'standard' and anything unrecognised → no expansion.
755
+ default:
756
+ return void 0;
757
+ }
758
+ }
759
+ function expandPreset(config) {
760
+ const defaults = presetDefaults(config.preset);
761
+ if (!defaults) return config;
762
+ return {
763
+ ...config,
764
+ widget: {
765
+ ...defaults.widget,
766
+ ...config.widget
767
+ },
768
+ capture: {
769
+ ...defaults.capture,
770
+ ...config.capture
771
+ },
772
+ proactive: {
773
+ ...defaults.proactive,
774
+ ...config.proactive,
775
+ cooldown: {
776
+ ...defaults.proactive?.cooldown,
777
+ ...config.proactive?.cooldown
778
+ }
779
+ }
780
+ };
781
+ }
782
+ function isSilenced() {
783
+ const truthy = (v) => v === "1" || v === "true";
784
+ try {
785
+ if (typeof process !== "undefined" && process.env && truthy(process.env.MUSHI_SILENT)) return true;
786
+ } catch {
787
+ }
788
+ try {
789
+ const env = import.meta.env;
790
+ if (env && typeof env === "object" && (truthy(env.MUSHI_SILENT) || truthy(env.VITE_MUSHI_SILENT))) return true;
791
+ } catch {
792
+ }
793
+ return false;
794
+ }
795
+ function validateConfig(config) {
796
+ try {
797
+ if (isSilenced()) return;
798
+ if (!config || typeof config !== "object") return;
799
+ const unknownKeys = Object.keys(config).filter((key) => !KNOWN_CONFIG_KEYS.includes(key));
800
+ if (unknownKeys.length > 0) {
801
+ console.error(
802
+ `[mushi] Unknown config key${unknownKeys.length > 1 ? "s" : ""}: ${unknownKeys.map((k) => `\`${k}\``).join(", ")} \u2014 check for typos (see MushiConfig). Ignored.`
803
+ );
804
+ }
805
+ if (config.preset !== void 0 && !KNOWN_PRESETS.includes(config.preset)) {
806
+ console.error(
807
+ `[mushi] Unknown preset \`${String(config.preset)}\` \u2014 expected one of ${KNOWN_PRESETS.map(
808
+ (p) => `'${p}'`
809
+ ).join(", ")}. Preset ignored.`
810
+ );
811
+ }
812
+ } catch {
813
+ }
814
+ }
602
815
 
603
816
  // src/pre-filter.ts
604
817
  var DEFAULT_MIN_LENGTH = 10;
@@ -1646,38 +1859,40 @@ function createRateLimiter(config = {}) {
1646
1859
  return { tryConsume, reset, availableTokens };
1647
1860
  }
1648
1861
 
1649
- // src/pii-scrubber.ts
1650
- var ORDERED_PATTERNS = [
1651
- { key: "ssns", regex: /\b\d{3}-\d{2}-\d{4}\b/g, replacement: "[REDACTED_SSN]" },
1652
- { key: "creditCards", regex: /\b(?:\d[ -]*){12,18}\d\b/g, replacement: "[REDACTED_CC]" },
1653
- // Vendor secret tokens — mirrors packages/server/.../pii-scrubber.ts exactly.
1654
- { key: "secretTokens", regex: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g, replacement: "[REDACTED_AWS_KEY]" },
1655
- { key: "secretTokens", regex: /(?:aws_secret_access_key|secret_access_key)["'\s:=]+[A-Za-z0-9/+=]{40}\b/gi, replacement: "aws_secret_access_key=[REDACTED_AWS_SECRET]" },
1656
- { key: "secretTokens", regex: /\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{24,}\b/g, replacement: "[REDACTED_STRIPE_KEY]" },
1657
- { key: "secretTokens", regex: /\bpk_(?:live|test)_[A-Za-z0-9]{24,}\b/g, replacement: "[REDACTED_STRIPE_PK]" },
1658
- { key: "secretTokens", regex: /\bxox[abpor]-[A-Za-z0-9-]{10,}\b/g, replacement: "[REDACTED_SLACK_TOKEN]" },
1659
- { key: "secretTokens", regex: /\bghp_[A-Za-z0-9]{36}\b/g, replacement: "[REDACTED_GITHUB_PAT]" },
1660
- { key: "secretTokens", regex: /\bgithub_pat_[A-Za-z0-9_]{80,}\b/g, replacement: "[REDACTED_GITHUB_PAT]" },
1661
- { key: "secretTokens", regex: /\bsk-(?:proj-)?[A-Za-z0-9_-]{20,}\b/g, replacement: "[REDACTED_OPENAI_KEY]" },
1662
- { key: "secretTokens", regex: /\bsk-ant-[A-Za-z0-9_-]{20,}\b/g, replacement: "[REDACTED_ANTHROPIC_KEY]" },
1663
- { key: "secretTokens", regex: /\bAIza[0-9A-Za-z_-]{35}\b/g, replacement: "[REDACTED_GOOGLE_KEY]" },
1664
- { key: "secretTokens", regex: /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, replacement: "[REDACTED_JWT]" },
1665
- { key: "emails", regex: /\b[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}\b/g, replacement: "[REDACTED_EMAIL]" },
1666
- { key: "phones", regex: /(?:\+\d{1,3}[\s.-])?\(?\d{2,4}\)?[\s.-]\d{3,4}[\s.-]\d{3,4}\b/g, replacement: "[REDACTED_PHONE]" },
1667
- { key: "ipAddresses", regex: /\b(?:\d{1,3}\.){3}\d{1,3}\b/g, replacement: "[REDACTED_IP]" },
1668
- { key: "ipv6", regex: /\b(?:[A-Fa-f0-9]{1,4}:){2,7}[A-Fa-f0-9]{0,4}\b/g, replacement: "[REDACTED_IPV6]" }
1669
- ];
1670
- var DEFAULT_CONFIG = {
1671
- emails: true,
1672
- phones: true,
1673
- creditCards: true,
1674
- ssns: true,
1675
- ipAddresses: false,
1676
- // Secret tokens default ON — if they leak into a bug report there's no
1677
- // good reason to ship them to our servers. Cheaper to scrub client-side.
1678
- secretTokens: true,
1679
- ipv6: false
1862
+ // src/pii-patterns.json
1863
+ var pii_patterns_default = {
1864
+ patterns: [
1865
+ { id: "ssn", configKey: "ssns", source: "\\b\\d{3}-\\d{2}-\\d{4}\\b", replacement: "[REDACTED_SSN]" },
1866
+ { id: "creditCard", configKey: "creditCards", source: "\\b(?:\\d[ -]*){12,18}\\d\\b", replacement: "[REDACTED_CC]" },
1867
+ { id: "awsAccessKey", configKey: "secretTokens", source: "\\b(?:AKIA|ASIA)[0-9A-Z]{16}\\b", replacement: "[REDACTED_AWS_KEY]" },
1868
+ { id: "awsSecretKey", configKey: "secretTokens", source: `(?:aws_secret_access_key|secret_access_key)["'\\s:=]+[A-Za-z0-9/+=]{40}\\b`, caseInsensitive: true, replacement: "aws_secret_access_key=[REDACTED_AWS_SECRET]" },
1869
+ { id: "stripeSecretKey", configKey: "secretTokens", source: "\\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{24,}\\b", replacement: "[REDACTED_STRIPE_KEY]" },
1870
+ { id: "stripePublishableKey", configKey: "secretTokens", source: "\\bpk_(?:live|test)_[A-Za-z0-9]{24,}\\b", replacement: "[REDACTED_STRIPE_PK]" },
1871
+ { id: "slackToken", configKey: "secretTokens", source: "\\bxox[abpor]-[A-Za-z0-9-]{10,}\\b", replacement: "[REDACTED_SLACK_TOKEN]" },
1872
+ { id: "githubPatClassic", configKey: "secretTokens", source: "\\bghp_[A-Za-z0-9]{36}\\b", replacement: "[REDACTED_GITHUB_PAT]" },
1873
+ { id: "githubPatFineGrained", configKey: "secretTokens", source: "\\bgithub_pat_[A-Za-z0-9_]{80,}\\b", replacement: "[REDACTED_GITHUB_PAT]" },
1874
+ { id: "openaiKey", configKey: "secretTokens", source: "\\bsk-(?:proj-)?[A-Za-z0-9_-]{20,}\\b", replacement: "[REDACTED_OPENAI_KEY]" },
1875
+ { id: "anthropicKey", configKey: "secretTokens", source: "\\bsk-ant-[A-Za-z0-9_-]{20,}\\b", replacement: "[REDACTED_ANTHROPIC_KEY]" },
1876
+ { id: "googleKey", configKey: "secretTokens", source: "\\bAIza[0-9A-Za-z_-]{35}\\b", replacement: "[REDACTED_GOOGLE_KEY]" },
1877
+ { id: "jwt", configKey: "secretTokens", source: "\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\b", replacement: "[REDACTED_JWT]" },
1878
+ { id: "email", configKey: "emails", source: "\\b[A-Za-z0-9._%+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}\\b", replacement: "[REDACTED_EMAIL]" },
1879
+ { id: "phone", configKey: "phones", source: "(?:\\+\\d{1,3}[\\s.-])?\\(?\\d{2,4}\\)?[\\s.-]\\d{3,4}[\\s.-]\\d{3,4}\\b", replacement: "[REDACTED_PHONE]" },
1880
+ { id: "ipv4", configKey: "ipAddresses", source: "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b", replacement: "[REDACTED_IP]", defaultOn: false },
1881
+ { id: "ipv6", configKey: "ipv6", source: "\\b(?:[A-Fa-f0-9]{1,4}:){2,7}[A-Fa-f0-9]{0,4}\\b", replacement: "[REDACTED_IPV6]", defaultOn: false }
1882
+ ]
1680
1883
  };
1884
+
1885
+ // src/pii-scrubber.ts
1886
+ var RAW_PATTERNS = pii_patterns_default.patterns;
1887
+ var ORDERED_PATTERNS = RAW_PATTERNS.map((p) => ({
1888
+ key: p.configKey,
1889
+ regex: new RegExp(p.source, p.caseInsensitive ? "gi" : "g"),
1890
+ replacement: p.replacement
1891
+ }));
1892
+ var DEFAULT_CONFIG = RAW_PATTERNS.reduce((acc, p) => {
1893
+ acc[p.configKey] = p.defaultOn !== false;
1894
+ return acc;
1895
+ }, {});
1681
1896
  function createPiiScrubber(config = {}) {
1682
1897
  const merged = { ...DEFAULT_CONFIG, ...config };
1683
1898
  const activePatterns = ORDERED_PATTERNS.filter((p) => merged[p.key]);
@@ -2162,6 +2377,6 @@ function isSafeFaviconHref(href) {
2162
2377
  }
2163
2378
  }
2164
2379
 
2165
- export { DEFAULT_API_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT, 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, REGION_ENDPOINTS, 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 };
2380
+ export { DEFAULT_API_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT, 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, REGION_ENDPOINTS, buildIdentityClaims, buildSdkIngestHeaders, captureEnvironment, checkReportPayloadSize, createApiClient, createBreadcrumbBuffer, createLogger, createOfflineQueue, createPiiScrubber, createPreFilter, createRateLimiter, diagnoseEnvConfig, estimateJsonBytes, expandPreset, 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, validateConfig };
2166
2381
  //# sourceMappingURL=index.js.map
2167
2382
  //# sourceMappingURL=index.js.map