@mushi-mushi/core 1.35.0 → 1.37.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/diagnostics.cjs +115 -0
- package/dist/diagnostics.cjs.map +1 -0
- package/dist/diagnostics.d.cts +29 -0
- package/dist/diagnostics.d.ts +29 -0
- package/dist/diagnostics.js +112 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/reporter-channels.d.cts +1 -1
- package/dist/reporter-channels.d.ts +1 -1
- package/dist/{types-c6R3idzB.d.cts → types-DGCkdOm1.d.cts} +9 -0
- package/dist/{types-c6R3idzB.d.ts → types-DGCkdOm1.d.ts} +9 -0
- package/package.json +14 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/pii-patterns.json
|
|
4
|
+
var pii_patterns_default = {
|
|
5
|
+
patterns: [
|
|
6
|
+
{ id: "ssn", configKey: "ssns", source: "\\b\\d{3}-\\d{2}-\\d{4}\\b", replacement: "[REDACTED_SSN]" },
|
|
7
|
+
{ id: "creditCard", configKey: "creditCards", source: "\\b(?:\\d[ -]*){12,18}\\d\\b", replacement: "[REDACTED_CC]" },
|
|
8
|
+
{ id: "awsAccessKey", configKey: "secretTokens", source: "\\b(?:AKIA|ASIA)[0-9A-Z]{16}\\b", replacement: "[REDACTED_AWS_KEY]" },
|
|
9
|
+
{ 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]" },
|
|
10
|
+
{ id: "stripeSecretKey", configKey: "secretTokens", source: "\\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{24,}\\b", replacement: "[REDACTED_STRIPE_KEY]" },
|
|
11
|
+
{ id: "stripePublishableKey", configKey: "secretTokens", source: "\\bpk_(?:live|test)_[A-Za-z0-9]{24,}\\b", replacement: "[REDACTED_STRIPE_PK]" },
|
|
12
|
+
{ id: "slackToken", configKey: "secretTokens", source: "\\bxox[abpor]-[A-Za-z0-9-]{10,}\\b", replacement: "[REDACTED_SLACK_TOKEN]" },
|
|
13
|
+
{ id: "githubPatClassic", configKey: "secretTokens", source: "\\bghp_[A-Za-z0-9]{36}\\b", replacement: "[REDACTED_GITHUB_PAT]" },
|
|
14
|
+
{ id: "githubPatFineGrained", configKey: "secretTokens", source: "\\bgithub_pat_[A-Za-z0-9_]{80,}\\b", replacement: "[REDACTED_GITHUB_PAT]" },
|
|
15
|
+
{ id: "openaiKey", configKey: "secretTokens", source: "\\bsk-(?:proj-)?[A-Za-z0-9_-]{20,}\\b", replacement: "[REDACTED_OPENAI_KEY]" },
|
|
16
|
+
{ id: "anthropicKey", configKey: "secretTokens", source: "\\bsk-ant-[A-Za-z0-9_-]{20,}\\b", replacement: "[REDACTED_ANTHROPIC_KEY]" },
|
|
17
|
+
{ id: "googleKey", configKey: "secretTokens", source: "\\bAIza[0-9A-Za-z_-]{35}\\b", replacement: "[REDACTED_GOOGLE_KEY]" },
|
|
18
|
+
{ id: "jwt", configKey: "secretTokens", source: "\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\b", replacement: "[REDACTED_JWT]" },
|
|
19
|
+
{ id: "email", configKey: "emails", source: "\\b[A-Za-z0-9._%+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}\\b", replacement: "[REDACTED_EMAIL]" },
|
|
20
|
+
{ id: "phone", configKey: "phones", source: "(?:\\+\\d{1,3}[\\s.-])?\\(?\\d{2,4}\\)?[\\s.-]\\d{3,4}[\\s.-]\\d{3,4}\\b", replacement: "[REDACTED_PHONE]" },
|
|
21
|
+
{ id: "ipv4", configKey: "ipAddresses", source: "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b", replacement: "[REDACTED_IP]", defaultOn: false },
|
|
22
|
+
{ 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 }
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/pii-scrubber.ts
|
|
27
|
+
var RAW_PATTERNS = pii_patterns_default.patterns;
|
|
28
|
+
var ORDERED_PATTERNS = RAW_PATTERNS.map((p) => ({
|
|
29
|
+
key: p.configKey,
|
|
30
|
+
regex: new RegExp(p.source, p.caseInsensitive ? "gi" : "g"),
|
|
31
|
+
replacement: p.replacement
|
|
32
|
+
}));
|
|
33
|
+
var DEFAULT_CONFIG = RAW_PATTERNS.reduce((acc, p) => {
|
|
34
|
+
acc[p.configKey] = p.defaultOn !== false;
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
function createPiiScrubber(config = {}) {
|
|
38
|
+
const merged = { ...DEFAULT_CONFIG, ...config };
|
|
39
|
+
const activePatterns = ORDERED_PATTERNS.filter((p) => merged[p.key]);
|
|
40
|
+
function scrub(text) {
|
|
41
|
+
if (!text) return text;
|
|
42
|
+
let result = text;
|
|
43
|
+
for (const { regex, replacement } of activePatterns) {
|
|
44
|
+
result = result.replace(new RegExp(regex.source, regex.flags), replacement);
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function scrubObject(obj, keys) {
|
|
49
|
+
const copy = { ...obj };
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
if (typeof copy[key] === "string") {
|
|
52
|
+
copy[key] = scrub(copy[key]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return copy;
|
|
56
|
+
}
|
|
57
|
+
return { scrub, scrubObject };
|
|
58
|
+
}
|
|
59
|
+
function scrubPii(text, config) {
|
|
60
|
+
return createPiiScrubber(config).scrub(text);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/diagnostics.ts
|
|
64
|
+
var DIAGNOSTICS_TIMEOUT_MS = 300;
|
|
65
|
+
var DIAGNOSTICS_MAX_CHARS = 16e3;
|
|
66
|
+
var MAX_DEPTH = 6;
|
|
67
|
+
function scrubDeep(value, scrub, depth) {
|
|
68
|
+
if (typeof value === "string") return scrub(value);
|
|
69
|
+
if (value === null || typeof value === "number" || typeof value === "boolean") return value;
|
|
70
|
+
if (depth >= MAX_DEPTH) return void 0;
|
|
71
|
+
if (Array.isArray(value)) return value.map((v) => scrubDeep(v, scrub, depth + 1)).filter((v) => v !== void 0);
|
|
72
|
+
if (typeof value === "object") {
|
|
73
|
+
const out = {};
|
|
74
|
+
for (const [k, v] of Object.entries(value)) {
|
|
75
|
+
const s = scrubDeep(v, scrub, depth + 1);
|
|
76
|
+
if (s !== void 0) out[k] = s;
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
function capSize(value, maxChars) {
|
|
83
|
+
if (JSON.stringify(value).length <= maxChars) return value;
|
|
84
|
+
const out = { diagnosticsTruncated: true };
|
|
85
|
+
for (const [k, v] of Object.entries(value)) {
|
|
86
|
+
const next = { ...out, [k]: v };
|
|
87
|
+
if (JSON.stringify(next).length > maxChars) continue;
|
|
88
|
+
out[k] = v;
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
async function collectDiagnostics(provider, opts = {}) {
|
|
93
|
+
if (!provider) return null;
|
|
94
|
+
let timer;
|
|
95
|
+
try {
|
|
96
|
+
const value = await Promise.race([
|
|
97
|
+
Promise.resolve().then(provider),
|
|
98
|
+
new Promise((resolve) => {
|
|
99
|
+
timer = setTimeout(() => resolve(null), opts.timeoutMs ?? DIAGNOSTICS_TIMEOUT_MS);
|
|
100
|
+
})
|
|
101
|
+
]);
|
|
102
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
103
|
+
const scrubbed = scrubDeep(value, opts.scrub ?? ((s) => scrubPii(s)), 0);
|
|
104
|
+
return Object.keys(scrubbed).length > 0 ? capSize(scrubbed, opts.maxChars ?? DIAGNOSTICS_MAX_CHARS) : null;
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
} finally {
|
|
108
|
+
if (timer) clearTimeout(timer);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
exports.DIAGNOSTICS_MAX_CHARS = DIAGNOSTICS_MAX_CHARS;
|
|
113
|
+
exports.collectDiagnostics = collectDiagnostics;
|
|
114
|
+
//# sourceMappingURL=diagnostics.cjs.map
|
|
115
|
+
//# sourceMappingURL=diagnostics.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pii-patterns.json","../src/pii-scrubber.ts","../src/diagnostics.ts"],"names":[],"mappings":";;;AAAA,IAAA,oBAAA,GAAA;AAAA,EACE,QAAA,EAAY;AAAA,IACV,EAAE,IAAM,KAAA,EAAO,SAAA,EAAa,QAAQ,MAAA,EAAU,4BAAA,EAA8B,aAAe,gBAAA,EAAiB;AAAA,IAC5G,EAAE,IAAM,YAAA,EAAc,SAAA,EAAa,eAAe,MAAA,EAAU,8BAAA,EAAgC,aAAe,eAAA,EAAgB;AAAA,IAC3H,EAAE,IAAM,cAAA,EAAgB,SAAA,EAAa,gBAAgB,MAAA,EAAU,iCAAA,EAAmC,aAAe,oBAAA,EAAqB;AAAA,IACtI,EAAE,EAAA,EAAM,cAAA,EAAgB,SAAA,EAAa,cAAA,EAAgB,QAAU,CAAA,0EAAA,CAAA,EAA+E,eAAA,EAAmB,IAAA,EAAM,WAAA,EAAe,6CAAA,EAA8C;AAAA,IACpO,EAAE,IAAM,iBAAA,EAAmB,SAAA,EAAa,gBAAgB,MAAA,EAAU,gDAAA,EAAkD,aAAe,uBAAA,EAAwB;AAAA,IAC3J,EAAE,IAAM,sBAAA,EAAwB,SAAA,EAAa,gBAAgB,MAAA,EAAU,yCA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AAA,KAAU,YAAY,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,OAAO,IAAA;AACxE,IAAA,MAAM,QAAA,GAAW,SAAA,CAAU,KAAA,EAAO,IAAA,CAAK,KAAA,KAAU,CAAC,CAAA,KAAM,QAAA,CAAS,CAAC,CAAA,CAAA,EAAI,CAAC,CAAA;AACvE,IAAA,OAAO,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA,CAAE,MAAA,GAAS,CAAA,GAAI,OAAA,CAAQ,QAAA,EAAU,IAAA,CAAK,QAAA,IAAY,qBAAqB,CAAA,GAAI,IAAA;AAAA,EACxG,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,SAAE;AACA,IAAA,IAAI,KAAA,eAAoB,KAAK,CAAA;AAAA,EAC/B;AACF","file":"diagnostics.cjs","sourcesContent":["{\n \"patterns\": [\n { \"id\": \"ssn\", \"configKey\": \"ssns\", \"source\": \"\\\\b\\\\d{3}-\\\\d{2}-\\\\d{4}\\\\b\", \"replacement\": \"[REDACTED_SSN]\" },\n { \"id\": \"creditCard\", \"configKey\": \"creditCards\", \"source\": \"\\\\b(?:\\\\d[ -]*){12,18}\\\\d\\\\b\", \"replacement\": \"[REDACTED_CC]\" },\n { \"id\": \"awsAccessKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\b(?:AKIA|ASIA)[0-9A-Z]{16}\\\\b\", \"replacement\": \"[REDACTED_AWS_KEY]\" },\n { \"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]\" },\n { \"id\": \"stripeSecretKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{24,}\\\\b\", \"replacement\": \"[REDACTED_STRIPE_KEY]\" },\n { \"id\": \"stripePublishableKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bpk_(?:live|test)_[A-Za-z0-9]{24,}\\\\b\", \"replacement\": \"[REDACTED_STRIPE_PK]\" },\n { \"id\": \"slackToken\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bxox[abpor]-[A-Za-z0-9-]{10,}\\\\b\", \"replacement\": \"[REDACTED_SLACK_TOKEN]\" },\n { \"id\": \"githubPatClassic\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bghp_[A-Za-z0-9]{36}\\\\b\", \"replacement\": \"[REDACTED_GITHUB_PAT]\" },\n { \"id\": \"githubPatFineGrained\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bgithub_pat_[A-Za-z0-9_]{80,}\\\\b\", \"replacement\": \"[REDACTED_GITHUB_PAT]\" },\n { \"id\": \"openaiKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bsk-(?:proj-)?[A-Za-z0-9_-]{20,}\\\\b\", \"replacement\": \"[REDACTED_OPENAI_KEY]\" },\n { \"id\": \"anthropicKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bsk-ant-[A-Za-z0-9_-]{20,}\\\\b\", \"replacement\": \"[REDACTED_ANTHROPIC_KEY]\" },\n { \"id\": \"googleKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bAIza[0-9A-Za-z_-]{35}\\\\b\", \"replacement\": \"[REDACTED_GOOGLE_KEY]\" },\n { \"id\": \"jwt\", \"configKey\": \"secretTokens\", \"source\": \"\\\\beyJ[A-Za-z0-9_-]+\\\\.[A-Za-z0-9_-]+\\\\.[A-Za-z0-9_-]+\\\\b\", \"replacement\": \"[REDACTED_JWT]\" },\n { \"id\": \"email\", \"configKey\": \"emails\", \"source\": \"\\\\b[A-Za-z0-9._%+\\\\-]+@[A-Za-z0-9.\\\\-]+\\\\.[A-Za-z]{2,}\\\\b\", \"replacement\": \"[REDACTED_EMAIL]\" },\n { \"id\": \"phone\", \"configKey\": \"phones\", \"source\": \"(?:\\\\+\\\\d{1,3}[\\\\s.-])?\\\\(?\\\\d{2,4}\\\\)?[\\\\s.-]\\\\d{3,4}[\\\\s.-]\\\\d{3,4}\\\\b\", \"replacement\": \"[REDACTED_PHONE]\" },\n { \"id\": \"ipv4\", \"configKey\": \"ipAddresses\", \"source\": \"\\\\b(?:\\\\d{1,3}\\\\.){3}\\\\d{1,3}\\\\b\", \"replacement\": \"[REDACTED_IP]\", \"defaultOn\": false },\n { \"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 }\n ]\n}\n","import piiPatternsData from './pii-patterns.json' with { type: 'json' };\n\nexport interface PiiScrubberConfig {\n emails?: boolean;\n phones?: boolean;\n creditCards?: boolean;\n ssns?: boolean;\n ipAddresses?: boolean;\n /**\n * Scrub vendor-shaped secret tokens (AWS access keys, Stripe keys,\n * Slack/GitHub PATs, OpenAI/Anthropic/Google keys, JWTs).\n *\n * Wave S1 / D-15: SDK parity with the server-side scrubber. The server\n * scrubs these on every LLM invocation; the SDK now scrubs them at\n * capture so they never hit the wire in the first place — important for\n * users who `console.log(stripeKey)` during dev and later ship bug\n * reports with the error text attached.\n */\n secretTokens?: boolean;\n /** IPv6 addresses. Defaults off for the same reason IPv4 does. */\n ipv6?: boolean;\n}\n\ninterface PiiPattern {\n key: keyof PiiScrubberConfig;\n regex: RegExp;\n replacement: string;\n}\n\ninterface RawPiiPattern {\n id: string;\n configKey: keyof PiiScrubberConfig;\n source: string;\n /** Omitted (falsy) for the vast majority of patterns — case-sensitive by default. */\n caseInsensitive?: boolean;\n replacement: string;\n /** Omitted (truthy) for every pattern except IPv4/IPv6, which default off. */\n defaultOn?: boolean;\n}\n\n// Order matters: SSN → CC → vendor secrets → email → phone → IP. Secret\n// tokens are matched *before* the generic email/phone regex because some JWT\n// payloads contain `.` that could be mis-parsed as `xyz.abc.com`.\n//\n// The pattern list itself lives in ./pii-patterns.json — the single source of\n// truth shared with the Flutter SDK's code-generated copy\n// (packages/flutter/lib/src/pii_patterns.g.dart, built by\n// scripts/generate-flutter-pii-patterns.mjs) so the two scrubbers can't drift.\nconst RAW_PATTERNS = piiPatternsData.patterns as RawPiiPattern[];\n\nconst ORDERED_PATTERNS: PiiPattern[] = RAW_PATTERNS.map((p) => ({\n key: p.configKey,\n regex: new RegExp(p.source, p.caseInsensitive ? 'gi' : 'g'),\n replacement: p.replacement,\n}));\n\nconst DEFAULT_CONFIG: PiiScrubberConfig = RAW_PATTERNS.reduce<PiiScrubberConfig>((acc, p) => {\n acc[p.configKey] = p.defaultOn !== false;\n return acc;\n}, {});\n\nexport function createPiiScrubber(config: PiiScrubberConfig = {}) {\n const merged = { ...DEFAULT_CONFIG, ...config };\n\n const activePatterns = ORDERED_PATTERNS.filter((p) => merged[p.key]);\n\n function scrub(text: string): string {\n if (!text) return text;\n let result = text;\n for (const { regex, replacement } of activePatterns) {\n result = result.replace(new RegExp(regex.source, regex.flags), replacement);\n }\n return result;\n }\n\n function scrubObject<T extends Record<string, unknown>>(obj: T, keys: string[]): T {\n const copy = { ...obj };\n for (const key of keys) {\n if (typeof copy[key] === 'string') {\n (copy as Record<string, unknown>)[key] = scrub(copy[key] as string);\n }\n }\n return copy;\n }\n\n return { scrub, scrubObject };\n}\n\nexport function scrubPii(text: string, config?: PiiScrubberConfig): string {\n return createPiiScrubber(config).scrub(text);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// URL query-string scrubbing (RealWorld attunement, Phase 1)\n//\n// Captured network URLs and route-timeline entries keep their query strings\n// for debuggability (`?tag=dragons&limit=10` is exactly what you want to see\n// on a Conduit article-list bug). But query VALUES are a PII channel:\n// `?token=eyJ…`, `?email=jake@x.com`, OAuth `?code=…`. We redact by key name\n// for known-sensitive keys, and run the pattern scrubber over the remaining\n// values so a JWT hiding under an innocent key (`?next=eyJ…`) is still caught.\n// Keys are always preserved — only values are redacted.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Query-param keys whose values are redacted wholesale. Substring match for\n * unambiguous stems (`access_token`, `id_token`, `user[email]` all hit), plus\n * exact matches for short names too ambiguous to substring-match (`key`,\n * `code` — OAuth authorization codes — and `sig`).\n */\nconst SENSITIVE_QUERY_KEY_SUBSTRING_RE =\n /token|jwt|passw|pwd|secret|api[-_]?key|apikey|auth|session|signature|email|phone|ssn/i;\nconst SENSITIVE_QUERY_KEY_EXACT_RE = /^(?:key|code|sig)$/i;\n\nfunction isSensitiveQueryKey(key: string): boolean {\n let decoded = key;\n try {\n decoded = decodeURIComponent(key);\n } catch {\n /* keep raw */\n }\n return (\n SENSITIVE_QUERY_KEY_SUBSTRING_RE.test(decoded) ||\n SENSITIVE_QUERY_KEY_EXACT_RE.test(decoded)\n );\n}\n\nfunction scrubQueryPairs(query: string, scrub: (s: string) => string): string {\n return query\n .split('&')\n .map((pair) => {\n const eq = pair.indexOf('=');\n if (eq === -1) return pair;\n const key = pair.slice(0, eq);\n const value = pair.slice(eq + 1);\n if (value.length === 0) return pair;\n if (isSensitiveQueryKey(key)) return `${key}=[Scrubbed]`;\n // Generic value scrub. Decode first so percent-encoded PII\n // (`user%40x.com`) matches the same patterns as free text.\n let decoded = value;\n try {\n decoded = decodeURIComponent(value);\n } catch {\n /* malformed escape — scrub the raw value instead */\n }\n const scrubbed = scrub(decoded);\n if (scrubbed !== decoded) return `${key}=${encodeURIComponent(scrubbed)}`;\n return pair;\n })\n .join('&');\n}\n\n/**\n * Scrub the query-string portion(s) of a URL — both the standard `?…` part\n * and any `?…` inside the hash fragment (hash routers like RealWorld's\n * `#/path?query` carry their query inside the fragment). Path segments and\n * param keys are left untouched; only values are redacted. Accepts absolute\n * or relative URLs and never throws.\n */\nexport function scrubUrl(url: string, config?: PiiScrubberConfig): string {\n if (!url || (!url.includes('?') && !url.includes('#'))) return url;\n const { scrub } = createPiiScrubber(config);\n const scrubPart = (part: string): string => {\n const qIdx = part.indexOf('?');\n if (qIdx === -1) return part;\n return part.slice(0, qIdx + 1) + scrubQueryPairs(part.slice(qIdx + 1), scrub);\n };\n const hashIdx = url.indexOf('#');\n if (hashIdx === -1) return scrubPart(url);\n return scrubPart(url.slice(0, hashIdx)) + scrubPart(url.slice(hashIdx));\n}\n","// SPDX-License-Identifier: MIT\n/**\n * FILE: packages/core/src/diagnostics.ts\n * PURPOSE: The host app's own diagnostics, read at the moment a report is sent\n * (`setDiagnosticsProvider`). yen-yen pushed its load log with\n * `setMetadata` on a timer (2026-11-16); a provider is read when the\n * reporter presses Send, so the report carries what the app knew then.\n *\n * A slow or throwing provider never blocks or drops a report: it gets\n * `DIAGNOSTICS_TIMEOUT_MS`, any error is swallowed, strings are PII-scrubbed,\n * and the result is capped at `DIAGNOSTICS_MAX_CHARS` of JSON. Keys merge into\n * the report's metadata, so `{ screenLoading: [...] }` lands at\n * `custom_metadata.screenLoading`, where triage reads it.\n */\n\nimport { scrubPii } from './pii-scrubber';\n\ntype DiagnosticsValue = Record<string, unknown>;\n\n/** Returns the diagnostics to attach (plain JSON values), or null/undefined for none. */\nexport type MushiDiagnosticsProvider = () =>\n | DiagnosticsValue\n | null\n | undefined\n | Promise<DiagnosticsValue | null | undefined>;\n\nconst DIAGNOSTICS_TIMEOUT_MS = 300;\n/** @internal Exported for tests only. */\nexport const DIAGNOSTICS_MAX_CHARS = 16_000;\nconst MAX_DEPTH = 6;\n\nfunction scrubDeep(value: unknown, scrub: (s: string) => string, depth: number): unknown {\n if (typeof value === 'string') return scrub(value);\n if (value === null || typeof value === 'number' || typeof value === 'boolean') return value;\n if (depth >= MAX_DEPTH) return undefined;\n if (Array.isArray(value)) return value.map((v) => scrubDeep(v, scrub, depth + 1)).filter((v) => v !== undefined);\n if (typeof value === 'object') {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n const s = scrubDeep(v, scrub, depth + 1);\n if (s !== undefined) out[k] = s;\n }\n return out;\n }\n // Functions, symbols, bigint: not JSON.\n return undefined;\n}\n\n/** Whole top-level keys, in order, while the JSON stays under the cap. */\nfunction capSize(value: DiagnosticsValue, maxChars: number): DiagnosticsValue {\n if (JSON.stringify(value).length <= maxChars) return value;\n const out: DiagnosticsValue = { diagnosticsTruncated: true };\n for (const [k, v] of Object.entries(value)) {\n const next = { ...out, [k]: v };\n if (JSON.stringify(next).length > maxChars) continue;\n out[k] = v;\n }\n return out;\n}\n\n/**\n * Run the host's provider for one report. Resolves null when there is none, it\n * returns nothing usable, throws, or takes longer than the timeout.\n */\nexport async function collectDiagnostics(\n provider: MushiDiagnosticsProvider | null | undefined,\n opts: { timeoutMs?: number; maxChars?: number; scrub?: (s: string) => string } = {},\n): Promise<DiagnosticsValue | null> {\n if (!provider) return null;\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n const value = await Promise.race([\n Promise.resolve().then(provider),\n new Promise<null>((resolve) => {\n timer = setTimeout(() => resolve(null), opts.timeoutMs ?? DIAGNOSTICS_TIMEOUT_MS);\n }),\n ]);\n if (!value || typeof value !== 'object' || Array.isArray(value)) return null;\n const scrubbed = scrubDeep(value, opts.scrub ?? ((s) => scrubPii(s)), 0) as DiagnosticsValue;\n return Object.keys(scrubbed).length > 0 ? capSize(scrubbed, opts.maxChars ?? DIAGNOSTICS_MAX_CHARS) : null;\n } catch {\n return null;\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FILE: packages/core/src/diagnostics.ts
|
|
3
|
+
* PURPOSE: The host app's own diagnostics, read at the moment a report is sent
|
|
4
|
+
* (`setDiagnosticsProvider`). yen-yen pushed its load log with
|
|
5
|
+
* `setMetadata` on a timer (2026-11-16); a provider is read when the
|
|
6
|
+
* reporter presses Send, so the report carries what the app knew then.
|
|
7
|
+
*
|
|
8
|
+
* A slow or throwing provider never blocks or drops a report: it gets
|
|
9
|
+
* `DIAGNOSTICS_TIMEOUT_MS`, any error is swallowed, strings are PII-scrubbed,
|
|
10
|
+
* and the result is capped at `DIAGNOSTICS_MAX_CHARS` of JSON. Keys merge into
|
|
11
|
+
* the report's metadata, so `{ screenLoading: [...] }` lands at
|
|
12
|
+
* `custom_metadata.screenLoading`, where triage reads it.
|
|
13
|
+
*/
|
|
14
|
+
type DiagnosticsValue = Record<string, unknown>;
|
|
15
|
+
/** Returns the diagnostics to attach (plain JSON values), or null/undefined for none. */
|
|
16
|
+
type MushiDiagnosticsProvider = () => DiagnosticsValue | null | undefined | Promise<DiagnosticsValue | null | undefined>;
|
|
17
|
+
/** @internal Exported for tests only. */
|
|
18
|
+
declare const DIAGNOSTICS_MAX_CHARS = 16000;
|
|
19
|
+
/**
|
|
20
|
+
* Run the host's provider for one report. Resolves null when there is none, it
|
|
21
|
+
* returns nothing usable, throws, or takes longer than the timeout.
|
|
22
|
+
*/
|
|
23
|
+
declare function collectDiagnostics(provider: MushiDiagnosticsProvider | null | undefined, opts?: {
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
maxChars?: number;
|
|
26
|
+
scrub?: (s: string) => string;
|
|
27
|
+
}): Promise<DiagnosticsValue | null>;
|
|
28
|
+
|
|
29
|
+
export { DIAGNOSTICS_MAX_CHARS, type MushiDiagnosticsProvider, collectDiagnostics };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FILE: packages/core/src/diagnostics.ts
|
|
3
|
+
* PURPOSE: The host app's own diagnostics, read at the moment a report is sent
|
|
4
|
+
* (`setDiagnosticsProvider`). yen-yen pushed its load log with
|
|
5
|
+
* `setMetadata` on a timer (2026-11-16); a provider is read when the
|
|
6
|
+
* reporter presses Send, so the report carries what the app knew then.
|
|
7
|
+
*
|
|
8
|
+
* A slow or throwing provider never blocks or drops a report: it gets
|
|
9
|
+
* `DIAGNOSTICS_TIMEOUT_MS`, any error is swallowed, strings are PII-scrubbed,
|
|
10
|
+
* and the result is capped at `DIAGNOSTICS_MAX_CHARS` of JSON. Keys merge into
|
|
11
|
+
* the report's metadata, so `{ screenLoading: [...] }` lands at
|
|
12
|
+
* `custom_metadata.screenLoading`, where triage reads it.
|
|
13
|
+
*/
|
|
14
|
+
type DiagnosticsValue = Record<string, unknown>;
|
|
15
|
+
/** Returns the diagnostics to attach (plain JSON values), or null/undefined for none. */
|
|
16
|
+
type MushiDiagnosticsProvider = () => DiagnosticsValue | null | undefined | Promise<DiagnosticsValue | null | undefined>;
|
|
17
|
+
/** @internal Exported for tests only. */
|
|
18
|
+
declare const DIAGNOSTICS_MAX_CHARS = 16000;
|
|
19
|
+
/**
|
|
20
|
+
* Run the host's provider for one report. Resolves null when there is none, it
|
|
21
|
+
* returns nothing usable, throws, or takes longer than the timeout.
|
|
22
|
+
*/
|
|
23
|
+
declare function collectDiagnostics(provider: MushiDiagnosticsProvider | null | undefined, opts?: {
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
maxChars?: number;
|
|
26
|
+
scrub?: (s: string) => string;
|
|
27
|
+
}): Promise<DiagnosticsValue | null>;
|
|
28
|
+
|
|
29
|
+
export { DIAGNOSTICS_MAX_CHARS, type MushiDiagnosticsProvider, collectDiagnostics };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// src/pii-patterns.json
|
|
2
|
+
var pii_patterns_default = {
|
|
3
|
+
patterns: [
|
|
4
|
+
{ id: "ssn", configKey: "ssns", source: "\\b\\d{3}-\\d{2}-\\d{4}\\b", replacement: "[REDACTED_SSN]" },
|
|
5
|
+
{ id: "creditCard", configKey: "creditCards", source: "\\b(?:\\d[ -]*){12,18}\\d\\b", replacement: "[REDACTED_CC]" },
|
|
6
|
+
{ id: "awsAccessKey", configKey: "secretTokens", source: "\\b(?:AKIA|ASIA)[0-9A-Z]{16}\\b", replacement: "[REDACTED_AWS_KEY]" },
|
|
7
|
+
{ 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]" },
|
|
8
|
+
{ id: "stripeSecretKey", configKey: "secretTokens", source: "\\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{24,}\\b", replacement: "[REDACTED_STRIPE_KEY]" },
|
|
9
|
+
{ id: "stripePublishableKey", configKey: "secretTokens", source: "\\bpk_(?:live|test)_[A-Za-z0-9]{24,}\\b", replacement: "[REDACTED_STRIPE_PK]" },
|
|
10
|
+
{ id: "slackToken", configKey: "secretTokens", source: "\\bxox[abpor]-[A-Za-z0-9-]{10,}\\b", replacement: "[REDACTED_SLACK_TOKEN]" },
|
|
11
|
+
{ id: "githubPatClassic", configKey: "secretTokens", source: "\\bghp_[A-Za-z0-9]{36}\\b", replacement: "[REDACTED_GITHUB_PAT]" },
|
|
12
|
+
{ id: "githubPatFineGrained", configKey: "secretTokens", source: "\\bgithub_pat_[A-Za-z0-9_]{80,}\\b", replacement: "[REDACTED_GITHUB_PAT]" },
|
|
13
|
+
{ id: "openaiKey", configKey: "secretTokens", source: "\\bsk-(?:proj-)?[A-Za-z0-9_-]{20,}\\b", replacement: "[REDACTED_OPENAI_KEY]" },
|
|
14
|
+
{ id: "anthropicKey", configKey: "secretTokens", source: "\\bsk-ant-[A-Za-z0-9_-]{20,}\\b", replacement: "[REDACTED_ANTHROPIC_KEY]" },
|
|
15
|
+
{ id: "googleKey", configKey: "secretTokens", source: "\\bAIza[0-9A-Za-z_-]{35}\\b", replacement: "[REDACTED_GOOGLE_KEY]" },
|
|
16
|
+
{ id: "jwt", configKey: "secretTokens", source: "\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\b", replacement: "[REDACTED_JWT]" },
|
|
17
|
+
{ id: "email", configKey: "emails", source: "\\b[A-Za-z0-9._%+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}\\b", replacement: "[REDACTED_EMAIL]" },
|
|
18
|
+
{ id: "phone", configKey: "phones", source: "(?:\\+\\d{1,3}[\\s.-])?\\(?\\d{2,4}\\)?[\\s.-]\\d{3,4}[\\s.-]\\d{3,4}\\b", replacement: "[REDACTED_PHONE]" },
|
|
19
|
+
{ id: "ipv4", configKey: "ipAddresses", source: "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b", replacement: "[REDACTED_IP]", defaultOn: false },
|
|
20
|
+
{ 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 }
|
|
21
|
+
]
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/pii-scrubber.ts
|
|
25
|
+
var RAW_PATTERNS = pii_patterns_default.patterns;
|
|
26
|
+
var ORDERED_PATTERNS = RAW_PATTERNS.map((p) => ({
|
|
27
|
+
key: p.configKey,
|
|
28
|
+
regex: new RegExp(p.source, p.caseInsensitive ? "gi" : "g"),
|
|
29
|
+
replacement: p.replacement
|
|
30
|
+
}));
|
|
31
|
+
var DEFAULT_CONFIG = RAW_PATTERNS.reduce((acc, p) => {
|
|
32
|
+
acc[p.configKey] = p.defaultOn !== false;
|
|
33
|
+
return acc;
|
|
34
|
+
}, {});
|
|
35
|
+
function createPiiScrubber(config = {}) {
|
|
36
|
+
const merged = { ...DEFAULT_CONFIG, ...config };
|
|
37
|
+
const activePatterns = ORDERED_PATTERNS.filter((p) => merged[p.key]);
|
|
38
|
+
function scrub(text) {
|
|
39
|
+
if (!text) return text;
|
|
40
|
+
let result = text;
|
|
41
|
+
for (const { regex, replacement } of activePatterns) {
|
|
42
|
+
result = result.replace(new RegExp(regex.source, regex.flags), replacement);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
function scrubObject(obj, keys) {
|
|
47
|
+
const copy = { ...obj };
|
|
48
|
+
for (const key of keys) {
|
|
49
|
+
if (typeof copy[key] === "string") {
|
|
50
|
+
copy[key] = scrub(copy[key]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return copy;
|
|
54
|
+
}
|
|
55
|
+
return { scrub, scrubObject };
|
|
56
|
+
}
|
|
57
|
+
function scrubPii(text, config) {
|
|
58
|
+
return createPiiScrubber(config).scrub(text);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/diagnostics.ts
|
|
62
|
+
var DIAGNOSTICS_TIMEOUT_MS = 300;
|
|
63
|
+
var DIAGNOSTICS_MAX_CHARS = 16e3;
|
|
64
|
+
var MAX_DEPTH = 6;
|
|
65
|
+
function scrubDeep(value, scrub, depth) {
|
|
66
|
+
if (typeof value === "string") return scrub(value);
|
|
67
|
+
if (value === null || typeof value === "number" || typeof value === "boolean") return value;
|
|
68
|
+
if (depth >= MAX_DEPTH) return void 0;
|
|
69
|
+
if (Array.isArray(value)) return value.map((v) => scrubDeep(v, scrub, depth + 1)).filter((v) => v !== void 0);
|
|
70
|
+
if (typeof value === "object") {
|
|
71
|
+
const out = {};
|
|
72
|
+
for (const [k, v] of Object.entries(value)) {
|
|
73
|
+
const s = scrubDeep(v, scrub, depth + 1);
|
|
74
|
+
if (s !== void 0) out[k] = s;
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
function capSize(value, maxChars) {
|
|
81
|
+
if (JSON.stringify(value).length <= maxChars) return value;
|
|
82
|
+
const out = { diagnosticsTruncated: true };
|
|
83
|
+
for (const [k, v] of Object.entries(value)) {
|
|
84
|
+
const next = { ...out, [k]: v };
|
|
85
|
+
if (JSON.stringify(next).length > maxChars) continue;
|
|
86
|
+
out[k] = v;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
async function collectDiagnostics(provider, opts = {}) {
|
|
91
|
+
if (!provider) return null;
|
|
92
|
+
let timer;
|
|
93
|
+
try {
|
|
94
|
+
const value = await Promise.race([
|
|
95
|
+
Promise.resolve().then(provider),
|
|
96
|
+
new Promise((resolve) => {
|
|
97
|
+
timer = setTimeout(() => resolve(null), opts.timeoutMs ?? DIAGNOSTICS_TIMEOUT_MS);
|
|
98
|
+
})
|
|
99
|
+
]);
|
|
100
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
101
|
+
const scrubbed = scrubDeep(value, opts.scrub ?? ((s) => scrubPii(s)), 0);
|
|
102
|
+
return Object.keys(scrubbed).length > 0 ? capSize(scrubbed, opts.maxChars ?? DIAGNOSTICS_MAX_CHARS) : null;
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
} finally {
|
|
106
|
+
if (timer) clearTimeout(timer);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { DIAGNOSTICS_MAX_CHARS, collectDiagnostics };
|
|
111
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
112
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pii-patterns.json","../src/pii-scrubber.ts","../src/diagnostics.ts"],"names":[],"mappings":";AAAA,IAAA,oBAAA,GAAA;AAAA,EACE,QAAA,EAAY;AAAA,IACV,EAAE,IAAM,KAAA,EAAO,SAAA,EAAa,QAAQ,MAAA,EAAU,4BAAA,EAA8B,aAAe,gBAAA,EAAiB;AAAA,IAC5G,EAAE,IAAM,YAAA,EAAc,SAAA,EAAa,eAAe,MAAA,EAAU,8BAAA,EAAgC,aAAe,eAAA,EAAgB;AAAA,IAC3H,EAAE,IAAM,cAAA,EAAgB,SAAA,EAAa,gBAAgB,MAAA,EAAU,iCAAA,EAAmC,aAAe,oBAAA,EAAqB;AAAA,IACtI,EAAE,EAAA,EAAM,cAAA,EAAgB,SAAA,EAAa,cAAA,EAAgB,QAAU,CAAA,0EAAA,CAAA,EAA+E,eAAA,EAAmB,IAAA,EAAM,WAAA,EAAe,6CAAA,EAA8C;AAAA,IACpO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C7B,QAAA,KAAA,GAAQ,WAAW,MAAM,OAAA,CAAQ,IAAI,CAAA,EAAG,IAAA,CAAK,aAAa,sBAAsB,CAAA;AAAA,MAClF,CAAC;AAAA,KACF,CAAA;AACD,IAAA,IAAI,CAAC,SAAS,OAAO,KAAA,KAAU,YAAY,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,OAAO,IAAA;AACxE,IAAA,MAAM,QAAA,GAAW,SAAA,CAAU,KAAA,EAAO,IAAA,CAAK,KAAA,KAAU,CAAC,CAAA,KAAM,QAAA,CAAS,CAAC,CAAA,CAAA,EAAI,CAAC,CAAA;AACvE,IAAA,OAAO,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA,CAAE,MAAA,GAAS,CAAA,GAAI,OAAA,CAAQ,QAAA,EAAU,IAAA,CAAK,QAAA,IAAY,qBAAqB,CAAA,GAAI,IAAA;AAAA,EACxG,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,SAAE;AACA,IAAA,IAAI,KAAA,eAAoB,KAAK,CAAA;AAAA,EAC/B;AACF","file":"diagnostics.js","sourcesContent":["{\n \"patterns\": [\n { \"id\": \"ssn\", \"configKey\": \"ssns\", \"source\": \"\\\\b\\\\d{3}-\\\\d{2}-\\\\d{4}\\\\b\", \"replacement\": \"[REDACTED_SSN]\" },\n { \"id\": \"creditCard\", \"configKey\": \"creditCards\", \"source\": \"\\\\b(?:\\\\d[ -]*){12,18}\\\\d\\\\b\", \"replacement\": \"[REDACTED_CC]\" },\n { \"id\": \"awsAccessKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\b(?:AKIA|ASIA)[0-9A-Z]{16}\\\\b\", \"replacement\": \"[REDACTED_AWS_KEY]\" },\n { \"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]\" },\n { \"id\": \"stripeSecretKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{24,}\\\\b\", \"replacement\": \"[REDACTED_STRIPE_KEY]\" },\n { \"id\": \"stripePublishableKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bpk_(?:live|test)_[A-Za-z0-9]{24,}\\\\b\", \"replacement\": \"[REDACTED_STRIPE_PK]\" },\n { \"id\": \"slackToken\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bxox[abpor]-[A-Za-z0-9-]{10,}\\\\b\", \"replacement\": \"[REDACTED_SLACK_TOKEN]\" },\n { \"id\": \"githubPatClassic\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bghp_[A-Za-z0-9]{36}\\\\b\", \"replacement\": \"[REDACTED_GITHUB_PAT]\" },\n { \"id\": \"githubPatFineGrained\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bgithub_pat_[A-Za-z0-9_]{80,}\\\\b\", \"replacement\": \"[REDACTED_GITHUB_PAT]\" },\n { \"id\": \"openaiKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bsk-(?:proj-)?[A-Za-z0-9_-]{20,}\\\\b\", \"replacement\": \"[REDACTED_OPENAI_KEY]\" },\n { \"id\": \"anthropicKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bsk-ant-[A-Za-z0-9_-]{20,}\\\\b\", \"replacement\": \"[REDACTED_ANTHROPIC_KEY]\" },\n { \"id\": \"googleKey\", \"configKey\": \"secretTokens\", \"source\": \"\\\\bAIza[0-9A-Za-z_-]{35}\\\\b\", \"replacement\": \"[REDACTED_GOOGLE_KEY]\" },\n { \"id\": \"jwt\", \"configKey\": \"secretTokens\", \"source\": \"\\\\beyJ[A-Za-z0-9_-]+\\\\.[A-Za-z0-9_-]+\\\\.[A-Za-z0-9_-]+\\\\b\", \"replacement\": \"[REDACTED_JWT]\" },\n { \"id\": \"email\", \"configKey\": \"emails\", \"source\": \"\\\\b[A-Za-z0-9._%+\\\\-]+@[A-Za-z0-9.\\\\-]+\\\\.[A-Za-z]{2,}\\\\b\", \"replacement\": \"[REDACTED_EMAIL]\" },\n { \"id\": \"phone\", \"configKey\": \"phones\", \"source\": \"(?:\\\\+\\\\d{1,3}[\\\\s.-])?\\\\(?\\\\d{2,4}\\\\)?[\\\\s.-]\\\\d{3,4}[\\\\s.-]\\\\d{3,4}\\\\b\", \"replacement\": \"[REDACTED_PHONE]\" },\n { \"id\": \"ipv4\", \"configKey\": \"ipAddresses\", \"source\": \"\\\\b(?:\\\\d{1,3}\\\\.){3}\\\\d{1,3}\\\\b\", \"replacement\": \"[REDACTED_IP]\", \"defaultOn\": false },\n { \"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 }\n ]\n}\n","import piiPatternsData from './pii-patterns.json' with { type: 'json' };\n\nexport interface PiiScrubberConfig {\n emails?: boolean;\n phones?: boolean;\n creditCards?: boolean;\n ssns?: boolean;\n ipAddresses?: boolean;\n /**\n * Scrub vendor-shaped secret tokens (AWS access keys, Stripe keys,\n * Slack/GitHub PATs, OpenAI/Anthropic/Google keys, JWTs).\n *\n * Wave S1 / D-15: SDK parity with the server-side scrubber. The server\n * scrubs these on every LLM invocation; the SDK now scrubs them at\n * capture so they never hit the wire in the first place — important for\n * users who `console.log(stripeKey)` during dev and later ship bug\n * reports with the error text attached.\n */\n secretTokens?: boolean;\n /** IPv6 addresses. Defaults off for the same reason IPv4 does. */\n ipv6?: boolean;\n}\n\ninterface PiiPattern {\n key: keyof PiiScrubberConfig;\n regex: RegExp;\n replacement: string;\n}\n\ninterface RawPiiPattern {\n id: string;\n configKey: keyof PiiScrubberConfig;\n source: string;\n /** Omitted (falsy) for the vast majority of patterns — case-sensitive by default. */\n caseInsensitive?: boolean;\n replacement: string;\n /** Omitted (truthy) for every pattern except IPv4/IPv6, which default off. */\n defaultOn?: boolean;\n}\n\n// Order matters: SSN → CC → vendor secrets → email → phone → IP. Secret\n// tokens are matched *before* the generic email/phone regex because some JWT\n// payloads contain `.` that could be mis-parsed as `xyz.abc.com`.\n//\n// The pattern list itself lives in ./pii-patterns.json — the single source of\n// truth shared with the Flutter SDK's code-generated copy\n// (packages/flutter/lib/src/pii_patterns.g.dart, built by\n// scripts/generate-flutter-pii-patterns.mjs) so the two scrubbers can't drift.\nconst RAW_PATTERNS = piiPatternsData.patterns as RawPiiPattern[];\n\nconst ORDERED_PATTERNS: PiiPattern[] = RAW_PATTERNS.map((p) => ({\n key: p.configKey,\n regex: new RegExp(p.source, p.caseInsensitive ? 'gi' : 'g'),\n replacement: p.replacement,\n}));\n\nconst DEFAULT_CONFIG: PiiScrubberConfig = RAW_PATTERNS.reduce<PiiScrubberConfig>((acc, p) => {\n acc[p.configKey] = p.defaultOn !== false;\n return acc;\n}, {});\n\nexport function createPiiScrubber(config: PiiScrubberConfig = {}) {\n const merged = { ...DEFAULT_CONFIG, ...config };\n\n const activePatterns = ORDERED_PATTERNS.filter((p) => merged[p.key]);\n\n function scrub(text: string): string {\n if (!text) return text;\n let result = text;\n for (const { regex, replacement } of activePatterns) {\n result = result.replace(new RegExp(regex.source, regex.flags), replacement);\n }\n return result;\n }\n\n function scrubObject<T extends Record<string, unknown>>(obj: T, keys: string[]): T {\n const copy = { ...obj };\n for (const key of keys) {\n if (typeof copy[key] === 'string') {\n (copy as Record<string, unknown>)[key] = scrub(copy[key] as string);\n }\n }\n return copy;\n }\n\n return { scrub, scrubObject };\n}\n\nexport function scrubPii(text: string, config?: PiiScrubberConfig): string {\n return createPiiScrubber(config).scrub(text);\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// URL query-string scrubbing (RealWorld attunement, Phase 1)\n//\n// Captured network URLs and route-timeline entries keep their query strings\n// for debuggability (`?tag=dragons&limit=10` is exactly what you want to see\n// on a Conduit article-list bug). But query VALUES are a PII channel:\n// `?token=eyJ…`, `?email=jake@x.com`, OAuth `?code=…`. We redact by key name\n// for known-sensitive keys, and run the pattern scrubber over the remaining\n// values so a JWT hiding under an innocent key (`?next=eyJ…`) is still caught.\n// Keys are always preserved — only values are redacted.\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Query-param keys whose values are redacted wholesale. Substring match for\n * unambiguous stems (`access_token`, `id_token`, `user[email]` all hit), plus\n * exact matches for short names too ambiguous to substring-match (`key`,\n * `code` — OAuth authorization codes — and `sig`).\n */\nconst SENSITIVE_QUERY_KEY_SUBSTRING_RE =\n /token|jwt|passw|pwd|secret|api[-_]?key|apikey|auth|session|signature|email|phone|ssn/i;\nconst SENSITIVE_QUERY_KEY_EXACT_RE = /^(?:key|code|sig)$/i;\n\nfunction isSensitiveQueryKey(key: string): boolean {\n let decoded = key;\n try {\n decoded = decodeURIComponent(key);\n } catch {\n /* keep raw */\n }\n return (\n SENSITIVE_QUERY_KEY_SUBSTRING_RE.test(decoded) ||\n SENSITIVE_QUERY_KEY_EXACT_RE.test(decoded)\n );\n}\n\nfunction scrubQueryPairs(query: string, scrub: (s: string) => string): string {\n return query\n .split('&')\n .map((pair) => {\n const eq = pair.indexOf('=');\n if (eq === -1) return pair;\n const key = pair.slice(0, eq);\n const value = pair.slice(eq + 1);\n if (value.length === 0) return pair;\n if (isSensitiveQueryKey(key)) return `${key}=[Scrubbed]`;\n // Generic value scrub. Decode first so percent-encoded PII\n // (`user%40x.com`) matches the same patterns as free text.\n let decoded = value;\n try {\n decoded = decodeURIComponent(value);\n } catch {\n /* malformed escape — scrub the raw value instead */\n }\n const scrubbed = scrub(decoded);\n if (scrubbed !== decoded) return `${key}=${encodeURIComponent(scrubbed)}`;\n return pair;\n })\n .join('&');\n}\n\n/**\n * Scrub the query-string portion(s) of a URL — both the standard `?…` part\n * and any `?…` inside the hash fragment (hash routers like RealWorld's\n * `#/path?query` carry their query inside the fragment). Path segments and\n * param keys are left untouched; only values are redacted. Accepts absolute\n * or relative URLs and never throws.\n */\nexport function scrubUrl(url: string, config?: PiiScrubberConfig): string {\n if (!url || (!url.includes('?') && !url.includes('#'))) return url;\n const { scrub } = createPiiScrubber(config);\n const scrubPart = (part: string): string => {\n const qIdx = part.indexOf('?');\n if (qIdx === -1) return part;\n return part.slice(0, qIdx + 1) + scrubQueryPairs(part.slice(qIdx + 1), scrub);\n };\n const hashIdx = url.indexOf('#');\n if (hashIdx === -1) return scrubPart(url);\n return scrubPart(url.slice(0, hashIdx)) + scrubPart(url.slice(hashIdx));\n}\n","// SPDX-License-Identifier: MIT\n/**\n * FILE: packages/core/src/diagnostics.ts\n * PURPOSE: The host app's own diagnostics, read at the moment a report is sent\n * (`setDiagnosticsProvider`). yen-yen pushed its load log with\n * `setMetadata` on a timer (2026-11-16); a provider is read when the\n * reporter presses Send, so the report carries what the app knew then.\n *\n * A slow or throwing provider never blocks or drops a report: it gets\n * `DIAGNOSTICS_TIMEOUT_MS`, any error is swallowed, strings are PII-scrubbed,\n * and the result is capped at `DIAGNOSTICS_MAX_CHARS` of JSON. Keys merge into\n * the report's metadata, so `{ screenLoading: [...] }` lands at\n * `custom_metadata.screenLoading`, where triage reads it.\n */\n\nimport { scrubPii } from './pii-scrubber';\n\ntype DiagnosticsValue = Record<string, unknown>;\n\n/** Returns the diagnostics to attach (plain JSON values), or null/undefined for none. */\nexport type MushiDiagnosticsProvider = () =>\n | DiagnosticsValue\n | null\n | undefined\n | Promise<DiagnosticsValue | null | undefined>;\n\nconst DIAGNOSTICS_TIMEOUT_MS = 300;\n/** @internal Exported for tests only. */\nexport const DIAGNOSTICS_MAX_CHARS = 16_000;\nconst MAX_DEPTH = 6;\n\nfunction scrubDeep(value: unknown, scrub: (s: string) => string, depth: number): unknown {\n if (typeof value === 'string') return scrub(value);\n if (value === null || typeof value === 'number' || typeof value === 'boolean') return value;\n if (depth >= MAX_DEPTH) return undefined;\n if (Array.isArray(value)) return value.map((v) => scrubDeep(v, scrub, depth + 1)).filter((v) => v !== undefined);\n if (typeof value === 'object') {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n const s = scrubDeep(v, scrub, depth + 1);\n if (s !== undefined) out[k] = s;\n }\n return out;\n }\n // Functions, symbols, bigint: not JSON.\n return undefined;\n}\n\n/** Whole top-level keys, in order, while the JSON stays under the cap. */\nfunction capSize(value: DiagnosticsValue, maxChars: number): DiagnosticsValue {\n if (JSON.stringify(value).length <= maxChars) return value;\n const out: DiagnosticsValue = { diagnosticsTruncated: true };\n for (const [k, v] of Object.entries(value)) {\n const next = { ...out, [k]: v };\n if (JSON.stringify(next).length > maxChars) continue;\n out[k] = v;\n }\n return out;\n}\n\n/**\n * Run the host's provider for one report. Resolves null when there is none, it\n * returns nothing usable, throws, or takes longer than the timeout.\n */\nexport async function collectDiagnostics(\n provider: MushiDiagnosticsProvider | null | undefined,\n opts: { timeoutMs?: number; maxChars?: number; scrub?: (s: string) => string } = {},\n): Promise<DiagnosticsValue | null> {\n if (!provider) return null;\n let timer: ReturnType<typeof setTimeout> | undefined;\n try {\n const value = await Promise.race([\n Promise.resolve().then(provider),\n new Promise<null>((resolve) => {\n timer = setTimeout(() => resolve(null), opts.timeoutMs ?? DIAGNOSTICS_TIMEOUT_MS);\n }),\n ]);\n if (!value || typeof value !== 'object' || Array.isArray(value)) return null;\n const scrubbed = scrubDeep(value, opts.scrub ?? ((s) => scrubPii(s)), 0) as DiagnosticsValue;\n return Object.keys(scrubbed).length > 0 ? capSize(scrubbed, opts.maxChars ?? DIAGNOSTICS_MAX_CHARS) : null;\n } catch {\n return null;\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MushiApiClient, a as MushiConfig, b as MushiPreFilterConfig, c as MushiReport, d as MushiOfflineConfig, e as MushiEnvironment, f as MushiAnalyticsConfig, g as MushiPropertyValue, h as MushiBreadcrumb } from './types-
|
|
2
|
-
export { i as MushiActivityEvent, j as MushiApiCascadeConfig, k as MushiApiResponse, l as MushiAssistantConfig, m as MushiAssistantReply, n as MushiAssistantStep, o as MushiBannerConfig, p as MushiBannerLink, q as MushiBetaChangelogEntry, r as MushiBetaModeConfig, s as MushiCaptureConfig, t as MushiCaptureEventInput, u as MushiCaptureExceptionOptions, v as MushiConsoleEntry, w as MushiCooldownConfig, x as MushiCrossAppReport, y as MushiCustomCategory, z as MushiDiagnosticsResult, A as MushiDiscoverInventoryConfig, B as MushiDiscoveryEventPayload, C as MushiEventHandler, D as MushiEventType, E as MushiHallOfFameEntry, F as MushiInitConfig, G as MushiIntegrationsConfig, H as MushiLeaderboardEntry, I as MushiNetworkEntry, J as MushiNotificationsConfig, K as MushiOnDeviceClassifier, L as MushiOnDeviceClassifierInput, N as MushiOnDeviceClassifierResult, O as MushiPageContext, P as MushiPerformanceMetrics, Q as MushiPreset, R as MushiPrivacyConfig, S as MushiProactiveConfig, T as MushiProductEventPayload, U as MushiPushSubscriptionJSON, V as MushiReportBuilder, W as MushiReportCategory, X as MushiReportStatus, Y as MushiReporterChannelUnavailable, Z as MushiReporterComment, _ as MushiReporterNotificationPrefs, $ as MushiReporterPrefsUpdate, a0 as MushiReporterReport, a1 as MushiReporterReportDetail, a2 as MushiReporterTimelineItem, a3 as MushiReporterUpdates, a4 as MushiReputationResult, a5 as MushiRewardsConfig, a6 as MushiRuntimeSdkConfig, a7 as MushiRuntimeWidgetConfig, a8 as MushiSDKInstance, a9 as MushiSdkVersionInfo, aa as MushiSelectedElement, ab as MushiSentryConfig, ac as MushiSentryContext, ad as MushiSessionEventPayload, ae as MushiTesterReputation, af as MushiTierResult, ag as MushiTimelineEntry, ah as MushiTimelineKind, ai as MushiTracePropagationConfig, aj as MushiUrlMatcher, ak as MushiWidgetAnchor, al as MushiWidgetConfig } from './types-
|
|
1
|
+
import { M as MushiApiClient, a as MushiConfig, b as MushiPreFilterConfig, c as MushiReport, d as MushiOfflineConfig, e as MushiEnvironment, f as MushiAnalyticsConfig, g as MushiPropertyValue, h as MushiBreadcrumb } from './types-DGCkdOm1.cjs';
|
|
2
|
+
export { i as MushiActivityEvent, j as MushiApiCascadeConfig, k as MushiApiResponse, l as MushiAssistantConfig, m as MushiAssistantReply, n as MushiAssistantStep, o as MushiBannerConfig, p as MushiBannerLink, q as MushiBetaChangelogEntry, r as MushiBetaModeConfig, s as MushiCaptureConfig, t as MushiCaptureEventInput, u as MushiCaptureExceptionOptions, v as MushiConsoleEntry, w as MushiCooldownConfig, x as MushiCrossAppReport, y as MushiCustomCategory, z as MushiDiagnosticsResult, A as MushiDiscoverInventoryConfig, B as MushiDiscoveryEventPayload, C as MushiEventHandler, D as MushiEventType, E as MushiHallOfFameEntry, F as MushiInitConfig, G as MushiIntegrationsConfig, H as MushiLeaderboardEntry, I as MushiNetworkEntry, J as MushiNotificationsConfig, K as MushiOnDeviceClassifier, L as MushiOnDeviceClassifierInput, N as MushiOnDeviceClassifierResult, O as MushiPageContext, P as MushiPerformanceMetrics, Q as MushiPreset, R as MushiPrivacyConfig, S as MushiProactiveConfig, T as MushiProductEventPayload, U as MushiPushSubscriptionJSON, V as MushiReportBuilder, W as MushiReportCategory, X as MushiReportStatus, Y as MushiReporterChannelUnavailable, Z as MushiReporterComment, _ as MushiReporterNotificationPrefs, $ as MushiReporterPrefsUpdate, a0 as MushiReporterReport, a1 as MushiReporterReportDetail, a2 as MushiReporterTimelineItem, a3 as MushiReporterUpdates, a4 as MushiReputationResult, a5 as MushiRewardsConfig, a6 as MushiRuntimeSdkConfig, a7 as MushiRuntimeWidgetConfig, a8 as MushiSDKInstance, a9 as MushiSdkVersionInfo, aa as MushiSelectedElement, ab as MushiSentryConfig, ac as MushiSentryContext, ad as MushiSessionEventPayload, ae as MushiTesterReputation, af as MushiTierResult, ag as MushiTimelineEntry, ah as MushiTimelineKind, ai as MushiTracePropagationConfig, aj as MushiUrlMatcher, ak as MushiWidgetAnchor, al as MushiWidgetConfig } from './types-DGCkdOm1.cjs';
|
|
3
3
|
|
|
4
4
|
/** Replay the in-flight POST via keepalive/beacon during pagehide. */
|
|
5
5
|
declare function flushLastOutboundOnUnload(): boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MushiApiClient, a as MushiConfig, b as MushiPreFilterConfig, c as MushiReport, d as MushiOfflineConfig, e as MushiEnvironment, f as MushiAnalyticsConfig, g as MushiPropertyValue, h as MushiBreadcrumb } from './types-
|
|
2
|
-
export { i as MushiActivityEvent, j as MushiApiCascadeConfig, k as MushiApiResponse, l as MushiAssistantConfig, m as MushiAssistantReply, n as MushiAssistantStep, o as MushiBannerConfig, p as MushiBannerLink, q as MushiBetaChangelogEntry, r as MushiBetaModeConfig, s as MushiCaptureConfig, t as MushiCaptureEventInput, u as MushiCaptureExceptionOptions, v as MushiConsoleEntry, w as MushiCooldownConfig, x as MushiCrossAppReport, y as MushiCustomCategory, z as MushiDiagnosticsResult, A as MushiDiscoverInventoryConfig, B as MushiDiscoveryEventPayload, C as MushiEventHandler, D as MushiEventType, E as MushiHallOfFameEntry, F as MushiInitConfig, G as MushiIntegrationsConfig, H as MushiLeaderboardEntry, I as MushiNetworkEntry, J as MushiNotificationsConfig, K as MushiOnDeviceClassifier, L as MushiOnDeviceClassifierInput, N as MushiOnDeviceClassifierResult, O as MushiPageContext, P as MushiPerformanceMetrics, Q as MushiPreset, R as MushiPrivacyConfig, S as MushiProactiveConfig, T as MushiProductEventPayload, U as MushiPushSubscriptionJSON, V as MushiReportBuilder, W as MushiReportCategory, X as MushiReportStatus, Y as MushiReporterChannelUnavailable, Z as MushiReporterComment, _ as MushiReporterNotificationPrefs, $ as MushiReporterPrefsUpdate, a0 as MushiReporterReport, a1 as MushiReporterReportDetail, a2 as MushiReporterTimelineItem, a3 as MushiReporterUpdates, a4 as MushiReputationResult, a5 as MushiRewardsConfig, a6 as MushiRuntimeSdkConfig, a7 as MushiRuntimeWidgetConfig, a8 as MushiSDKInstance, a9 as MushiSdkVersionInfo, aa as MushiSelectedElement, ab as MushiSentryConfig, ac as MushiSentryContext, ad as MushiSessionEventPayload, ae as MushiTesterReputation, af as MushiTierResult, ag as MushiTimelineEntry, ah as MushiTimelineKind, ai as MushiTracePropagationConfig, aj as MushiUrlMatcher, ak as MushiWidgetAnchor, al as MushiWidgetConfig } from './types-
|
|
1
|
+
import { M as MushiApiClient, a as MushiConfig, b as MushiPreFilterConfig, c as MushiReport, d as MushiOfflineConfig, e as MushiEnvironment, f as MushiAnalyticsConfig, g as MushiPropertyValue, h as MushiBreadcrumb } from './types-DGCkdOm1.js';
|
|
2
|
+
export { i as MushiActivityEvent, j as MushiApiCascadeConfig, k as MushiApiResponse, l as MushiAssistantConfig, m as MushiAssistantReply, n as MushiAssistantStep, o as MushiBannerConfig, p as MushiBannerLink, q as MushiBetaChangelogEntry, r as MushiBetaModeConfig, s as MushiCaptureConfig, t as MushiCaptureEventInput, u as MushiCaptureExceptionOptions, v as MushiConsoleEntry, w as MushiCooldownConfig, x as MushiCrossAppReport, y as MushiCustomCategory, z as MushiDiagnosticsResult, A as MushiDiscoverInventoryConfig, B as MushiDiscoveryEventPayload, C as MushiEventHandler, D as MushiEventType, E as MushiHallOfFameEntry, F as MushiInitConfig, G as MushiIntegrationsConfig, H as MushiLeaderboardEntry, I as MushiNetworkEntry, J as MushiNotificationsConfig, K as MushiOnDeviceClassifier, L as MushiOnDeviceClassifierInput, N as MushiOnDeviceClassifierResult, O as MushiPageContext, P as MushiPerformanceMetrics, Q as MushiPreset, R as MushiPrivacyConfig, S as MushiProactiveConfig, T as MushiProductEventPayload, U as MushiPushSubscriptionJSON, V as MushiReportBuilder, W as MushiReportCategory, X as MushiReportStatus, Y as MushiReporterChannelUnavailable, Z as MushiReporterComment, _ as MushiReporterNotificationPrefs, $ as MushiReporterPrefsUpdate, a0 as MushiReporterReport, a1 as MushiReporterReportDetail, a2 as MushiReporterTimelineItem, a3 as MushiReporterUpdates, a4 as MushiReputationResult, a5 as MushiRewardsConfig, a6 as MushiRuntimeSdkConfig, a7 as MushiRuntimeWidgetConfig, a8 as MushiSDKInstance, a9 as MushiSdkVersionInfo, aa as MushiSelectedElement, ab as MushiSentryConfig, ac as MushiSentryContext, ad as MushiSessionEventPayload, ae as MushiTesterReputation, af as MushiTierResult, ag as MushiTimelineEntry, ah as MushiTimelineKind, ai as MushiTracePropagationConfig, aj as MushiUrlMatcher, ak as MushiWidgetAnchor, al as MushiWidgetConfig } from './types-DGCkdOm1.js';
|
|
3
3
|
|
|
4
4
|
/** Replay the in-flight POST via keepalive/beacon during pagehide. */
|
|
5
5
|
declare function flushLastOutboundOnUnload(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { U as MushiPushSubscriptionJSON, Y as MushiReporterChannelUnavailable, am as MushiReporterChannels, _ as MushiReporterNotificationPrefs, $ as MushiReporterPrefsUpdate, a1 as MushiReporterReportDetail, a2 as MushiReporterTimelineItem, a3 as MushiReporterUpdates, an as reporterChannels, ao as subscribeBrowserPush } from './types-
|
|
1
|
+
export { U as MushiPushSubscriptionJSON, Y as MushiReporterChannelUnavailable, am as MushiReporterChannels, _ as MushiReporterNotificationPrefs, $ as MushiReporterPrefsUpdate, a1 as MushiReporterReportDetail, a2 as MushiReporterTimelineItem, a3 as MushiReporterUpdates, an as reporterChannels, ao as subscribeBrowserPush } from './types-DGCkdOm1.cjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { U as MushiPushSubscriptionJSON, Y as MushiReporterChannelUnavailable, am as MushiReporterChannels, _ as MushiReporterNotificationPrefs, $ as MushiReporterPrefsUpdate, a1 as MushiReporterReportDetail, a2 as MushiReporterTimelineItem, a3 as MushiReporterUpdates, an as reporterChannels, ao as subscribeBrowserPush } from './types-
|
|
1
|
+
export { U as MushiPushSubscriptionJSON, Y as MushiReporterChannelUnavailable, am as MushiReporterChannels, _ as MushiReporterNotificationPrefs, $ as MushiReporterPrefsUpdate, a1 as MushiReporterReportDetail, a2 as MushiReporterTimelineItem, a3 as MushiReporterUpdates, an as reporterChannels, ao as subscribeBrowserPush } from './types-DGCkdOm1.js';
|
|
@@ -1554,6 +1554,15 @@ interface MushiSDKInstance {
|
|
|
1554
1554
|
name?: string;
|
|
1555
1555
|
}): void;
|
|
1556
1556
|
setMetadata(key: string, value: unknown): void;
|
|
1557
|
+
/**
|
|
1558
|
+
* Diagnostics read when the reporter presses Send (load timings, the last
|
|
1559
|
+
* errors your app logged, connection state). Its keys merge into the report's
|
|
1560
|
+
* metadata; triage reads `screenLoading` / `timings` lines. Gets 300 ms, is
|
|
1561
|
+
* PII-scrubbed and size-capped; a slow or throwing provider never blocks or
|
|
1562
|
+
* drops the report. Keep amounts, names and other personal data out.
|
|
1563
|
+
* Pass `null` to remove it.
|
|
1564
|
+
*/
|
|
1565
|
+
setDiagnosticsProvider(provider: (() => Record<string, unknown> | null | undefined | Promise<Record<string, unknown> | null | undefined>) | null): void;
|
|
1557
1566
|
setScreen(screen: {
|
|
1558
1567
|
name: string;
|
|
1559
1568
|
route?: string;
|
|
@@ -1554,6 +1554,15 @@ interface MushiSDKInstance {
|
|
|
1554
1554
|
name?: string;
|
|
1555
1555
|
}): void;
|
|
1556
1556
|
setMetadata(key: string, value: unknown): void;
|
|
1557
|
+
/**
|
|
1558
|
+
* Diagnostics read when the reporter presses Send (load timings, the last
|
|
1559
|
+
* errors your app logged, connection state). Its keys merge into the report's
|
|
1560
|
+
* metadata; triage reads `screenLoading` / `timings` lines. Gets 300 ms, is
|
|
1561
|
+
* PII-scrubbed and size-capped; a slow or throwing provider never blocks or
|
|
1562
|
+
* drops the report. Keep amounts, names and other personal data out.
|
|
1563
|
+
* Pass `null` to remove it.
|
|
1564
|
+
*/
|
|
1565
|
+
setDiagnosticsProvider(provider: (() => Record<string, unknown> | null | undefined | Promise<Record<string, unknown> | null | undefined>) | null): void;
|
|
1557
1566
|
setScreen(screen: {
|
|
1558
1567
|
name: string;
|
|
1559
1568
|
route?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mushi-mushi/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.0",
|
|
4
4
|
"description": "Mushi Mushi SDK types, API client, pre-filter. One place to improve AI-built apps: fix bugs, smooth user journeys and clean up the code.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,6 +37,16 @@
|
|
|
37
37
|
"types": "./dist/reporter-channels.d.cts",
|
|
38
38
|
"default": "./dist/reporter-channels.cjs"
|
|
39
39
|
}
|
|
40
|
+
},
|
|
41
|
+
"./diagnostics": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/diagnostics.d.ts",
|
|
44
|
+
"default": "./dist/diagnostics.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/diagnostics.d.cts",
|
|
48
|
+
"default": "./dist/diagnostics.cjs"
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
51
|
},
|
|
42
52
|
"typesVersions": {
|
|
@@ -46,6 +56,9 @@
|
|
|
46
56
|
],
|
|
47
57
|
"reporter-channels": [
|
|
48
58
|
"./dist/reporter-channels.d.ts"
|
|
59
|
+
],
|
|
60
|
+
"diagnostics": [
|
|
61
|
+
"./dist/diagnostics.d.ts"
|
|
49
62
|
]
|
|
50
63
|
}
|
|
51
64
|
},
|