bugstack-sdk 2.3.0 → 2.4.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/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to `bugstack-sdk` are documented here.
4
4
  Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
 
6
+ ## [2.4.0] — unreleased
7
+
8
+ ### Added
9
+ - **Browser capture: `bugstack-sdk/browser`.** A dependency-free entry for
10
+ the customer's page: uncaught errors and unhandled rejections, failed
11
+ requests (5xx or no answer) and the route trail, sent to Bugstack's session
12
+ ingest with the repository's public BROWSER key (never the server key).
13
+ Nothing runs until you call `init()`; it is a no-op on the server and
14
+ never throws. Ported from the Bugstack monorepo's `@bugstack/browser`,
15
+ which was never published.
16
+ - **Frustration signals, OFF by default.** `init({ key, frustration: true })`
17
+ also records rage clicks (3+ on one element within 1 s), dead clicks (a
18
+ button or link that changed nothing within 1 s, or a link that landed on a
19
+ not-found page), error clicks (a click followed within 1 s by an uncaught
20
+ error), abandoned forms (a submit that hit a validation error, then left
21
+ without a submit that passed) and thrashing (4+ route changes in 10 s
22
+ alternating between two routes). Each carries a redacted element
23
+ descriptor: a stable selector (tag, id, stable classes, `data-testid`) and
24
+ a visible label cut to 60 characters. Never an input's value, a query
25
+ string or a request body. `frustration: { sampleRate, maxPerPage }` samples
26
+ sessions (once per session) and caps events per page view (default 20).
27
+ The DOM observer the dead-click check needs is installed only when
28
+ frustration is on.
29
+
30
+ ### Changed
31
+ - `npm run build` cleans `dist` once before tsup (two build configs now).
32
+
6
33
  ## [2.3.0] — 2026-11-23
7
34
 
8
35
  ### Added
package/README.md CHANGED
@@ -247,6 +247,48 @@ Put `bugstackWinstonFormat()` first in the chain. `error` and higher levels are
247
247
 
248
248
  ---
249
249
 
250
+ ## Browser Capture and Frustration Signals
251
+
252
+ `bugstack-sdk/browser` runs in your users' browsers. It reports uncaught
253
+ errors, failed requests and the route trail that led there, and, if you opt
254
+ in, **frustration signals**: rage clicks, dead clicks, clicks followed by an
255
+ error, forms abandoned after a validation error, and rapid back-and-forth
256
+ between two pages. Bugstack groups them across sessions and opens an
257
+ incident only when many users hit the same element far more than the rest
258
+ of that page, then anchors it to the page and component that render it.
259
+
260
+ Use the repository's **browser key** from its settings in Bugstack. It is
261
+ public by design and accepted only from your allowed origins; never put the
262
+ server `apiKey` in the browser.
263
+
264
+ ```ts
265
+ // instrumentation-client.ts (Next.js 15.3+, App Router or Pages Router)
266
+ import { init } from "bugstack-sdk/browser";
267
+
268
+ init({
269
+ key: process.env.NEXT_PUBLIC_BUGSTACK_BROWSER_KEY!,
270
+ frustration: true, // OFF unless set
271
+ });
272
+ ```
273
+
274
+ On older Next.js versions, call `init()` once from a `"use client"`
275
+ component in the root layout (App Router) or inside `useEffect` in
276
+ `pages/_app.tsx` (Pages Router). `setUser({ id, email })` names the user;
277
+ Bugstack stores only a keyed hash of it.
278
+
279
+ | Option | Default | What it does |
280
+ |---|---|---|
281
+ | `key` | required | The repository's browser key |
282
+ | `sampleRate` | `1` | Share of sessions recorded at all, decided once per session |
283
+ | `frustration` | off | `true`, or `{ sampleRate, maxPerPage }`: share of recorded sessions that also record frustration, and the most frustration events per page view (default 20) |
284
+ | `release`, `environment` | none | Sent with every batch |
285
+
286
+ What is recorded: element selectors (tag, id, stable classes,
287
+ `data-testid`) and visible labels cut to 60 characters, route paths without
288
+ query strings, request method, path and status. Never input values, text you
289
+ type, query strings, headers or bodies. Every handler is wrapped: the SDK
290
+ never throws into your page and hands back the same responses and errors.
291
+
250
292
  ## Source Maps for Production (Next.js)
