@bugban/js 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # @bugban/js
2
+
3
+ Error and performance monitoring for JavaScript — the framework-agnostic core of the [Bugban](https://bugban.online) SDK family. Runs in browsers and in Node.js.
4
+
5
+ Captures uncaught errors, `console.error`, failed network calls, Core Web Vitals and a DOM snapshot of the page at the moment it broke — then reports them to your Bugban project, where they are grouped, tracked and analysed by AI.
6
+
7
+ ```bash
8
+ npm install @bugban/js
9
+ ```
10
+
11
+ Using a framework? Install the adapter instead — it wires the framework's own error path, which the global handlers cannot see:
12
+
13
+ | Framework | Package |
14
+ |---|---|
15
+ | React (Vite, CRA, …) | [`@bugban/react`](https://www.npmjs.com/package/@bugban/react) |
16
+ | Vue 3 | [`@bugban/vue`](https://www.npmjs.com/package/@bugban/vue) |
17
+ | Next.js | [`@bugban/next`](https://www.npmjs.com/package/@bugban/next) |
18
+ | Node.js | [`@bugban/node`](https://www.npmjs.com/package/@bugban/node) |
19
+ | Express | [`@bugban/express`](https://www.npmjs.com/package/@bugban/express) |
20
+ | NestJS | [`@bugban/nestjs`](https://www.npmjs.com/package/@bugban/nestjs) |
21
+
22
+ ## Quick start
23
+
24
+ ```js
25
+ import { Bugban } from '@bugban/js';
26
+
27
+ Bugban.init({
28
+ apiKey: 'bb_your_project_key', // Bugban → project → Settings
29
+ host: 'https://bugban.online',
30
+ release: '1.4.2', // your app version
31
+ environment: 'production',
32
+ });
33
+ ```
34
+
35
+ That is the whole setup. From here on, uncaught errors, rejected promises, `console.error` calls and failed HTTP requests are reported automatically.
36
+
37
+ ### Reporting an error yourself
38
+
39
+ Errors inside a `try/catch` never reach a global handler, so report them explicitly:
40
+
41
+ ```js
42
+ import { Bugban } from '@bugban/js';
43
+
44
+ try {
45
+ await saveOrder();
46
+ } catch (err) {
47
+ Bugban.capture(err, { handled: true });
48
+ }
49
+ ```
50
+
51
+ ### Who was affected
52
+
53
+ ```js
54
+ Bugban.setUser({ id: user.id, email: user.email, name: user.name });
55
+ Bugban.setContext('cart', { items: 3, total: 41.5 });
56
+ Bugban.addBreadcrumb({ type: 'manual', message: 'Checkout started' });
57
+ ```
58
+
59
+ ## Install without npm
60
+
61
+ For a page with no bundler, load the standalone build and use the `Bugban` global:
62
+
63
+ ```html
64
+ <script src="https://bugban.online/sdk/bugban.js"></script>
65
+ <script>
66
+ Bugban.init({ apiKey: 'bb_your_project_key', host: 'https://bugban.online' });
67
+ </script>
68
+ ```
69
+
70
+ Pin a version in production: `https://bugban.online/sdk/bugban-1.0.0.js`.
71
+
72
+ > **Do not use the script tag and the npm package in the same app.** Two copies of the SDK install two sets of handlers and report everything twice. Pick one.
73
+
74
+ ## What is collected
75
+
76
+ | | Default | Option |
77
+ |---|---|---|
78
+ | Uncaught errors, rejected promises | on | `globalHandlers` |
79
+ | `console.error` / `console.warn` | on | `console` |
80
+ | Network calls (`fetch`, `XHR`) | on | `network` |
81
+ | Clicks and route changes | on | `domBreadcrumbs` |
82
+ | Core Web Vitals (LCP, FCP, CLS, INP, TTFB) | on | `vitals` |
83
+ | DOM snapshot at error time | on | `snapshot` |
84
+
85
+ ### Privacy
86
+
87
+ Request bodies are never sent. Headers, query parameters and context keys that look like credentials (`password`, `token`, `authorization`, `cookie`, `card`, …) are replaced with `[redacted]` before anything leaves the process.
88
+
89
+ The DOM snapshot is a **serialized copy of the page**, not a pixel screenshot, and **every input value is masked** before it is sent:
90
+
91
+ ```js
92
+ Bugban.init({
93
+ apiKey: '…',
94
+ snapshot: {
95
+ maskInputs: true, // default, keep it on
96
+ maskSelectors: ['.invoice-total'], // mask extra elements by selector
97
+ },
98
+ });
99
+ ```
100
+
101
+ `maskInputs` defaults to `true` and there is no reason to turn it off — with it on, a password field is stored as `••••••••`. To disable snapshots entirely:
102
+
103
+ ```js
104
+ Bugban.init({ apiKey: '…', snapshot: false });
105
+ ```
106
+
107
+ ## Filtering what gets reported
108
+
109
+ ```js
110
+ Bugban.init({
111
+ apiKey: '…',
112
+ sampleRate: 0.25, // report a quarter of errors
113
+ ignoreErrors: ['ResizeObserver loop', /^AbortError/],
114
+ beforeSend(event) {
115
+ if (event.message?.includes('third-party-widget')) return null; // drop it
116
+ return event;
117
+ },
118
+ });
119
+ ```
120
+
121
+ ## Options
122
+
123
+ | Option | Default | Description |
124
+ |---|---|---|
125
+ | `apiKey` | — | Project key. Without it the SDK does nothing at all. |
126
+ | `host` | — | Your Bugban host. |
127
+ | `release` | — | App version. Groups errors by release. |
128
+ | `environment` | — | `production`, `staging`, … |
129
+ | `enabled` | `true` | Set `false` to disable without removing the code. |
130
+ | `debug` | `false` | Log what the SDK is doing to the console. |
131
+ | `sampleRate` | `1` | Fraction of errors sent (`0`–`1`). |
132
+ | `maxBreadcrumbs` | `30` | Size of the breadcrumb ring buffer. |
133
+ | `ignoreErrors` | `[]` | Strings or regexes matched against the message. |
134
+ | `beforeSend` | — | Edit or drop an event. Return `null` to drop. |
135
+ | `beforeBreadcrumb` | — | Edit or drop a breadcrumb. |
136
+ | `redactKeys` | `[]` | Extra key names to redact. |
137
+
138
+ ## API
139
+
140
+ ```js
141
+ Bugban.init(options) // start; returns the client
142
+ Bugban.capture(error, extra) // report an error
143
+ Bugban.captureMessage(msg) // report a message
144
+ Bugban.setUser(user) // attach the signed-in user (null to clear)
145
+ Bugban.setContext(key, value) // attach arbitrary context
146
+ Bugban.addBreadcrumb(crumb) // record a step
147
+ Bugban.flush() // await delivery (before a process exits)
148
+ Bugban.close() // remove every handler
149
+ Bugban.VERSION
150
+ ```
151
+
152
+ ## Compatibility
153
+
154
+ - **Node.js 12 and newer**, ESM and CommonJS. Tested on 12, 14, 16, 18, 20 and 22. On versions without global `fetch` the SDK falls back to the `http`/`https` module automatically.
155
+ - **Browsers**: anything supporting ES2018. The standalone build targets ES2017.
156
+ - **TypeScript**: types are bundled, no `@types` package needed.
157
+
158
+ The SDK never throws. If it cannot report — no key, no network, an unsupported runtime — it goes quiet instead of breaking your app.
159
+
160
+ ## License
161
+
162
+ MIT