catchfn 0.0.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 ADDED
@@ -0,0 +1,280 @@
1
+ # CatchFn
2
+
3
+ > Self-hosted bug reporting and context collection for developers
4
+
5
+ CatchFn is a lightweight SDK for capturing bug reports with rich context including breadcrumbs, console logs, network activity, and device information. It's designed to integrate seamlessly with your development workflow and the superfunctions ecosystem.
6
+
7
+ ## Features
8
+
9
+ - 🍞 **Breadcrumb Tracking** - Automatic navigation, console, and network breadcrumbs
10
+ - 📝 **Console Capture** - Optional console log buffering
11
+ - 🌐 **Network Monitoring** - Track HTTP requests with automatic header redaction
12
+ - 🔒 **Data Redaction** - Built-in sensitive data protection
13
+ - 🎣 **Hooks System** - `beforeSend` hooks for custom processing
14
+ - 🚫 **Ignore Patterns** - Filter unwanted reports
15
+ - 📦 **Size Limiting** - Automatic payload size optimization
16
+ - 🔧 **TypeScript-First** - Full type safety and inference
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install catchfn
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ```typescript
27
+ import { catchFn } from "catchfn";
28
+
29
+ // Initialize CatchFn
30
+ const catcher = catchFn({
31
+ name: "my-app",
32
+ environment: "production",
33
+ enableBreadcrumbs: true,
34
+ enableConsoleCapture: true,
35
+ enableNetworkCapture: false,
36
+ });
37
+
38
+ // Add breadcrumbs manually
39
+ catcher.addBreadcrumb({
40
+ type: "navigation",
41
+ message: "User navigated to dashboard",
42
+ data: { from: "/home", to: "/dashboard" },
43
+ });
44
+
45
+ // Capture a bug report
46
+ const report = await catcher.captureBug({
47
+ title: "Payment failed",
48
+ description: "User encountered error during checkout",
49
+ severity: "high",
50
+ tags: ["payment", "checkout"],
51
+ user: {
52
+ id: "user-123",
53
+ email: "user@example.com",
54
+ },
55
+ });
56
+
57
+ console.log("Bug report ID:", report.id);
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ ```typescript
63
+ interface CatchFnConfig {
64
+ // Required
65
+ name: string;
66
+
67
+ // Breadcrumbs
68
+ enableBreadcrumbs?: boolean; // default: true
69
+ maxBreadcrumbs?: number; // default: 50
70
+
71
+ // Console capture
72
+ enableConsoleCapture?: boolean; // default: false
73
+ maxConsoleLogs?: number; // default: 100
74
+
75
+ // Network capture
76
+ enableNetworkCapture?: boolean; // default: false
77
+ maxNetworkRequests?: number; // default: 20
78
+
79
+ // Bug settings
80
+ defaultSeverity?: "low" | "medium" | "high" | "critical"; // default: "medium"
81
+ environment?: string;
82
+ release?: string;
83
+ user?: { id?: string; email?: string; [key: string]: any };
84
+
85
+ // Hooks and filters
86
+ beforeSend?: (event: BugReportEvent) => BugReportEvent | null;
87
+ ignorePatterns?: (string | RegExp)[];
88
+
89
+ // Size limits
90
+ maxPayloadSize?: number; // default: 262144 (256KB)
91
+ sensitiveFields?: string[]; // Additional fields to redact
92
+ }
93
+ ```
94
+
95
+ ## Usage Examples
96
+
97
+ ### Basic Bug Capture
98
+
99
+ ```typescript
100
+ await catcher.captureBug({
101
+ title: "API request failed",
102
+ description: "Failed to fetch user data",
103
+ severity: "medium",
104
+ tags: ["api", "network"],
105
+ });
106
+ ```
107
+
108
+ ### With User Context
109
+
110
+ ```typescript
111
+ await catcher.captureBug({
112
+ title: "Feature access denied",
113
+ description: "User tried to access premium feature",
114
+ severity: "low",
115
+ user: {
116
+ id: "user-123",
117
+ email: "user@example.com",
118
+ plan: "free",
119
+ },
120
+ metadata: {
121
+ feature: "analytics-dashboard",
122
+ requestedAt: new Date().toISOString(),
123
+ },
124
+ });
125
+ ```
126
+
127
+ ### Using beforeSend Hook
128
+
129
+ ```typescript
130
+ const catcher = catchFn({
131
+ name: "my-app",
132
+ beforeSend: (event) => {
133
+ // Add custom data
134
+ event.metadata = {
135
+ ...event.metadata,
136
+ buildNumber: "1.2.3",
137
+ };
138
+
139
+ // Filter internal users
140
+ if (event.user?.email?.endsWith("@company.com")) {
141
+ return null; // Drop the event
142
+ }
143
+
144
+ return event;
145
+ },
146
+ });
147
+ ```
148
+
149
+ ### Ignore Patterns
150
+
151
+ ```typescript
152
+ const catcher = catchFn({
153
+ name: "my-app",
154
+ ignorePatterns: ["ResizeObserver loop", /network.*timeout/i],
155
+ });
156
+
157
+ // This will be ignored
158
+ await catcher.captureBug({
159
+ title: "ResizeObserver loop limit exceeded",
160
+ description: "Browser warning",
161
+ });
162
+ ```
163
+
164
+ ### Manual Breadcrumbs
165
+
166
+ ```typescript
167
+ // Navigation
168
+ catcher.addBreadcrumb({
169
+ type: "navigation",
170
+ message: "User navigated to settings",
171
+ data: { from: "/dashboard", to: "/settings" },
172
+ });
173
+
174
+ // User interaction
175
+ catcher.addBreadcrumb({
176
+ type: "user",
177
+ message: "Button clicked",
178
+ data: { button: "submit-form" },
179
+ });
180
+
181
+ // Custom
182
+ catcher.addBreadcrumb({
183
+ type: "custom",
184
+ message: "Payment processed",
185
+ data: { amount: 99.99, currency: "USD" },
186
+ level: "info",
187
+ });
188
+ ```
189
+
190
+ ## API Reference
191
+
192
+ ### `catchFn(config: CatchFnConfig)`
193
+
194
+ Factory function to create a new CatchFn instance.
195
+
196
+ ### `CatchFn.captureBug(options: CaptureBugOptions)`
197
+
198
+ Capture a bug report with context.
199
+
200
+ **Returns:** `Promise<BugReportEvent>`
201
+
202
+ ### `CatchFn.addBreadcrumb(breadcrumb: Breadcrumb)`
203
+
204
+ Manually add a breadcrumb.
205
+
206
+ ### `CatchFn.beforeSend(hook: BeforeSendHook)`
207
+
208
+ Register a beforeSend hook.
209
+
210
+ ### `CatchFn.addIgnorePattern(pattern: IgnorePattern)`
211
+
212
+ Add a pattern to ignore.
213
+
214
+ ### `CatchFn.clear()`
215
+
216
+ Clear all collected context (breadcrumbs, logs, network requests).
217
+
218
+ ### `CatchFn.stop()`
219
+
220
+ Stop all collectors (console, network interceptors).
221
+
222
+ ### `CatchFn.getConfig()`
223
+
224
+ Get the current configuration.
225
+
226
+ ## Advanced Usage
227
+
228
+ ### Using Collectors Directly
229
+
230
+ ```typescript
231
+ import { BreadcrumbCollector } from "catchfn";
232
+
233
+ const breadcrumbs = new BreadcrumbCollector(100);
234
+
235
+ breadcrumbs.addNavigation("/home", "/profile");
236
+ breadcrumbs.addUser("click", "edit-button");
237
+
238
+ const collected = breadcrumbs.collect();
239
+ console.log(collected);
240
+ ```
241
+
242
+ ### Data Redaction
243
+
244
+ ```typescript
245
+ import { redactObject, redactUrl } from "catchfn";
246
+
247
+ const data = {
248
+ username: "john",
249
+ password: "secret123", // Will be redacted
250
+ apiKey: "abc123", // Will be redacted
251
+ };
252
+
253
+ const redacted = redactObject(data);
254
+ // { username: "john", password: "[REDACTED]", apiKey: "[REDACTED]" }
255
+
256
+ const url = redactUrl("https://api.example.com?token=secret&id=123");
257
+ // "https://api.example.com?token=[REDACTED]&id=123"
258
+ ```
259
+
260
+ ## Integration with WatchFn
261
+
262
+ CatchFn is designed to integrate with [WatchFn](../watchfn) for centralized bug tracking and analysis.
263
+
264
+ ```typescript
265
+ import { catchFn } from "catchfn";
266
+ // import { watchFn } from "watchfn"; // Future integration
267
+
268
+ const catcher = catchFn({
269
+ name: "my-app",
270
+ // watchfnClient: watch, // Future: send events to watchfn
271
+ });
272
+ ```
273
+
274
+ ## License
275
+
276
+ MIT © 21n
277
+
278
+ ## Contributing
279
+
280
+ See the main [superfunctions repository](https://github.com/21nCo/super-functions) for contribution guidelines.