251
293
 
252
294
  By default, server-side errors in a Next.js production build come back with stack frames that point at compiled chunks like `.next/server/chunks/8393.js:1:8734`. The Bugstack orchestrator can't fix what it can't locate — so without source maps, those errors land in your dashboard as "Could not identify primary file from error" and never auto-fix.
@@ -472,7 +472,7 @@ function getFirstAppFrame(frames) {
472
472
  }
473
473
 
474
474
  // src/core/sdk-version.ts
475
- var SDK_VERSION = "2.3.0" ;
475
+ var SDK_VERSION = "2.4.0" ;
476
476
 
477
477
  // src/core/logged-errors.ts
478
478
  var DEFAULT_MAX_PER_MINUTE = 20;
@@ -470,7 +470,7 @@ function getFirstAppFrame(frames) {
470
470
  }
471
471
 
472
472
  // src/core/sdk-version.ts
473
- var SDK_VERSION = "2.3.0" ;
473
+ var SDK_VERSION = "2.4.0" ;
474
474
 
475
475
  // src/core/logged-errors.ts
476
476
  var DEFAULT_MAX_PER_MINUTE = 20;
@@ -465,7 +465,7 @@ function getFirstAppFrame(frames) {
465
465
  }
466
466
 
467
467
  // src/core/sdk-version.ts
468
- var SDK_VERSION = "2.3.0" ;
468
+ var SDK_VERSION = "2.4.0" ;
469
469
 
470
470
  // src/core/logged-errors.ts
471
471
  var DEFAULT_MAX_PER_MINUTE = 20;
@@ -463,7 +463,7 @@ function getFirstAppFrame(frames) {
463
463
  }
464
464
 
465
465
  // src/core/sdk-version.ts
466
- var SDK_VERSION = "2.3.0" ;
466
+ var SDK_VERSION = "2.4.0" ;
467
467
 
468
468
  // src/core/logged-errors.ts
469
469
  var DEFAULT_MAX_PER_MINUTE = 20;
@@ -472,7 +472,7 @@ function getFirstAppFrame(frames) {
472
472
  }
473
473
 
474
474
  // src/core/sdk-version.ts
475
- var SDK_VERSION = "2.3.0" ;
475
+ var SDK_VERSION = "2.4.0" ;
476
476
 
477
477
  // src/core/logged-errors.ts
478
478
  var DEFAULT_MAX_PER_MINUTE = 20;
@@ -470,7 +470,7 @@ function getFirstAppFrame(frames) {
470
470
  }
471
471
 
472
472
  // src/core/sdk-version.ts
473
- var SDK_VERSION = "2.3.0" ;
473
+ var SDK_VERSION = "2.4.0" ;
474
474
 
475
475
  // src/core/logged-errors.ts
476
476
  var DEFAULT_MAX_PER_MINUTE = 20;
