@mushi-mushi/core 0.9.0 → 1.0.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/README.md +7 -1
- package/SECURITY.md +167 -4
- package/dist/index.cjs +197 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +350 -1
- package/dist/index.d.ts +350 -1
- package/dist/index.js +196 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,10 +10,12 @@ Core types, API client, and utilities for the Mushi Mushi SDK.
|
|
|
10
10
|
- **API Client**: Fetch-based HTTP client with retry and exponential backoff. Tags every internal request with `X-Mushi-Internal: <kind>` so framework SDKs can filter their own traffic out of network capture and `apiCascade`. Ships HMAC-signed reporter helpers (`getLatestSdkVersion`, `listReporterReports`, `listReporterComments`, `replyToReporterReport`) for the two-way reply pipeline, plus `postDiscoveryEvent` (v2.1) for the passive inventory channel
|
|
11
11
|
- **Pre-Filter**: On-device Stage 0 spam/gibberish filter (runs client-side, zero server cost)
|
|
12
12
|
- **Offline Queue**: IndexedDB-backed queue with auto-sync on reconnect
|
|
13
|
-
- **Environment Capture**: Browser/device snapshot
|
|
13
|
+
- **Environment Capture**: Browser/device snapshot — viewport, user agent (with **User-Agent Client Hints** when supported), connection info, screen + DPR, accessibility prefs (`prefers-reduced-motion`, `prefers-color-scheme`, `prefers-contrast`), online/displayMode/title, and a one-shot **page load timing** read from `PerformanceNavigationTiming` (TTFB, DOMContentLoaded, FCP, LCP)
|
|
14
14
|
- **Reporter Token**: Anonymous persistent identity for report attribution
|
|
15
15
|
- **Session ID**: Tab-scoped session correlation
|
|
16
16
|
- **Rate Limiter**: Token bucket self-throttle to prevent API flooding
|
|
17
|
+
- **Breadcrumb Buffer** (1.0+ — `createBreadcrumbBuffer`): 50-entry ring of `{timestamp, category, level, message, data?}` rows; framework SDKs auto-capture route changes, `console.error/warn`, `[data-testid]` clicks, and SDK lifecycle events. Snapshot is attached to every `MushiReport` (server promotes it to a dedicated `reports.breadcrumbs` jsonb column for GIN-indexed filtering)
|
|
18
|
+
- **Exception Normaliser** (1.0+ — `normaliseThrown`): turns any thrown value (`Error`, string, plain object, `null`, `undefined`) into a stable `{ name, message, stack?, cause? }` shape with truncated stacks and cyclic-cause guards. Powers `Mushi.captureException()` in `@mushi-mushi/web`
|
|
17
19
|
|
|
18
20
|
## Public types added in 0.7 → 0.11
|
|
19
21
|
|
|
@@ -31,6 +33,10 @@ Core types, API client, and utilities for the Mushi Mushi SDK.
|
|
|
31
33
|
| `MushiReporterComment` | Reporter-facing comment row (HMAC-authed) tagged `author_kind: 'admin' \| 'reporter'`. |
|
|
32
34
|
| `MushiDiscoverInventoryConfig` | Mushi v2.1 — fine-grained controls for `capture.discoverInventory` (`enabled`, `throttleMs`, `routeTemplates`, `userIdSource`, `captureDomSummary`). Pass `true` for defaults. |
|
|
33
35
|
| `MushiDiscoveryEventPayload` | Mushi v2.1 — wire shape for `POST /v1/sdk/discovery`. Mirrored server-side by `_shared/schemas.ts::discoveryEventSchema`; route + page title + testids + network paths + query-param **keys only** + sha256 user id hash. |
|
|
36
|
+
| `MushiBreadcrumb` | 1.0+ — `{ timestamp, category, level: 'debug' \| 'info' \| 'warning' \| 'error' \| 'critical', message, data? }`. Mirrors the Sentry breadcrumb shape so the admin can interleave Mushi + Sentry breadcrumbs on one timeline. |
|
|
37
|
+
| `MushiSentryContext` | 1.0+ — rich Sentry handshake the SDK captures via `@sentry/browser` v7/v8/v9: `eventId`, `replayId`, `traceId`, `spanId`, `transaction`, `release`, `environment`, `user`, `tags`, `breadcrumbs`, `issueUrl`, `mushiReportId` (bidirectional). |
|
|
38
|
+
| `MushiCaptureExceptionOptions` | 1.0+ — options for `Mushi.captureException(err, opts)`: `level`, `tags`, `extras`, `category`, `userIntent` overrides for the structured report. |
|
|
39
|
+
| `NormalisedException` | 1.0+ — return type of `normaliseThrown(err)` (`{ name, message, stack?, cause? }`); used internally by `captureException` and exposed for adapters that want to ship their own thin wrappers. |
|
|
34
40
|
|
|
35
41
|
Constants: `MUSHI_INTERNAL_HEADER` (`'X-Mushi-Internal'`),
|
|
36
42
|
`MUSHI_INTERNAL_INIT_MARKER`, and the `MushiInternalRequestKind` literal union
|
package/SECURITY.md
CHANGED
|
@@ -19,15 +19,59 @@ If you discover a security vulnerability, please report it responsibly.
|
|
|
19
19
|
|
|
20
20
|
**Do NOT open a public GitHub issue.**
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Use either channel below:
|
|
23
|
+
|
|
24
|
+
1. **GitHub Private Vulnerability Reporting** — strongly preferred.
|
|
25
|
+
<https://github.com/kensaurus/mushi-mushi/security/advisories/new>
|
|
26
|
+
Routes the report into a private advisory with built-in CVE issuance,
|
|
27
|
+
patch coordination, and contributor-credit workflow.
|
|
28
|
+
2. **Email** — `kensaurus@gmail.com`, subject prefix `[mushi-security]`.
|
|
29
|
+
PGP welcome but not required.
|
|
23
30
|
|
|
24
31
|
Include:
|
|
25
32
|
- Description of the vulnerability
|
|
26
|
-
- Steps to reproduce
|
|
27
|
-
- Impact assessment
|
|
33
|
+
- Steps to reproduce (smallest reproducer wins)
|
|
34
|
+
- Impact assessment (what an attacker gains)
|
|
28
35
|
- Suggested fix (if any)
|
|
36
|
+
- Whether you want public credit (and how to spell your name)
|
|
37
|
+
|
|
38
|
+
### Coordinated-disclosure timeline
|
|
39
|
+
|
|
40
|
+
| Day | Action |
|
|
41
|
+
|-----|--------|
|
|
42
|
+
| 0 | Report received |
|
|
43
|
+
| ≤ 2 | Acknowledgment + assigned a tracking ID |
|
|
44
|
+
| ≤ 7 | Triage complete: severity assigned (CVSS 3.1) and target patch date communicated |
|
|
45
|
+
| ≤ 30 | Patch released for critical / high (CVSS ≥ 7.0); ≤ 60 days for medium; best-effort for low |
|
|
46
|
+
| Patch + 7 | Public advisory + CVE published; reporter credited unless they declined |
|
|
47
|
+
| Patch + 90 | Embargo expires regardless; if upstream is unresponsive, the reporter is free to publish |
|
|
48
|
+
|
|
49
|
+
### Safe harbor
|
|
50
|
+
|
|
51
|
+
Good-faith security research on Mushi Mushi is welcome. If you stay
|
|
52
|
+
within the rules below, we will not pursue legal action, will not ask
|
|
53
|
+
your hosting provider to take you offline, and will publicly credit your
|
|
54
|
+
work:
|
|
55
|
+
|
|
56
|
+
- Test only against your own self-hosted instance, the public demo at
|
|
57
|
+
<https://kensaur.us/mushi-mushi/admin/>, or accounts you own.
|
|
58
|
+
- Do not access, exfiltrate, or modify data belonging to other users.
|
|
59
|
+
- Do not run automated scanning that affects availability for others
|
|
60
|
+
(rate-limit your tooling, exclude `/health`).
|
|
61
|
+
- Disclose privately first (channels above); do not publish before the
|
|
62
|
+
embargo above expires.
|
|
63
|
+
- Do not intentionally exploit a finding to escalate beyond proving it
|
|
64
|
+
exists.
|
|
65
|
+
|
|
66
|
+
If a finding requires touching production data to confirm, **stop and
|
|
67
|
+
ask first** — describe what you'd need to do and we'll spin up a sandbox.
|
|
68
|
+
|
|
69
|
+
### Hall of fame
|
|
29
70
|
|
|
30
|
-
|
|
71
|
+
Researchers who report a confirmed vulnerability are credited in the
|
|
72
|
+
release notes for the patched version and added to
|
|
73
|
+
[`docs/SECURITY_HALL_OF_FAME.md`](./docs/SECURITY_HALL_OF_FAME.md) (with
|
|
74
|
+
permission).
|
|
31
75
|
|
|
32
76
|
## Scope
|
|
33
77
|
|
|
@@ -48,6 +92,125 @@ We will acknowledge receipt within 48 hours and aim to release a patch within 7
|
|
|
48
92
|
- **Rotate API keys** regularly via the admin console
|
|
49
93
|
- **Enable SSO** for team projects (Enterprise tier)
|
|
50
94
|
- **Review audit logs** periodically for suspicious activity
|
|
95
|
+
- **Verify SDK integrity** with `npm audit signatures` after install
|
|
96
|
+
- **Set `Content-Security-Policy`** on any page embedding the Mushi widget;
|
|
97
|
+
the widget itself ships with `script-src 'self'` and does not load
|
|
98
|
+
remote scripts.
|
|
99
|
+
|
|
100
|
+
## Threat model
|
|
101
|
+
|
|
102
|
+
What we treat as in-scope attacker capabilities, and what we don't.
|
|
103
|
+
|
|
104
|
+
| Capability | In scope | Notes |
|
|
105
|
+
|-----------|----------|-------|
|
|
106
|
+
| Unauthenticated network attacker hitting public endpoints | ✅ | Rate-limit + HMAC + replay protection on every webhook endpoint (`packages/server/supabase/functions/_shared/webhook-middleware.ts`). |
|
|
107
|
+
| Authenticated user trying to read another tenant's data | ✅ | Postgres RLS on every `public.*` table; advisor lints reviewed monthly. |
|
|
108
|
+
| Authenticated user trying to escalate to super-admin | ✅ | Role lives in `auth.users.raw_app_meta_data.role`; cannot be self-edited via PostgREST. |
|
|
109
|
+
| Compromised dependency (npm supply-chain attack) | ✅ | 7-day cooldown + provenance + Harden-Runner + pinned SHAs (see "Supply-chain hardening" below). |
|
|
110
|
+
| Stolen API key | ✅ | Per-key scopes (`api_key_has_scope`), revocation via admin console, audit log of every use. |
|
|
111
|
+
| User pasting a Stripe / OpenAI / GitHub PAT into a bug report | ✅ | PII scrubber redacts ~15 vendor token formats client-side before the report leaves the device. Mirrors `packages/core/src/pii-scrubber.ts` across iOS, Android, Flutter, React Native. |
|
|
112
|
+
| Stolen end-user device with the SDK installed | ⚠️ partial | Offline queue is AsyncStorage / Keychain / SharedPreferences — no app-level encryption beyond the OS default. Reports waiting to flush are vulnerable to a forensic attacker. |
|
|
113
|
+
| Compromised Supabase service-role key | ❌ | Treated as a tier-0 incident; would require key rotation and audit-log forensics. Not defendable in software. |
|
|
114
|
+
| Compromise of `kensaurus@gmail.com` | ❌ | Treated as a project-fork event; downstream consumers should pin to the last known-good version and follow the new release channel. |
|
|
115
|
+
| Physical / OS-level attacker on an end-user device | ❌ | Out of scope. |
|
|
116
|
+
| Malicious fork using the Mushi name to ship malware | ❌ (technical) ✅ (legal) | The MIT/BSL grant lets the fork exist; the trademark policy (`TRADEMARK.md`) makes shipping it under the Mushi name an infringement we will pursue. |
|
|
117
|
+
|
|
118
|
+
## Data handling and PII
|
|
119
|
+
|
|
120
|
+
### What the SDK collects by default
|
|
121
|
+
|
|
122
|
+
| Field | Scope | PII risk |
|
|
123
|
+
|-------|-------|----------|
|
|
124
|
+
| URL / route the user was on | Always | Low — strip query strings if your routes encode user IDs. |
|
|
125
|
+
| Browser / OS / device | Always | None |
|
|
126
|
+
| Console errors (last 50) | Opt-in via `captureConsole: true` | Medium — can include user data your code logs. |
|
|
127
|
+
| Network failures (URL + status) | Opt-in via `captureNetwork: true` | Medium — query params logged as-is unless you redact in-app. |
|
|
128
|
+
| User id / email / role | Only if you call `setUser()` | High — only set what you need; we do not auto-discover. |
|
|
129
|
+
| Session replay frames | Off by default | High — handled by the masking layer; passwords / cards / opted-out elements never leave the page. |
|
|
130
|
+
| Free-text bug description | Always | Medium — passed through the PII scrubber (see below). |
|
|
131
|
+
|
|
132
|
+
### What the PII scrubber redacts before send
|
|
133
|
+
|
|
134
|
+
Implemented identically across `@mushi-mushi/core`, the iOS, Android,
|
|
135
|
+
Flutter, and React Native SDKs. Defaults are below — every category can
|
|
136
|
+
be toggled off, but `secretTokens` is on by default and we recommend
|
|
137
|
+
keeping it that way.
|
|
138
|
+
|
|
139
|
+
| Category | Default | Patterns |
|
|
140
|
+
|----------|---------|----------|
|
|
141
|
+
| `ssns` | on | `123-45-6789` |
|
|
142
|
+
| `creditCards` | on | 12–19 digit Luhn-shaped sequences with optional separators |
|
|
143
|
+
| `secretTokens` | on | AWS access key (`AKIA…` / `ASIA…`), AWS secret (`aws_secret_access_key=…`), Stripe (`sk_live_…`, `sk_test_…`, `rk_…`, `pk_…`), Slack (`xox[abpor]-…`), GitHub PAT (`ghp_…`, `github_pat_…`), OpenAI (`sk-…`, `sk-proj-…`), Anthropic (`sk-ant-…`), Google API (`AIza…`), JWT (`eyJ…` 3-segment) |
|
|
144
|
+
| `emails` | on | RFC-5322 lite |
|
|
145
|
+
| `phones` | on | E.164 with optional country code |
|
|
146
|
+
| `ipAddresses` | off | IPv4 (off because internal IPs are usually not PII and noise hurts triage) |
|
|
147
|
+
| `ipv6` | off | Same |
|
|
148
|
+
|
|
149
|
+
The fields scrubbed are:
|
|
150
|
+
|
|
151
|
+
- `description` — primary free-text field of every bug report
|
|
152
|
+
- `summary` — short summary, in the same composer
|
|
153
|
+
- `breadcrumbs[].message` — auto-captured user-action trail (clicks, route changes, console messages)
|
|
154
|
+
|
|
155
|
+
Structured fields you set explicitly (`metadata.userEmail`,
|
|
156
|
+
`metadata.userId`, etc.) are intentionally **not** scrubbed — those are
|
|
157
|
+
opt-in attribution data, and silently rewriting them would break
|
|
158
|
+
support workflows.
|
|
159
|
+
|
|
160
|
+
### Where data lives
|
|
161
|
+
|
|
162
|
+
- **Reports & telemetry** — Supabase Postgres in the `us-west-1` region.
|
|
163
|
+
- **Session replays** — Supabase Storage, same region. Lifecycle policy
|
|
164
|
+
trims replays older than 30 days unless explicitly retained from the
|
|
165
|
+
admin console.
|
|
166
|
+
- **Inbound webhook bodies** — only a SHA-256 hash + `delivery_id` of
|
|
167
|
+
the body is persisted (`webhook_audit_log`). The full body is
|
|
168
|
+
processed in memory and discarded.
|
|
169
|
+
- **Outbound integrations** (Slack, Jira, …) — Mushi is a sender only;
|
|
170
|
+
the receiving system's retention applies.
|
|
171
|
+
|
|
172
|
+
### Encryption
|
|
173
|
+
|
|
174
|
+
| Surface | At rest | In transit |
|
|
175
|
+
|---------|---------|------------|
|
|
176
|
+
| Postgres (Supabase) | AES-256 (Supabase default) | TLS 1.2+ |
|
|
177
|
+
| Supabase Storage (replays) | AES-256 | TLS 1.2+ |
|
|
178
|
+
| Edge Function ↔ Postgres | — | TLS via the Supavisor pooler |
|
|
179
|
+
| SDK ↔ ingest endpoint | — | TLS 1.2+ enforced; HSTS preload on `kensaur.us` |
|
|
180
|
+
| Inbound webhooks | — | TLS terminated at CloudFront / Supabase edge |
|
|
181
|
+
| Audit log integrity | append-only by RLS; no in-row signing | — |
|
|
182
|
+
|
|
183
|
+
### Cryptographic primitives
|
|
184
|
+
|
|
185
|
+
| Use | Algorithm | Implementation |
|
|
186
|
+
|-----|-----------|---------------|
|
|
187
|
+
| Webhook HMAC verification (Sentry, GitHub, Datadog, Honeycomb, Grafana, Bugsnag, Rollbar, Crashlytics) | HMAC-SHA256, constant-time compare | Web Crypto in Deno; `crypto.subtle.timingSafeEqual` analogue |
|
|
188
|
+
| AWS SNS subscription confirmation | RSA-SHA1 / RSA-SHA256 | Deno `crypto.subtle.verify` with the cert from `SigningCertURL` (URL allow-listed to `*.sns.*.amazonaws.com`) |
|
|
189
|
+
| Opsgenie JWT shared-token | HS256 with `aud` claim verification | `jose` (Deno-compatible) |
|
|
190
|
+
| API-key hashing (database) | SHA-256 prefix + bcrypt secret half | `pgcrypto` |
|
|
191
|
+
| Provenance attestations (npm) | Sigstore (Fulcio + Rekor) | `npm publish --provenance` |
|
|
192
|
+
|
|
193
|
+
We deliberately do not roll our own crypto. If you find an algorithm or
|
|
194
|
+
library above that has been deprecated, please file a security advisory.
|
|
195
|
+
|
|
196
|
+
### Operator security checklist
|
|
197
|
+
|
|
198
|
+
When you provision a new self-hosted Mushi instance:
|
|
199
|
+
|
|
200
|
+
- [ ] Set `auth_leaked_password_protection = true` in Supabase Auth
|
|
201
|
+
(HaveIBeenPwned blocklist; flagged as `auth_leaked_password_protection`
|
|
202
|
+
in the security advisor).
|
|
203
|
+
- [ ] Enable at least two MFA factors in Supabase Auth (`auth_insufficient_mfa_options`).
|
|
204
|
+
- [ ] Rotate the service-role key on day 1, then quarterly.
|
|
205
|
+
- [ ] Restrict Postgres direct connections to your CI / migration runners
|
|
206
|
+
via Supabase network restrictions.
|
|
207
|
+
- [ ] Run `pnpm dlx supabase advisors --project-ref <ref>` after every
|
|
208
|
+
migration; aim for zero ERROR-level findings.
|
|
209
|
+
- [ ] Configure a Supabase log drain to your SIEM if you are subject to
|
|
210
|
+
SOC 2 / ISO 27001.
|
|
211
|
+
- [ ] Set CSP `frame-ancestors` on the host page if you embed the Mushi
|
|
212
|
+
widget (the widget is iframe-friendly but does not enforce
|
|
213
|
+
framing constraints itself).
|
|
51
214
|
|
|
52
215
|
## Supply-chain hardening (how this package is protected)
|
|
53
216
|
|
package/dist/index.cjs
CHANGED
|
@@ -785,6 +785,8 @@ function captureEnvironment() {
|
|
|
785
785
|
const nav = typeof navigator !== "undefined" ? navigator : void 0;
|
|
786
786
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
787
787
|
const doc = typeof document !== "undefined" ? document : void 0;
|
|
788
|
+
const scr = typeof screen !== "undefined" ? screen : void 0;
|
|
789
|
+
void kickOffUserAgentData(nav);
|
|
788
790
|
const connection = nav && "connection" in nav ? nav.connection : void 0;
|
|
789
791
|
return {
|
|
790
792
|
userAgent: nav?.userAgent ?? "unknown",
|
|
@@ -806,7 +808,19 @@ function captureEnvironment() {
|
|
|
806
808
|
deviceMemory: nav?.deviceMemory,
|
|
807
809
|
hardwareConcurrency: nav?.hardwareConcurrency,
|
|
808
810
|
route: win?.location?.pathname,
|
|
809
|
-
nearestTestid: findNearestTestidFromActive(doc)
|
|
811
|
+
nearestTestid: findNearestTestidFromActive(doc),
|
|
812
|
+
userAgentData: captureUserAgentData(nav),
|
|
813
|
+
screen: captureScreen(scr, win),
|
|
814
|
+
prefersColorScheme: matchScheme(win),
|
|
815
|
+
prefersReducedMotion: matchMedia(win, "(prefers-reduced-motion: reduce)"),
|
|
816
|
+
prefersReducedData: matchMedia(win, "(prefers-reduced-data: reduce)"),
|
|
817
|
+
prefersContrast: matchContrast(win),
|
|
818
|
+
forcedColors: matchMedia(win, "(forced-colors: active)"),
|
|
819
|
+
online: typeof nav?.onLine === "boolean" ? nav.onLine : void 0,
|
|
820
|
+
displayMode: matchDisplayMode(win),
|
|
821
|
+
documentTitle: doc?.title?.slice(0, 200),
|
|
822
|
+
buildId: readBuildIdMeta(doc),
|
|
823
|
+
pageLoadTiming: capturePageLoadTiming(win)
|
|
810
824
|
};
|
|
811
825
|
}
|
|
812
826
|
function findNearestTestidFromActive(doc) {
|
|
@@ -821,6 +835,117 @@ function findNearestTestidFromActive(doc) {
|
|
|
821
835
|
}
|
|
822
836
|
return void 0;
|
|
823
837
|
}
|
|
838
|
+
var cachedHighEntropy = null;
|
|
839
|
+
var highEntropyKickedOff = false;
|
|
840
|
+
function kickOffUserAgentData(nav) {
|
|
841
|
+
if (highEntropyKickedOff) return;
|
|
842
|
+
const ua = nav?.userAgentData;
|
|
843
|
+
if (!ua?.getHighEntropyValues) return;
|
|
844
|
+
highEntropyKickedOff = true;
|
|
845
|
+
ua.getHighEntropyValues([
|
|
846
|
+
"architecture",
|
|
847
|
+
"bitness",
|
|
848
|
+
"model",
|
|
849
|
+
"platformVersion",
|
|
850
|
+
"uaFullVersion",
|
|
851
|
+
"fullVersionList"
|
|
852
|
+
]).then((v) => {
|
|
853
|
+
cachedHighEntropy = v;
|
|
854
|
+
}).catch(() => {
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
function pickBrand(brands) {
|
|
858
|
+
if (!brands?.length) return void 0;
|
|
859
|
+
const real = brands.filter((b) => !/not.?a.?brand/i.test(b.brand));
|
|
860
|
+
if (real.length === 0) return void 0;
|
|
861
|
+
const named = real.find((b) => !/chromium|google chrome/i.test(b.brand));
|
|
862
|
+
return named ?? real[0];
|
|
863
|
+
}
|
|
864
|
+
function captureUserAgentData(nav) {
|
|
865
|
+
const low = nav?.userAgentData;
|
|
866
|
+
if (!low && !cachedHighEntropy) return void 0;
|
|
867
|
+
const fullList = cachedHighEntropy?.fullVersionList;
|
|
868
|
+
const brand = pickBrand(fullList ?? low?.brands);
|
|
869
|
+
const out = {};
|
|
870
|
+
if (brand) {
|
|
871
|
+
out.browser = brand.brand;
|
|
872
|
+
out.browserVersion = brand.version;
|
|
873
|
+
}
|
|
874
|
+
if (low?.platform) out.os = low.platform;
|
|
875
|
+
if (cachedHighEntropy?.platformVersion) out.osVersion = cachedHighEntropy.platformVersion;
|
|
876
|
+
if (typeof low?.mobile === "boolean") out.mobile = low.mobile;
|
|
877
|
+
if (cachedHighEntropy?.model) out.model = cachedHighEntropy.model;
|
|
878
|
+
if (cachedHighEntropy?.architecture) out.architecture = cachedHighEntropy.architecture;
|
|
879
|
+
if (cachedHighEntropy?.bitness) out.bitness = cachedHighEntropy.bitness;
|
|
880
|
+
return Object.keys(out).length === 0 ? void 0 : out;
|
|
881
|
+
}
|
|
882
|
+
function captureScreen(scr, win) {
|
|
883
|
+
if (!scr && !win) return void 0;
|
|
884
|
+
const out = {};
|
|
885
|
+
if (typeof scr?.width === "number") out.width = scr.width;
|
|
886
|
+
if (typeof scr?.height === "number") out.height = scr.height;
|
|
887
|
+
if (typeof win?.devicePixelRatio === "number") out.devicePixelRatio = win.devicePixelRatio;
|
|
888
|
+
if (typeof scr?.colorDepth === "number") out.colorDepth = scr.colorDepth;
|
|
889
|
+
const orientationType = scr?.orientation?.type;
|
|
890
|
+
if (orientationType) out.orientation = orientationType;
|
|
891
|
+
return Object.keys(out).length === 0 ? void 0 : out;
|
|
892
|
+
}
|
|
893
|
+
function matchMedia(win, query) {
|
|
894
|
+
if (!win?.matchMedia) return void 0;
|
|
895
|
+
try {
|
|
896
|
+
return win.matchMedia(query).matches;
|
|
897
|
+
} catch {
|
|
898
|
+
return void 0;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function matchScheme(win) {
|
|
902
|
+
if (!win?.matchMedia) return void 0;
|
|
903
|
+
if (matchMedia(win, "(prefers-color-scheme: dark)")) return "dark";
|
|
904
|
+
if (matchMedia(win, "(prefers-color-scheme: light)")) return "light";
|
|
905
|
+
return "no-preference";
|
|
906
|
+
}
|
|
907
|
+
function matchContrast(win) {
|
|
908
|
+
if (!win?.matchMedia) return void 0;
|
|
909
|
+
if (matchMedia(win, "(prefers-contrast: more)")) return "more";
|
|
910
|
+
if (matchMedia(win, "(prefers-contrast: less)")) return "less";
|
|
911
|
+
if (matchMedia(win, "(prefers-contrast: custom)")) return "custom";
|
|
912
|
+
return "no-preference";
|
|
913
|
+
}
|
|
914
|
+
function matchDisplayMode(win) {
|
|
915
|
+
if (!win?.matchMedia) return void 0;
|
|
916
|
+
if (matchMedia(win, "(display-mode: fullscreen)")) return "fullscreen";
|
|
917
|
+
if (matchMedia(win, "(display-mode: standalone)")) return "standalone";
|
|
918
|
+
if (matchMedia(win, "(display-mode: minimal-ui)")) return "minimal-ui";
|
|
919
|
+
if (matchMedia(win, "(display-mode: browser)")) return "browser";
|
|
920
|
+
return void 0;
|
|
921
|
+
}
|
|
922
|
+
function readBuildIdMeta(doc) {
|
|
923
|
+
if (!doc) return void 0;
|
|
924
|
+
const el = doc.querySelector?.('meta[name="mushi:build"]');
|
|
925
|
+
const v = el?.content?.trim();
|
|
926
|
+
if (!v) return void 0;
|
|
927
|
+
return v.slice(0, 64);
|
|
928
|
+
}
|
|
929
|
+
function capturePageLoadTiming(win) {
|
|
930
|
+
const perf = win?.performance;
|
|
931
|
+
if (!perf?.getEntriesByType) return void 0;
|
|
932
|
+
let entry;
|
|
933
|
+
try {
|
|
934
|
+
const entries = perf.getEntriesByType("navigation");
|
|
935
|
+
entry = entries[0];
|
|
936
|
+
} catch {
|
|
937
|
+
return void 0;
|
|
938
|
+
}
|
|
939
|
+
if (!entry) return void 0;
|
|
940
|
+
const start = entry.startTime ?? 0;
|
|
941
|
+
const out = {};
|
|
942
|
+
if (entry.domContentLoadedEventEnd > 0)
|
|
943
|
+
out.domContentLoadedMs = Math.round(entry.domContentLoadedEventEnd - start);
|
|
944
|
+
if (entry.loadEventEnd > 0) out.loadCompleteMs = Math.round(entry.loadEventEnd - start);
|
|
945
|
+
if (entry.responseStart > 0) out.timeToFirstByteMs = Math.round(entry.responseStart - start);
|
|
946
|
+
if (typeof entry.type === "string") out.navigationType = entry.type;
|
|
947
|
+
return Object.keys(out).length === 0 ? void 0 : out;
|
|
948
|
+
}
|
|
824
949
|
|
|
825
950
|
// src/reporter-token.ts
|
|
826
951
|
var STORAGE_KEY = "mushi_reporter_token";
|
|
@@ -1028,12 +1153,82 @@ function scrubPii(text, config) {
|
|
|
1028
1153
|
return createPiiScrubber(config).scrub(text);
|
|
1029
1154
|
}
|
|
1030
1155
|
|
|
1156
|
+
// src/breadcrumbs.ts
|
|
1157
|
+
var DEFAULT_MAX = 50;
|
|
1158
|
+
var DEFAULT_MAX_MESSAGE = 500;
|
|
1159
|
+
function createBreadcrumbBuffer(options = {}) {
|
|
1160
|
+
const max = Math.max(1, options.max ?? DEFAULT_MAX);
|
|
1161
|
+
const maxMsg = Math.max(50, options.maxMessageLength ?? DEFAULT_MAX_MESSAGE);
|
|
1162
|
+
let entries = [];
|
|
1163
|
+
return {
|
|
1164
|
+
add(input) {
|
|
1165
|
+
const ts = typeof input.timestamp === "number" ? input.timestamp : Date.now();
|
|
1166
|
+
const message = typeof input.message === "string" && input.message.length > maxMsg ? `${input.message.slice(0, maxMsg)}\u2026` : input.message;
|
|
1167
|
+
const crumb = {
|
|
1168
|
+
timestamp: ts,
|
|
1169
|
+
category: input.category,
|
|
1170
|
+
level: input.level ?? "info",
|
|
1171
|
+
message: message ?? "",
|
|
1172
|
+
...input.data ? { data: input.data } : {}
|
|
1173
|
+
};
|
|
1174
|
+
entries.push(crumb);
|
|
1175
|
+
while (entries.length > max) entries.shift();
|
|
1176
|
+
},
|
|
1177
|
+
getAll() {
|
|
1178
|
+
return entries.slice();
|
|
1179
|
+
},
|
|
1180
|
+
clear() {
|
|
1181
|
+
entries = [];
|
|
1182
|
+
},
|
|
1183
|
+
size() {
|
|
1184
|
+
return entries.length;
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
// src/exception-normaliser.ts
|
|
1190
|
+
var STACK_LIMIT = 8 * 1024;
|
|
1191
|
+
var FALLBACK_JSON_LIMIT = 1e3;
|
|
1192
|
+
function normaliseThrown(thrown) {
|
|
1193
|
+
if (thrown instanceof Error) {
|
|
1194
|
+
const name = thrown.name || "Error";
|
|
1195
|
+
const message = thrown.message || String(thrown);
|
|
1196
|
+
const stack = typeof thrown.stack === "string" && thrown.stack.length > 0 ? thrown.stack.slice(0, STACK_LIMIT) : void 0;
|
|
1197
|
+
const cause = thrown.cause;
|
|
1198
|
+
return {
|
|
1199
|
+
name,
|
|
1200
|
+
message,
|
|
1201
|
+
...stack ? { stack } : {},
|
|
1202
|
+
...cause !== void 0 ? { cause: cause instanceof Error ? cause.message : cause } : {}
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
if (typeof thrown === "string") {
|
|
1206
|
+
return { name: "Error", message: thrown };
|
|
1207
|
+
}
|
|
1208
|
+
if (thrown && typeof thrown === "object") {
|
|
1209
|
+
const obj = thrown;
|
|
1210
|
+
const name = typeof obj.name === "string" ? obj.name : "Error";
|
|
1211
|
+
const message = typeof obj.message === "string" ? obj.message : (() => {
|
|
1212
|
+
try {
|
|
1213
|
+
return JSON.stringify(obj).slice(0, FALLBACK_JSON_LIMIT);
|
|
1214
|
+
} catch {
|
|
1215
|
+
return String(obj);
|
|
1216
|
+
}
|
|
1217
|
+
})();
|
|
1218
|
+
const stack = typeof obj.stack === "string" ? obj.stack.slice(0, STACK_LIMIT) : void 0;
|
|
1219
|
+
return { name, message, ...stack ? { stack } : {} };
|
|
1220
|
+
}
|
|
1221
|
+
if (thrown === void 0) return { name: "Error", message: "unknown" };
|
|
1222
|
+
return { name: "Error", message: String(thrown) };
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1031
1225
|
exports.DEFAULT_API_ENDPOINT = DEFAULT_API_ENDPOINT;
|
|
1032
1226
|
exports.MUSHI_INTERNAL_HEADER = MUSHI_INTERNAL_HEADER;
|
|
1033
1227
|
exports.MUSHI_INTERNAL_INIT_MARKER = MUSHI_INTERNAL_INIT_MARKER;
|
|
1034
1228
|
exports.REGION_ENDPOINTS = REGION_ENDPOINTS;
|
|
1035
1229
|
exports.captureEnvironment = captureEnvironment;
|
|
1036
1230
|
exports.createApiClient = createApiClient;
|
|
1231
|
+
exports.createBreadcrumbBuffer = createBreadcrumbBuffer;
|
|
1037
1232
|
exports.createLogger = createLogger;
|
|
1038
1233
|
exports.createOfflineQueue = createOfflineQueue;
|
|
1039
1234
|
exports.createPiiScrubber = createPiiScrubber;
|
|
@@ -1043,6 +1238,7 @@ exports.getDeviceFingerprintHash = getDeviceFingerprintHash;
|
|
|
1043
1238
|
exports.getReporterToken = getReporterToken;
|
|
1044
1239
|
exports.getSessionId = getSessionId;
|
|
1045
1240
|
exports.noopLogger = noopLogger;
|
|
1241
|
+
exports.normaliseThrown = normaliseThrown;
|
|
1046
1242
|
exports.resolveRegionEndpoint = resolveRegionEndpoint;
|
|
1047
1243
|
exports.scrubPii = scrubPii;
|
|
1048
1244
|
//# sourceMappingURL=index.cjs.map
|