bugstash 0.1.0 → 0.1.2

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,324 @@
1
+ # BugStash
2
+
3
+ **Pre-production bug reporting SDK for React apps.** Drop a floating debug panel into your dev/staging environment. Capture bugs with screenshots, console logs, network requests, and full browser context — then manage everything from the [BugStash Dashboard](https://bugstash.vercel.app).
4
+
5
+ [![npm version](https://img.shields.io/npm/v/bugstash.svg)](https://www.npmjs.com/package/bugstash)
6
+ [![license](https://img.shields.io/npm/l/bugstash.svg)](https://www.npmjs.com/package/bugstash)
7
+
8
+ ---
9
+
10
+ ## Why BugStash?
11
+
12
+ - **No more "it works on my machine"** — Every bug report includes console logs, network requests, browser info, and an optional screenshot
13
+ - **Zero config** — One line to initialize, automatically disabled in production
14
+ - **Live Pins** — Click anywhere on your page to leave contextual feedback pinned to specific elements
15
+ - **Built for teams** — Multi-tenant dashboard with roles, projects, and real-time updates
16
+ - **Privacy first** — Built-in PII redaction for sensitive data
17
+
18
+ ---
19
+
20
+ ## Quick Start
21
+
22
+ ### 1. Install
23
+
24
+ ```bash
25
+ npm install bugstash
26
+ ```
27
+
28
+ ### 2. Get your Project ID
29
+
30
+ Sign up at [bugstash.vercel.app](https://bugstash.vercel.app), create an organization and project, then copy your **Project ID** from the settings page.
31
+
32
+ ### 3. Initialize
33
+
34
+ ```tsx
35
+ // app/layout.tsx or _app.tsx
36
+ import BugStash from 'bugstash';
37
+
38
+ BugStash.init({
39
+ projectId: 'your-project-id',
40
+ endpoint: 'https://bugstash-backend.azurewebsites.net',
41
+ environment: 'development', // auto-disabled in 'production'
42
+ });
43
+ ```
44
+
45
+ That's it. A floating bug button appears in the corner of your app.
46
+
47
+ ---
48
+
49
+ ## Configuration
50
+
51
+ ```tsx
52
+ BugStash.init({
53
+ // Required
54
+ projectId: 'your-project-id',
55
+
56
+ // Optional
57
+ endpoint: 'https://bugstash-backend.azurewebsites.net',
58
+ environment: 'development', // 'development' | 'staging' | 'production'
59
+ panelPosition: 'bottom-right', // 'bottom-right' | 'bottom-left'
60
+
61
+ // Features
62
+ enableScreenshot: true, // Screenshot capture (default: true)
63
+ enableAnnotation: true, // Annotate screenshots (default: true)
64
+ enablePerformance: true, // Collect Web Vitals (default: true)
65
+ enableLivePins: true, // Pin comments on page elements (default: true)
66
+
67
+ // Limits
68
+ maxLogs: 100, // Console log buffer size
69
+ maxNetworkCaptures: 50, // Network request buffer size
70
+ maxBreadcrumbs: 50, // User action breadcrumbs
71
+
72
+ // User context (optional)
73
+ user: {
74
+ id: 'user-123',
75
+ email: 'dev@example.com',
76
+ name: 'Jane Developer',
77
+ },
78
+
79
+ // Git commit hash (optional, shown in reports)
80
+ commitHash: process.env.NEXT_PUBLIC_COMMIT_SHA,
81
+ });
82
+ ```
83
+
84
+ ---
85
+
86
+ ## What Gets Captured
87
+
88
+ Every bug report automatically includes:
89
+
90
+ | Category | Details |
91
+ |----------|---------|
92
+ | **Console Logs** | `log`, `warn`, `error`, `info`, `debug` with timestamps |
93
+ | **Network Requests** | URL, method, status, duration, request/response size |
94
+ | **Errors** | Uncaught exceptions and unhandled promise rejections with stack traces |
95
+ | **Breadcrumbs** | Clicks, navigation, form submissions, custom events |
96
+ | **Performance** | FCP, LCP, CLS, TTFB, FID (Web Vitals) |
97
+ | **Browser Context** | User agent, viewport, URL, timestamp, OS, device |
98
+ | **Screenshot** | Full-page capture with optional annotations |
99
+
100
+ ---
101
+
102
+ ## Features
103
+
104
+ ### Bug Report Panel
105
+
106
+ Click the floating bug button to open the report panel. Write a description, set priority/category, attach a screenshot, and submit. All captured context is bundled automatically.
107
+
108
+ ### Live Pins
109
+
110
+ Pin comments directly on UI elements. Team members see pins in real-time. Great for design reviews and QA feedback.
111
+
112
+ ```tsx
113
+ // Toggle pin mode programmatically
114
+ BugStash.togglePinMode();
115
+ BugStash.isPinModeActive(); // boolean
116
+ ```
117
+
118
+ ### Themes
119
+
120
+ Choose from built-in themes or match your app's aesthetic:
121
+
122
+ ```tsx
123
+ BugStash.getThemes(); // List all available themes
124
+ BugStash.setTheme('midnight'); // Switch theme
125
+ BugStash.getCurrentThemeId(); // Get current theme
126
+ ```
127
+
128
+ ### Layouts
129
+
130
+ Switch between different panel layouts:
131
+
132
+ ```tsx
133
+ BugStash.getLayouts(); // List available layouts
134
+ BugStash.setLayout('minimal'); // Switch layout
135
+ ```
136
+
137
+ ### PII Redaction
138
+
139
+ Automatically redact sensitive data before it leaves the browser:
140
+
141
+ ```tsx
142
+ BugStash.redactString('my email is test@email.com');
143
+ // → "my email is [EMAIL REDACTED]"
144
+
145
+ BugStash.redactObject({ password: 'secret', name: 'John' });
146
+ // → { password: '[REDACTED]', name: 'John' }
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Programmatic API
152
+
153
+ Access captured data directly:
154
+
155
+ ```tsx
156
+ // Console logs
157
+ BugStash.getLogs();
158
+ BugStash.clearLogs();
159
+
160
+ // Network requests
161
+ BugStash.getNetworkCaptures();
162
+ BugStash.getFailedNetworkCaptures();
163
+ BugStash.clearNetworkCaptures();
164
+
165
+ // Errors
166
+ BugStash.getErrors();
167
+ BugStash.clearErrors();
168
+
169
+ // Breadcrumbs
170
+ BugStash.getBreadcrumbs();
171
+ BugStash.addBreadcrumb({ type: 'custom', message: 'User completed onboarding' });
172
+ BugStash.clearBreadcrumbs();
173
+
174
+ // Performance metrics
175
+ BugStash.getPerformanceMetrics();
176
+
177
+ // Cleanup
178
+ BugStash.destroy();
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Framework Examples
184
+
185
+ ### Next.js (App Router)
186
+
187
+ ```tsx
188
+ // app/providers.tsx
189
+ 'use client';
190
+
191
+ import { useEffect } from 'react';
192
+ import BugStash from 'bugstash';
193
+
194
+ export function BugStashProvider({ children }: { children: React.ReactNode }) {
195
+ useEffect(() => {
196
+ BugStash.init({
197
+ projectId: process.env.NEXT_PUBLIC_BUGSTASH_PROJECT_ID!,
198
+ endpoint: 'https://bugstash-backend.azurewebsites.net',
199
+ environment: process.env.NODE_ENV as any,
200
+ });
201
+ return () => BugStash.destroy();
202
+ }, []);
203
+
204
+ return <>{children}</>;
205
+ }
206
+ ```
207
+
208
+ ```tsx
209
+ // app/layout.tsx
210
+ import { BugStashProvider } from './providers';
211
+
212
+ export default function RootLayout({ children }) {
213
+ return (
214
+ <html>
215
+ <body>
216
+ <BugStashProvider>{children}</BugStashProvider>
217
+ </body>
218
+ </html>
219
+ );
220
+ }
221
+ ```
222
+
223
+ ### Vite + React
224
+
225
+ ```tsx
226
+ // main.tsx
227
+ import BugStash from 'bugstash';
228
+
229
+ BugStash.init({
230
+ projectId: import.meta.env.VITE_BUGSTASH_PROJECT_ID,
231
+ endpoint: 'https://bugstash-backend.azurewebsites.net',
232
+ environment: import.meta.env.MODE,
233
+ });
234
+ ```
235
+
236
+ ### Create React App
237
+
238
+ ```tsx
239
+ // src/index.tsx
240
+ import BugStash from 'bugstash';
241
+
242
+ BugStash.init({
243
+ projectId: process.env.REACT_APP_BUGSTASH_PROJECT_ID!,
244
+ endpoint: 'https://bugstash-backend.azurewebsites.net',
245
+ environment: process.env.NODE_ENV,
246
+ });
247
+ ```
248
+
249
+ ---
250
+
251
+ ## Dashboard
252
+
253
+ Manage all reports from the [BugStash Dashboard](https://bugstash.vercel.app):
254
+
255
+ - **View & filter** bug reports by status, priority, category, and assignee
256
+ - **Assign** reports to team members
257
+ - **Track** resolution status
258
+ - **Inspect** full context: logs, network, errors, screenshots
259
+ - **Live Pins** — see pinned comments in real-time
260
+ - **Multi-tenant** — multiple organizations and projects
261
+ - **Team roles** — owner, admin, member permissions
262
+
263
+ Sign up free at **[bugstash.vercel.app](https://bugstash.vercel.app)**
264
+
265
+ ---
266
+
267
+ ## How It Works
268
+
269
+ ```
270
+ Your App (dev/staging) BugStash Cloud
271
+ ┌─────────────────────┐ ┌──────────────────┐
272
+ │ │ │ │
273
+ │ bugstash SDK │───────>│ Backend API │
274
+ │ - captures logs │ HTTPS │ - stores reports│
275
+ │ - records network │ │ - manages pins │
276
+ │ - takes screenshots│ │ - real-time WS │
277
+ │ - tracks errors │ │ │
278
+ │ │ └────────┬─────────┘
279
+ └─────────────────────┘ │
280
+ v
281
+ ┌──────────────────┐
282
+ │ │
283
+ │ Dashboard │
284
+ │ - view reports │
285
+ │ - assign bugs │
286
+ │ - team collab │
287
+ │ │
288
+ └──────────────────┘
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Production Safety
294
+
295
+ BugStash automatically disables itself when `environment` is set to `'production'`. No data is captured, no UI is rendered, and no network requests are made. Zero overhead in production.
296
+
297
+ ```tsx
298
+ BugStash.init({
299
+ projectId: 'your-project-id',
300
+ environment: process.env.NODE_ENV, // 'production' = fully disabled
301
+ });
302
+ ```
303
+
304
+ ---
305
+
306
+ ## Requirements
307
+
308
+ - React >= 17.0.0
309
+ - Modern browser (Chrome, Firefox, Safari, Edge)
310
+ - Optional: `html2canvas` for screenshot capture (`npm install html2canvas`)
311
+
312
+ ---
313
+
314
+ ## Links
315
+
316
+ - [Dashboard & Sign Up](https://bugstash.vercel.app)
317
+ - [Documentation](https://bugstash.vercel.app/docs)
318
+ - [GitHub](https://github.com/anastanvir/bugstash)
319
+
320
+ ---
321
+
322
+ ## License
323
+
324
+ MIT
package/dist/index.cjs CHANGED
@@ -5077,11 +5077,24 @@ function cleanup() {
5077
5077
 
5078
5078
  // src/index.ts
5079
5079
  var initialized = false;
5080
+ function detectEnvironment() {
5081
+ if (typeof window === "undefined") return "production";
5082
+ const host = window.location.hostname;
5083
+ if (host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0" || host.endsWith(".local") || /^192\.168\./.test(host) || /^10\./.test(host) || /^172\.(1[6-9]|2\d|3[01])\./.test(host)) return "development";
5084
+ if (host.includes("staging") || host.includes("stage") || host.includes("preview") || host.includes("preprod") || host.includes("pre-prod") || host.includes("qa.") || host.includes(".qa") || host.includes("test.") || host.includes(".dev.") || host.includes("vercel.app") || // Vercel preview deployments
5085
+ host.includes("netlify.app") || // Netlify preview deployments
5086
+ host.includes("pages.dev") || // Cloudflare Pages previews
5087
+ host.includes("ngrok.io") || // ngrok tunnels
5088
+ host.includes("ngrok-free.app") || // ngrok free tier
5089
+ host.includes("localhost.run") || // localhost.run tunnels
5090
+ host.includes("loca.lt")) return "staging";
5091
+ return "production";
5092
+ }
5080
5093
  var BugStash = {
5081
5094
  init(options) {
5082
5095
  if (initialized) return;
5083
5096
  if (typeof window === "undefined") return;
5084
- const env = options.environment ?? "development";
5097
+ const env = options.environment ?? detectEnvironment();
5085
5098
  if (env === "production") return;
5086
5099
  initialized = true;
5087
5100
  if (options.endpoint) setEndpoint(options.endpoint);