@mushi-mushi/web 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,7 +46,7 @@ Each trigger respects its config flag — set `rageClick: false` to disable rage
46
46
 
47
47
  ## Bundle Size
48
48
 
49
- ~6 KB brotli (limit: 30 KB). Requires `@mushi-mushi/core` as a dependency (not bundled inline).
49
+ ~6 KB brotli, enforced at **15 KB gzipped** via `size-limit` in CI. Requires `@mushi-mushi/core` as a dependency (not bundled inline). The `./test-utils` entry is a separate artifact and is never pulled into production bundles.
50
50
 
51
51
  ## Quick Start
52
52
 
@@ -99,6 +99,28 @@ setupProactiveTriggers({
99
99
  });
100
100
  ```
101
101
 
102
+ ## Test utilities (`./test-utils`)
103
+
104
+ Deterministic Playwright / jsdom helpers, published as a separate
105
+ entry-point so production bundles pay nothing for them:
106
+
107
+ ```ts
108
+ import { triggerBug, openReport, waitForQueueDrain } from '@mushi-mushi/web/test-utils';
109
+ ```
110
+
111
+ | Export | Purpose |
112
+ |---------------------|-------------------------------------------------------------------------|
113
+ | `triggerBug(opts?)` | Submit a report bypassing the widget. Returns the server-assigned id. |
114
+ | `openReport(cat?)` | Open the widget programmatically without submitting. |
115
+ | `waitForQueueDrain` | Resolve once the offline queue is empty (number remaining at timeout). |
116
+
117
+ Every helper no-ops when `Mushi.getInstance()` returns `null`, so
118
+ conditional-wiring tests (e.g. cloud vs local targets) don't need to
119
+ branch. For browser-context use in Playwright's `page.evaluate`, import
120
+ the SDK via the app's own bundle (`window.__mushi__` in dev builds) or
121
+ POST to `/v1/reports` directly — `page.evaluate` has no npm resolver in
122
+ the browser context.
123
+
102
124
  ## License
103
125
 
104
126
  MIT
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ require('@mushi-mushi/core');
4
+
5
+ // src/mushi.ts
6
+
7
+ // src/test-utils.ts
8
+ async function triggerBug(opts = {}) {
9
+ return null;
10
+ }
11
+ function openReport(category) {
12
+ return;
13
+ }
14
+ async function waitForQueueDrain(options = {}) {
15
+ return 0;
16
+ }
17
+
18
+ exports.openReport = openReport;
19
+ exports.triggerBug = triggerBug;
20
+ exports.waitForQueueDrain = waitForQueueDrain;
21
+ //# sourceMappingURL=test-utils.cjs.map
22
+ //# sourceMappingURL=test-utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/test-utils.ts"],"names":[],"mappings":";;;;;;;AAsDA,eAAsB,UAAA,CAAW,IAAA,GAA0B,EAAC,EAA2B;AAErF,EAAU,OAAO,IAAA;AAqBnB;AAOO,SAAS,WAAW,QAAA,EAAsC;AAE/D,EAAU;AAEZ;AAOA,eAAsB,iBAAA,CAAkB,OAAA,GAAkC,EAAC,EAAoB;AAE7F,EAAU,OAAO,CAAA;AAenB","file":"test-utils.cjs","sourcesContent":["/**\n * @mushi-mushi/web/test-utils\n *\n * Playwright / jsdom helpers for deterministic SDK tests. This module is\n * published as a separate entry-point so production bundles never pay the\n * cost — import it via `import { triggerBug, openReport } from\n * '@mushi-mushi/web/test-utils'`.\n *\n * Design goals:\n * 1. Zero production footprint. Nothing here is imported from `./mushi`,\n * `./widget`, or any runtime module. We reach for the live SDK via\n * `Mushi.getInstance()` so the test process sees exactly what the app\n * bootstrapped — no duplicate SDK singletons, no double-init races.\n * 2. Safe in a test harness even when Mushi is disabled. Every helper\n * no-ops when `Mushi.getInstance()` returns `null`, so Playwright\n * specs that conditionally wire Mushi (e.g. cloud vs local targets)\n * don't have to branch.\n * 3. Flat surface. Tests want 3 verbs: \"open the widget\", \"submit a\n * report programmatically\", \"wait until the SDK confirms the POST\n * landed\". Anything beyond that belongs in the app under test.\n */\n\nimport { Mushi } from './mushi';\nimport type {\n MushiReportCategory,\n MushiSDKInstance,\n} from '@mushi-mushi/core';\n\n/** Options accepted by `triggerBug`. Mirrors the core report contract but\n * keeps every field optional so a Playwright test can say\n * `triggerBug({ description: 'button dead' })` without a category. */\nexport interface TriggerBugOptions {\n /** Short free-text description of the issue. Defaults to a marker\n * string so tests that forget to pass a description still produce a\n * distinguishable report in the admin console. */\n description?: string;\n /** Severity-free category tag. */\n category?: MushiReportCategory;\n /** Arbitrary metadata the test wants to round-trip. Merged on top of\n * whatever `setMetadata` has already stored. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Submit a report bypassing the widget UI. Returns the server-assigned\n * `reportId` when the POST lands, or `null` if Mushi isn't initialised in\n * this test context (or the submit failed — the SDK swallows network\n * errors silently by design).\n *\n * Use this from Playwright `page.evaluate(...)` calls to round-trip a\n * report into the backend without needing to drive the widget's DOM. It's\n * the fastest way to assert \"a bug report made it from the browser into\n * reports/ in Supabase\".\n */\nexport async function triggerBug(opts: TriggerBugOptions = {}): Promise<string | null> {\n const sdk = Mushi.getInstance();\n if (!sdk) return null;\n\n const description = opts.description\n ?? `[test-utils] triggerBug marker ${new Date().toISOString()}`;\n\n if (opts.metadata) {\n for (const [k, v] of Object.entries(opts.metadata)) {\n try { sdk.setMetadata(k, v); } catch { /* ignore */ }\n }\n }\n\n // `captureEvent` is the documented programmatic-submit API since 0.3.0\n // — it bypasses the widget, resolves with the server-assigned report\n // id, and participates in the same offline queue / pre-filter pipeline\n // as a widget submission.\n return await sdk.captureEvent({\n description,\n source: 'test-utils',\n ...(opts.category ? { category: opts.category } : {}),\n ...(opts.metadata ? { metadata: opts.metadata } : {}),\n });\n}\n\n/**\n * Programmatically open the Mushi widget without submitting anything. Use\n * for interaction tests that want to assert \"the widget is mounted and\n * reachable\" or to drive a user-like flow via Playwright selectors.\n */\nexport function openReport(category?: MushiReportCategory): void {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n sdk.report(category ? { category } : undefined);\n}\n\n/**\n * Wait until the offline queue drains — useful after `triggerBug` in tests\n * that submit while offline then assert the report eventually syncs.\n * Resolves with the number of queued items remaining (0 = fully drained).\n */\nexport async function waitForQueueDrain(options: { timeoutMs?: number } = {}): Promise<number> {\n const sdk = Mushi.getInstance();\n if (!sdk) return 0;\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n // The SDK instance doesn't publicly expose the queue, but `getQueueSize`\n // has been in the contract since 0.2.x. We tolerate its absence so\n // upgrading doesn't break tests that only need triggerBug/openReport.\n const getQueueSize = (sdk as MushiSDKInstance & { getQueueSize?: () => number }).getQueueSize;\n if (typeof getQueueSize !== 'function') return 0;\n\n while (Date.now() - started < timeoutMs) {\n const remaining = getQueueSize.call(sdk);\n if (remaining === 0) return 0;\n await new Promise((r) => setTimeout(r, 100));\n }\n return getQueueSize.call(sdk);\n}\n"]}
@@ -0,0 +1,66 @@
1
+ import { MushiReportCategory } from '@mushi-mushi/core';
2
+
3
+ /**
4
+ * @mushi-mushi/web/test-utils
5
+ *
6
+ * Playwright / jsdom helpers for deterministic SDK tests. This module is
7
+ * published as a separate entry-point so production bundles never pay the
8
+ * cost — import it via `import { triggerBug, openReport } from
9
+ * '@mushi-mushi/web/test-utils'`.
10
+ *
11
+ * Design goals:
12
+ * 1. Zero production footprint. Nothing here is imported from `./mushi`,
13
+ * `./widget`, or any runtime module. We reach for the live SDK via
14
+ * `Mushi.getInstance()` so the test process sees exactly what the app
15
+ * bootstrapped — no duplicate SDK singletons, no double-init races.
16
+ * 2. Safe in a test harness even when Mushi is disabled. Every helper
17
+ * no-ops when `Mushi.getInstance()` returns `null`, so Playwright
18
+ * specs that conditionally wire Mushi (e.g. cloud vs local targets)
19
+ * don't have to branch.
20
+ * 3. Flat surface. Tests want 3 verbs: "open the widget", "submit a
21
+ * report programmatically", "wait until the SDK confirms the POST
22
+ * landed". Anything beyond that belongs in the app under test.
23
+ */
24
+
25
+ /** Options accepted by `triggerBug`. Mirrors the core report contract but
26
+ * keeps every field optional so a Playwright test can say
27
+ * `triggerBug({ description: 'button dead' })` without a category. */
28
+ interface TriggerBugOptions {
29
+ /** Short free-text description of the issue. Defaults to a marker
30
+ * string so tests that forget to pass a description still produce a
31
+ * distinguishable report in the admin console. */
32
+ description?: string;
33
+ /** Severity-free category tag. */
34
+ category?: MushiReportCategory;
35
+ /** Arbitrary metadata the test wants to round-trip. Merged on top of
36
+ * whatever `setMetadata` has already stored. */
37
+ metadata?: Record<string, unknown>;
38
+ }
39
+ /**
40
+ * Submit a report bypassing the widget UI. Returns the server-assigned
41
+ * `reportId` when the POST lands, or `null` if Mushi isn't initialised in
42
+ * this test context (or the submit failed — the SDK swallows network
43
+ * errors silently by design).
44
+ *
45
+ * Use this from Playwright `page.evaluate(...)` calls to round-trip a
46
+ * report into the backend without needing to drive the widget's DOM. It's
47
+ * the fastest way to assert "a bug report made it from the browser into
48
+ * reports/ in Supabase".
49
+ */
50
+ declare function triggerBug(opts?: TriggerBugOptions): Promise<string | null>;
51
+ /**
52
+ * Programmatically open the Mushi widget without submitting anything. Use
53
+ * for interaction tests that want to assert "the widget is mounted and
54
+ * reachable" or to drive a user-like flow via Playwright selectors.
55
+ */
56
+ declare function openReport(category?: MushiReportCategory): void;
57
+ /**
58
+ * Wait until the offline queue drains — useful after `triggerBug` in tests
59
+ * that submit while offline then assert the report eventually syncs.
60
+ * Resolves with the number of queued items remaining (0 = fully drained).
61
+ */
62
+ declare function waitForQueueDrain(options?: {
63
+ timeoutMs?: number;
64
+ }): Promise<number>;
65
+
66
+ export { type TriggerBugOptions, openReport, triggerBug, waitForQueueDrain };
@@ -0,0 +1,66 @@
1
+ import { MushiReportCategory } from '@mushi-mushi/core';
2
+
3
+ /**
4
+ * @mushi-mushi/web/test-utils
5
+ *
6
+ * Playwright / jsdom helpers for deterministic SDK tests. This module is
7
+ * published as a separate entry-point so production bundles never pay the
8
+ * cost — import it via `import { triggerBug, openReport } from
9
+ * '@mushi-mushi/web/test-utils'`.
10
+ *
11
+ * Design goals:
12
+ * 1. Zero production footprint. Nothing here is imported from `./mushi`,
13
+ * `./widget`, or any runtime module. We reach for the live SDK via
14
+ * `Mushi.getInstance()` so the test process sees exactly what the app
15
+ * bootstrapped — no duplicate SDK singletons, no double-init races.
16
+ * 2. Safe in a test harness even when Mushi is disabled. Every helper
17
+ * no-ops when `Mushi.getInstance()` returns `null`, so Playwright
18
+ * specs that conditionally wire Mushi (e.g. cloud vs local targets)
19
+ * don't have to branch.
20
+ * 3. Flat surface. Tests want 3 verbs: "open the widget", "submit a
21
+ * report programmatically", "wait until the SDK confirms the POST
22
+ * landed". Anything beyond that belongs in the app under test.
23
+ */
24
+
25
+ /** Options accepted by `triggerBug`. Mirrors the core report contract but
26
+ * keeps every field optional so a Playwright test can say
27
+ * `triggerBug({ description: 'button dead' })` without a category. */
28
+ interface TriggerBugOptions {
29
+ /** Short free-text description of the issue. Defaults to a marker
30
+ * string so tests that forget to pass a description still produce a
31
+ * distinguishable report in the admin console. */
32
+ description?: string;
33
+ /** Severity-free category tag. */
34
+ category?: MushiReportCategory;
35
+ /** Arbitrary metadata the test wants to round-trip. Merged on top of
36
+ * whatever `setMetadata` has already stored. */
37
+ metadata?: Record<string, unknown>;
38
+ }
39
+ /**
40
+ * Submit a report bypassing the widget UI. Returns the server-assigned
41
+ * `reportId` when the POST lands, or `null` if Mushi isn't initialised in
42
+ * this test context (or the submit failed — the SDK swallows network
43
+ * errors silently by design).
44
+ *
45
+ * Use this from Playwright `page.evaluate(...)` calls to round-trip a
46
+ * report into the backend without needing to drive the widget's DOM. It's
47
+ * the fastest way to assert "a bug report made it from the browser into
48
+ * reports/ in Supabase".
49
+ */
50
+ declare function triggerBug(opts?: TriggerBugOptions): Promise<string | null>;
51
+ /**
52
+ * Programmatically open the Mushi widget without submitting anything. Use
53
+ * for interaction tests that want to assert "the widget is mounted and
54
+ * reachable" or to drive a user-like flow via Playwright selectors.
55
+ */
56
+ declare function openReport(category?: MushiReportCategory): void;
57
+ /**
58
+ * Wait until the offline queue drains — useful after `triggerBug` in tests
59
+ * that submit while offline then assert the report eventually syncs.
60
+ * Resolves with the number of queued items remaining (0 = fully drained).
61
+ */
62
+ declare function waitForQueueDrain(options?: {
63
+ timeoutMs?: number;
64
+ }): Promise<number>;
65
+
66
+ export { type TriggerBugOptions, openReport, triggerBug, waitForQueueDrain };
@@ -0,0 +1,18 @@
1
+ import '@mushi-mushi/core';
2
+
3
+ // src/mushi.ts
4
+
5
+ // src/test-utils.ts
6
+ async function triggerBug(opts = {}) {
7
+ return null;
8
+ }
9
+ function openReport(category) {
10
+ return;
11
+ }
12
+ async function waitForQueueDrain(options = {}) {
13
+ return 0;
14
+ }
15
+
16
+ export { openReport, triggerBug, waitForQueueDrain };
17
+ //# sourceMappingURL=test-utils.js.map
18
+ //# sourceMappingURL=test-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/test-utils.ts"],"names":[],"mappings":";;;;;AAsDA,eAAsB,UAAA,CAAW,IAAA,GAA0B,EAAC,EAA2B;AAErF,EAAU,OAAO,IAAA;AAqBnB;AAOO,SAAS,WAAW,QAAA,EAAsC;AAE/D,EAAU;AAEZ;AAOA,eAAsB,iBAAA,CAAkB,OAAA,GAAkC,EAAC,EAAoB;AAE7F,EAAU,OAAO,CAAA;AAenB","file":"test-utils.js","sourcesContent":["/**\n * @mushi-mushi/web/test-utils\n *\n * Playwright / jsdom helpers for deterministic SDK tests. This module is\n * published as a separate entry-point so production bundles never pay the\n * cost — import it via `import { triggerBug, openReport } from\n * '@mushi-mushi/web/test-utils'`.\n *\n * Design goals:\n * 1. Zero production footprint. Nothing here is imported from `./mushi`,\n * `./widget`, or any runtime module. We reach for the live SDK via\n * `Mushi.getInstance()` so the test process sees exactly what the app\n * bootstrapped — no duplicate SDK singletons, no double-init races.\n * 2. Safe in a test harness even when Mushi is disabled. Every helper\n * no-ops when `Mushi.getInstance()` returns `null`, so Playwright\n * specs that conditionally wire Mushi (e.g. cloud vs local targets)\n * don't have to branch.\n * 3. Flat surface. Tests want 3 verbs: \"open the widget\", \"submit a\n * report programmatically\", \"wait until the SDK confirms the POST\n * landed\". Anything beyond that belongs in the app under test.\n */\n\nimport { Mushi } from './mushi';\nimport type {\n MushiReportCategory,\n MushiSDKInstance,\n} from '@mushi-mushi/core';\n\n/** Options accepted by `triggerBug`. Mirrors the core report contract but\n * keeps every field optional so a Playwright test can say\n * `triggerBug({ description: 'button dead' })` without a category. */\nexport interface TriggerBugOptions {\n /** Short free-text description of the issue. Defaults to a marker\n * string so tests that forget to pass a description still produce a\n * distinguishable report in the admin console. */\n description?: string;\n /** Severity-free category tag. */\n category?: MushiReportCategory;\n /** Arbitrary metadata the test wants to round-trip. Merged on top of\n * whatever `setMetadata` has already stored. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Submit a report bypassing the widget UI. Returns the server-assigned\n * `reportId` when the POST lands, or `null` if Mushi isn't initialised in\n * this test context (or the submit failed — the SDK swallows network\n * errors silently by design).\n *\n * Use this from Playwright `page.evaluate(...)` calls to round-trip a\n * report into the backend without needing to drive the widget's DOM. It's\n * the fastest way to assert \"a bug report made it from the browser into\n * reports/ in Supabase\".\n */\nexport async function triggerBug(opts: TriggerBugOptions = {}): Promise<string | null> {\n const sdk = Mushi.getInstance();\n if (!sdk) return null;\n\n const description = opts.description\n ?? `[test-utils] triggerBug marker ${new Date().toISOString()}`;\n\n if (opts.metadata) {\n for (const [k, v] of Object.entries(opts.metadata)) {\n try { sdk.setMetadata(k, v); } catch { /* ignore */ }\n }\n }\n\n // `captureEvent` is the documented programmatic-submit API since 0.3.0\n // — it bypasses the widget, resolves with the server-assigned report\n // id, and participates in the same offline queue / pre-filter pipeline\n // as a widget submission.\n return await sdk.captureEvent({\n description,\n source: 'test-utils',\n ...(opts.category ? { category: opts.category } : {}),\n ...(opts.metadata ? { metadata: opts.metadata } : {}),\n });\n}\n\n/**\n * Programmatically open the Mushi widget without submitting anything. Use\n * for interaction tests that want to assert \"the widget is mounted and\n * reachable\" or to drive a user-like flow via Playwright selectors.\n */\nexport function openReport(category?: MushiReportCategory): void {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n sdk.report(category ? { category } : undefined);\n}\n\n/**\n * Wait until the offline queue drains — useful after `triggerBug` in tests\n * that submit while offline then assert the report eventually syncs.\n * Resolves with the number of queued items remaining (0 = fully drained).\n */\nexport async function waitForQueueDrain(options: { timeoutMs?: number } = {}): Promise<number> {\n const sdk = Mushi.getInstance();\n if (!sdk) return 0;\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n // The SDK instance doesn't publicly expose the queue, but `getQueueSize`\n // has been in the contract since 0.2.x. We tolerate its absence so\n // upgrading doesn't break tests that only need triggerBug/openReport.\n const getQueueSize = (sdk as MushiSDKInstance & { getQueueSize?: () => number }).getQueueSize;\n if (typeof getQueueSize !== 'function') return 0;\n\n while (Date.now() - started < timeoutMs) {\n const remaining = getQueueSize.call(sdk);\n if (remaining === 0) return 0;\n await new Promise((r) => setTimeout(r, 100));\n }\n return getQueueSize.call(sdk);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mushi-mushi/web",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "Mushi Mushi browser SDK — embeddable bug reporting widget with Shadow DOM isolation",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,6 +17,16 @@
17
17
  "types": "./dist/index.d.cts",
18
18
  "default": "./dist/index.cjs"
19
19
  }
20
+ },
21
+ "./test-utils": {
22
+ "import": {
23
+ "types": "./dist/test-utils.d.ts",
24
+ "default": "./dist/test-utils.js"
25
+ },
26
+ "require": {
27
+ "types": "./dist/test-utils.d.cts",
28
+ "default": "./dist/test-utils.cjs"
29
+ }
20
30
  }
21
31
  },
22
32
  "files": [
@@ -40,6 +50,8 @@
40
50
  "mushi-mushi",
41
51
  "bug-reporting",
42
52
  "user-feedback",
53
+ "user-report",
54
+ "feedback-widget",
43
55
  "browser-sdk",
44
56
  "widget",
45
57
  "shadow-dom",
@@ -52,7 +64,12 @@
52
64
  "angular",
53
65
  "rage-click",
54
66
  "sentry-companion",
67
+ "sentry-alternative",
55
68
  "error-tracking",
69
+ "ai-triage",
70
+ "auto-fix",
71
+ "llm-ops",
72
+ "ai-agent",
56
73
  "sdk"
57
74
  ],
58
75
  "publishConfig": {
@@ -62,12 +79,19 @@
62
79
  "sideEffects": false,
63
80
  "size-limit": [
64
81
  {
82
+ "name": "Core SDK bundle (minified + gzipped)",
65
83
  "path": "dist/index.js",
66
- "limit": "30 KB"
84
+ "limit": "15 KB",
85
+ "gzip": true
86
+ },
87
+ {
88
+ "name": "Core SDK bundle (uncompressed)",
89
+ "path": "dist/index.js",
90
+ "limit": "60 KB"
67
91
  }
68
92
  ],
69
93
  "dependencies": {
70
- "@mushi-mushi/core": "^0.3.1"
94
+ "@mushi-mushi/core": "^0.4.1"
71
95
  },
72
96
  "devDependencies": {
73
97
  "@size-limit/file": "^12.1.0",
@@ -81,6 +105,9 @@
81
105
  "@mushi-mushi/tsconfig": "0.0.0"
82
106
  },
83
107
  "author": "Kenji Sakuramoto",
108
+ "engines": {
109
+ "node": ">=20"
110
+ },
84
111
  "scripts": {
85
112
  "build": "tsup",
86
113
  "dev": "tsup --watch",