@@ -0,0 +1,131 @@
1
+ type ElementRef = {
2
+ selector: string;
3
+ label?: string;
4
+ };
5
+ type SessionEvent = {
6
+ kind: "navigation";
7
+ at: string;
8
+ route: string;
9
+ } | {
10
+ kind: "error";
11
+ at: string;
12
+ route: string;
13
+ error: {
14
+ name: string;
15
+ message: string;
16
+ stack?: string;
17
+ };
18
+ } | {
19
+ kind: "failed_request";
20
+ at: string;
21
+ route: string;
22
+ request: {
23
+ method: string;
24
+ path: string;
25
+ status: number | null;
26
+ durationMs: number;
27
+ };
28
+ } | {
29
+ kind: "rage_click";
30
+ at: string;
31
+ route: string;
32
+ element: ElementRef;
33
+ clicks: number;
34
+ } | {
35
+ kind: "dead_click";
36
+ at: string;
37
+ route: string;
38
+ element: ElementRef;
39
+ /** Set when the click DID navigate, to a page that says it does not exist. */
40
+ reason?: "not_found";
41
+ /** For `not_found`: where the link went (path only). */
42
+ to?: string;
43
+ } | {
44
+ kind: "error_click";
45
+ at: string;
46
+ route: string;
47
+ element: ElementRef;
48
+ /** The error's class and a short message; the full error is its own `error` event. */
49
+ error: {
50
+ name: string;
51
+ message: string;
52
+ };
53
+ } | {
54
+ kind: "form_abandon";
55
+ at: string;
56
+ route: string;
57
+ /** The form: its selector, labelled by its submit control. */
58
+ element: ElementRef;
59
+ /** Fields that showed a validation error: selector and label, never a value. */
60
+ fields: ElementRef[];
61
+ /** Submits that hit a validation error. */
62
+ attempts: number;
63
+ } | {
64
+ kind: "thrash";
65
+ at: string;
66
+ route: string;
67
+ routes: [string, string];
68
+ switches: number;
69
+ };
70
+ type SessionUser = {
71
+ id?: string;
72
+ email?: string;
73
+ };
74
+ type SessionBatch = {
75
+ v: 1;
76
+ sessionId: string;
77
+ user?: SessionUser;
78
+ release?: string;
79
+ environment?: string;
80
+ events: SessionEvent[];
81
+ };
82
+ type BrowserConfig = {
83
+ /** The repository's BROWSER key (public; never the server SDK key). */
84
+ key: string;
85
+ /** Defaults to https://dashboard.bugstack.ai/api/v1/sessions/ingest. */
86
+ endpoint?: string;
87
+ /** The release the page is running, e.g. "web@1.4.2". */
88
+ release?: string;
89
+ environment?: string;
90
+ /** Share of browser sessions recorded, 0..1. Default 1. Decided once per session. */
91
+ sampleRate?: number;
92
+ /**
93
+ * Frustration signals: rage clicks, dead clicks, clicks followed by an
94
+ * error, forms left after a validation error, and rapid back-and-forth
95
+ * between two pages. OFF unless set. `true`, or an object to tune it.
96
+ * Never records an input's value or any text beyond a short element label.
97
+ */
98
+ frustration?: boolean | FrustrationConfig;
99
+ };
100
+ type FrustrationConfig = {
101
+ /** Default true when the object is given. */
102
+ enabled?: boolean;
103
+ /** Share of RECORDED sessions that also record frustration, 0..1. Default 1. Decided once per session. */
104
+ sampleRate?: number;
105
+ /** The most frustration events one page view sends. Default 20. */
106
+ maxPerPage?: number;
107
+ };
108
+
109
+ declare const DEFAULT_ENDPOINT = "https://dashboard.bugstack.ai/api/v1/sessions/ingest";
110
+
111
+ /**
112
+ * Start recording this browser session. Call once, as early as you can. A
113
+ * second call is ignored; close() first to start over.
114
+ */
115
+ declare function init(config: BrowserConfig): void;
116
+ /**
117
+ * Who this session belongs to. bugstack stores only a salted hash of it, which
118
+ * is how a support ticket from the same person finds what they saw. Pass null
119
+ * on sign-out.
120
+ */
121
+ declare function setUser(user: SessionUser | null): void;
122
+ /** Report an error you caught yourself. */
123
+ declare function captureError(err: unknown): void;
124
+ /** Send what is queued now. Resolves when the send settles; never rejects. */
125
+ declare function flush(): Promise<void>;
126
+ /** Stop recording: send what is queued, remove every listener and wrapper. */
127
+ declare function close(): void;
128
+ /** The current session id, or null when not recording. */
129
+ declare function getSessionId(): string | null;
130
+
131
+ export { type BrowserConfig, DEFAULT_ENDPOINT, type ElementRef, type FrustrationConfig, type SessionBatch, type SessionEvent, type SessionUser, captureError, close, flush, getSessionId, init, setUser };
@@ -0,0 +1,131 @@
1
+ type ElementRef = {
2
+ selector: string;
3
+ label?: string;
4
+ };
5
+ type SessionEvent = {
6
+ kind: "navigation";
7
+ at: string;
8
+ route: string;
9
+ } | {
10
+ kind: "error";
11
+ at: string;
12
+ route: string;
13
+ error: {
14
+ name: string;
15
+ message: string;
16
+ stack?: string;
17
+ };
18
+ } | {
19
+ kind: "failed_request";
20
+ at: string;
21
+ route: string;
22
+ request: {
23
+ method: string;
24
+ path: string;
25
+ status: number | null;
26
+ durationMs: number;
27
+ };
28
+ } | {
29
+ kind: "rage_click";
30
+ at: string;
31
+ route: string;
32
+ element: ElementRef;
33
+ clicks: number;
34
+ } | {
35
+ kind: "dead_click";
36
+ at: string;
37
+ route: string;
38
+ element: ElementRef;
39
+ /** Set when the click DID navigate, to a page that says it does not exist. */
40
+ reason?: "not_found";
41
+ /** For `not_found`: where the link went (path only). */
42
+ to?: string;
43
+ } | {
44
+ kind: "error_click";
45
+ at: string;
46
+ route: string;
47
+ element: ElementRef;
48
+ /** The error's class and a short message; the full error is its own `error` event. */
49
+ error: {
50
+ name: string;
51
+ message: string;
52
+ };
53
+ } | {
54
+ kind: "form_abandon";
55
+ at: string;
56
+ route: string;
57
+ /** The form: its selector, labelled by its submit control. */
58
+ element: ElementRef;
59
+ /** Fields that showed a validation error: selector and label, never a value. */
60
+ fields: ElementRef[];
61
+ /** Submits that hit a validation error. */
62
+ attempts: number;
63
+ } | {
64
+ kind: "thrash";
65
+ at: string;
66
+ route: string;
67
+ routes: [string, string];
68
+ switches: number;
69
+ };
70
+ type SessionUser = {
71
+ id?: string;
72
+ email?: string;
73
+ };
74
+ type SessionBatch = {
75
+ v: 1;
76
+ sessionId: string;
77
+ user?: SessionUser;
78
+ release?: string;
79
+ environment?: string;
80
+ events: SessionEvent[];
81
+ };
82
+ type BrowserConfig = {
83
+ /** The repository's BROWSER key (public; never the server SDK key). */
84
+ key: string;
85
+ /** Defaults to https://dashboard.bugstack.ai/api/v1/sessions/ingest. */
86
+ endpoint?: string;
87
+ /** The release the page is running, e.g. "web@1.4.2". */
88
+ release?: string;
89
+ environment?: string;
90
+ /** Share of browser sessions recorded, 0..1. Default 1. Decided once per session. */
91
+ sampleRate?: number;
92
+ /**
93
+ * Frustration signals: rage clicks, dead clicks, clicks followed by an
94
+ * error, forms left after a validation error, and rapid back-and-forth
95
+ * between two pages. OFF unless set. `true`, or an object to tune it.
96
+ * Never records an input's value or any text beyond a short element label.
97
+ */
98
+ frustration?: boolean | FrustrationConfig;
99
+ };
100
+ type FrustrationConfig = {
101
+ /** Default true when the object is given. */
102
+ enabled?: boolean;
103
+ /** Share of RECORDED sessions that also record frustration, 0..1. Default 1. Decided once per session. */
104
+ sampleRate?: number;
105
+ /** The most frustration events one page view sends. Default 20. */
106
+ maxPerPage?: number;
107
+ };
108
+
109
+ declare const DEFAULT_ENDPOINT = "https://dashboard.bugstack.ai/api/v1/sessions/ingest";
110
+
111
+ /**
112
+ * Start recording this browser session. Call once, as early as you can. A
113
+ * second call is ignored; close() first to start over.
114
+ */
115
+ declare function init(config: BrowserConfig): void;
116
+ /**
117
+ * Who this session belongs to. bugstack stores only a salted hash of it, which
118
+ * is how a support ticket from the same person finds what they saw. Pass null
119
+ * on sign-out.
120
+ */
121
+ declare function setUser(user: SessionUser | null): void;
122
+ /** Report an error you caught yourself. */
123
+ declare function captureError(err: unknown): void;
124
+ /** Send what is queued now. Resolves when the send settles; never rejects. */
125
+ declare function flush(): Promise<void>;
126
+ /** Stop recording: send what is queued, remove every listener and wrapper. */
127
+ declare function close(): void;
128
+ /** The current session id, or null when not recording. */
129
+ declare function getSessionId(): string | null;
130
+
131
+ export { type BrowserConfig, DEFAULT_ENDPOINT, type ElementRef, type FrustrationConfig, type SessionBatch, type SessionEvent, type SessionUser, captureError, close, flush, getSessionId, init, setUser };