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 +280 -0
- package/dist/index.cjs +815 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +462 -0
- package/dist/index.d.ts +462 -0
- package/dist/index.js +773 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types and interfaces for CatchFn
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Bug severity levels
|
|
6
|
+
*/
|
|
7
|
+
type BugSeverity = "low" | "medium" | "high" | "critical";
|
|
8
|
+
/**
|
|
9
|
+
* Breadcrumb types
|
|
10
|
+
*/
|
|
11
|
+
type BreadcrumbType = "navigation" | "console" | "network" | "user" | "custom";
|
|
12
|
+
/**
|
|
13
|
+
* Breadcrumb entry
|
|
14
|
+
*/
|
|
15
|
+
interface Breadcrumb {
|
|
16
|
+
type: BreadcrumbType;
|
|
17
|
+
timestamp: number;
|
|
18
|
+
message?: string;
|
|
19
|
+
data?: Record<string, any>;
|
|
20
|
+
category?: string;
|
|
21
|
+
level?: "debug" | "info" | "warning" | "error";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Console log entry
|
|
25
|
+
*/
|
|
26
|
+
interface ConsoleLogEntry {
|
|
27
|
+
level: "log" | "info" | "warn" | "error" | "debug";
|
|
28
|
+
args: any[];
|
|
29
|
+
timestamp: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Network request summary
|
|
33
|
+
*/
|
|
34
|
+
interface NetworkRequest {
|
|
35
|
+
url: string;
|
|
36
|
+
method: string;
|
|
37
|
+
status?: number;
|
|
38
|
+
statusText?: string;
|
|
39
|
+
duration?: number;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
requestHeaders?: Record<string, string>;
|
|
42
|
+
responseHeaders?: Record<string, string>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Device and environment information
|
|
46
|
+
*/
|
|
47
|
+
interface DeviceInfo {
|
|
48
|
+
userAgent?: string;
|
|
49
|
+
platform?: string;
|
|
50
|
+
language?: string;
|
|
51
|
+
screenResolution?: string;
|
|
52
|
+
viewportSize?: string;
|
|
53
|
+
timezone?: string;
|
|
54
|
+
nodeVersion?: string;
|
|
55
|
+
memoryUsage?: {
|
|
56
|
+
rss: number;
|
|
57
|
+
heapTotal: number;
|
|
58
|
+
heapUsed: number;
|
|
59
|
+
external: number;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Attachment reference
|
|
64
|
+
*/
|
|
65
|
+
interface AttachmentReference {
|
|
66
|
+
id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
type: string;
|
|
69
|
+
size: number;
|
|
70
|
+
url?: string;
|
|
71
|
+
dataUrl?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Bug report event - the main event sent to watchfn
|
|
75
|
+
*/
|
|
76
|
+
interface BugReportEvent {
|
|
77
|
+
id: string;
|
|
78
|
+
timestamp: number;
|
|
79
|
+
title: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
severity: BugSeverity;
|
|
82
|
+
tags?: string[];
|
|
83
|
+
breadcrumbs?: Breadcrumb[];
|
|
84
|
+
consoleLogs?: ConsoleLogEntry[];
|
|
85
|
+
networkRequests?: NetworkRequest[];
|
|
86
|
+
deviceInfo?: DeviceInfo;
|
|
87
|
+
user?: {
|
|
88
|
+
id?: string;
|
|
89
|
+
email?: string;
|
|
90
|
+
username?: string;
|
|
91
|
+
[key: string]: any;
|
|
92
|
+
};
|
|
93
|
+
environment?: string;
|
|
94
|
+
release?: string;
|
|
95
|
+
attachments?: AttachmentReference[];
|
|
96
|
+
integration?: {
|
|
97
|
+
issueId?: string;
|
|
98
|
+
issueUrl?: string;
|
|
99
|
+
};
|
|
100
|
+
metadata?: Record<string, any>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Options for capturing a bug
|
|
104
|
+
*/
|
|
105
|
+
interface CaptureBugOptions {
|
|
106
|
+
title: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
severity?: BugSeverity;
|
|
109
|
+
tags?: string[];
|
|
110
|
+
user?: BugReportEvent["user"];
|
|
111
|
+
environment?: string;
|
|
112
|
+
release?: string;
|
|
113
|
+
metadata?: Record<string, any>;
|
|
114
|
+
attachments?: AttachmentReference[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* BeforeSend hook function
|
|
118
|
+
* Return null to drop the event
|
|
119
|
+
*/
|
|
120
|
+
type BeforeSendHook = (event: BugReportEvent) => BugReportEvent | null | Promise<BugReportEvent | null>;
|
|
121
|
+
/**
|
|
122
|
+
* Ignore pattern - string or regex
|
|
123
|
+
*/
|
|
124
|
+
type IgnorePattern = string | RegExp;
|
|
125
|
+
/**
|
|
126
|
+
* CatchFn configuration
|
|
127
|
+
*/
|
|
128
|
+
interface CatchFnConfig {
|
|
129
|
+
/**
|
|
130
|
+
* Application name
|
|
131
|
+
*/
|
|
132
|
+
name: string;
|
|
133
|
+
/**
|
|
134
|
+
* Enable breadcrumb collection
|
|
135
|
+
* @default true
|
|
136
|
+
*/
|
|
137
|
+
enableBreadcrumbs?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Maximum number of breadcrumbs to keep
|
|
140
|
+
* @default 50
|
|
141
|
+
*/
|
|
142
|
+
maxBreadcrumbs?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Enable console log capture
|
|
145
|
+
* @default false
|
|
146
|
+
*/
|
|
147
|
+
enableConsoleCapture?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Maximum number of console logs to keep
|
|
150
|
+
* @default 100
|
|
151
|
+
*/
|
|
152
|
+
maxConsoleLogs?: number;
|
|
153
|
+
/**
|
|
154
|
+
* Enable network request tracking
|
|
155
|
+
* @default false
|
|
156
|
+
*/
|
|
157
|
+
enableNetworkCapture?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Maximum number of network requests to keep
|
|
160
|
+
* @default 20
|
|
161
|
+
*/
|
|
162
|
+
maxNetworkRequests?: number;
|
|
163
|
+
/**
|
|
164
|
+
* Default severity for bug reports
|
|
165
|
+
* @default "medium"
|
|
166
|
+
*/
|
|
167
|
+
defaultSeverity?: BugSeverity;
|
|
168
|
+
/**
|
|
169
|
+
* Default environment
|
|
170
|
+
*/
|
|
171
|
+
environment?: string;
|
|
172
|
+
/**
|
|
173
|
+
* Release version
|
|
174
|
+
*/
|
|
175
|
+
release?: string;
|
|
176
|
+
/**
|
|
177
|
+
* Default user context
|
|
178
|
+
*/
|
|
179
|
+
user?: BugReportEvent["user"];
|
|
180
|
+
/**
|
|
181
|
+
* BeforeSend hook
|
|
182
|
+
*/
|
|
183
|
+
beforeSend?: BeforeSendHook;
|
|
184
|
+
/**
|
|
185
|
+
* Patterns to ignore
|
|
186
|
+
*/
|
|
187
|
+
ignorePatterns?: IgnorePattern[];
|
|
188
|
+
/**
|
|
189
|
+
* Maximum payload size in bytes
|
|
190
|
+
* @default 262144 (256KB)
|
|
191
|
+
*/
|
|
192
|
+
maxPayloadSize?: number;
|
|
193
|
+
/**
|
|
194
|
+
* Sensitive fields to redact
|
|
195
|
+
*/
|
|
196
|
+
sensitiveFields?: string[];
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Context collector interface
|
|
200
|
+
*/
|
|
201
|
+
interface ContextCollector<T = any> {
|
|
202
|
+
collect(): T;
|
|
203
|
+
clear(): void;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Main CatchFn SDK class
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
declare class CatchFn {
|
|
211
|
+
private config;
|
|
212
|
+
private breadcrumbCollector;
|
|
213
|
+
private consoleCollector?;
|
|
214
|
+
private networkCollector?;
|
|
215
|
+
private beforeSendHooks;
|
|
216
|
+
private ignorePatterns;
|
|
217
|
+
constructor(config: CatchFnConfig);
|
|
218
|
+
/**
|
|
219
|
+
* Add a breadcrumb
|
|
220
|
+
*/
|
|
221
|
+
addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
|
|
222
|
+
/**
|
|
223
|
+
* Register a beforeSend hook
|
|
224
|
+
*/
|
|
225
|
+
beforeSend(hook: BeforeSendHook): void;
|
|
226
|
+
/**
|
|
227
|
+
* Add an ignore pattern
|
|
228
|
+
*/
|
|
229
|
+
addIgnorePattern(pattern: IgnorePattern): void;
|
|
230
|
+
/**
|
|
231
|
+
* Check if an event should be ignored
|
|
232
|
+
*/
|
|
233
|
+
private shouldIgnore;
|
|
234
|
+
/**
|
|
235
|
+
* Apply beforeSend hooks
|
|
236
|
+
*/
|
|
237
|
+
private applyHooks;
|
|
238
|
+
/**
|
|
239
|
+
* Capture a bug report
|
|
240
|
+
*/
|
|
241
|
+
captureBug(options: CaptureBugOptions): Promise<BugReportEvent>;
|
|
242
|
+
/**
|
|
243
|
+
* Clear all collected context
|
|
244
|
+
*/
|
|
245
|
+
clear(): void;
|
|
246
|
+
/**
|
|
247
|
+
* Stop all collectors
|
|
248
|
+
*/
|
|
249
|
+
stop(): void;
|
|
250
|
+
/**
|
|
251
|
+
* Get current configuration
|
|
252
|
+
*/
|
|
253
|
+
getConfig(): Readonly<typeof this.config>;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Breadcrumb collector - circular buffer for tracking user actions
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
declare class BreadcrumbCollector implements ContextCollector<Breadcrumb[]> {
|
|
261
|
+
private breadcrumbs;
|
|
262
|
+
private maxSize;
|
|
263
|
+
constructor(maxSize?: number);
|
|
264
|
+
/**
|
|
265
|
+
* Add a breadcrumb
|
|
266
|
+
*/
|
|
267
|
+
add(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
|
|
268
|
+
/**
|
|
269
|
+
* Add a navigation breadcrumb
|
|
270
|
+
*/
|
|
271
|
+
addNavigation(from: string, to: string): void;
|
|
272
|
+
/**
|
|
273
|
+
* Add a console breadcrumb
|
|
274
|
+
*/
|
|
275
|
+
addConsole(level: Breadcrumb["level"], message: string): void;
|
|
276
|
+
/**
|
|
277
|
+
* Add a network breadcrumb
|
|
278
|
+
*/
|
|
279
|
+
addNetwork(method: string, url: string, status?: number): void;
|
|
280
|
+
/**
|
|
281
|
+
* Add a user interaction breadcrumb
|
|
282
|
+
*/
|
|
283
|
+
addUser(action: string, target: string, data?: Record<string, any>): void;
|
|
284
|
+
/**
|
|
285
|
+
* Collect all breadcrumbs
|
|
286
|
+
*/
|
|
287
|
+
collect(): Breadcrumb[];
|
|
288
|
+
/**
|
|
289
|
+
* Clear all breadcrumbs
|
|
290
|
+
*/
|
|
291
|
+
clear(): void;
|
|
292
|
+
/**
|
|
293
|
+
* Get the current number of breadcrumbs
|
|
294
|
+
*/
|
|
295
|
+
size(): number;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Console log collector - captures console output
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
declare class ConsoleCollector implements ContextCollector<ConsoleLogEntry[]> {
|
|
303
|
+
private logs;
|
|
304
|
+
private maxSize;
|
|
305
|
+
private originalMethods;
|
|
306
|
+
private isActive;
|
|
307
|
+
constructor(maxSize?: number);
|
|
308
|
+
/**
|
|
309
|
+
* Start intercepting console methods
|
|
310
|
+
*/
|
|
311
|
+
start(): void;
|
|
312
|
+
/**
|
|
313
|
+
* Stop intercepting console methods
|
|
314
|
+
*/
|
|
315
|
+
stop(): void;
|
|
316
|
+
/**
|
|
317
|
+
* Capture a console log entry
|
|
318
|
+
*/
|
|
319
|
+
private capture;
|
|
320
|
+
/**
|
|
321
|
+
* Serialize console arguments
|
|
322
|
+
*/
|
|
323
|
+
private serializeArgs;
|
|
324
|
+
/**
|
|
325
|
+
* Collect all console logs
|
|
326
|
+
*/
|
|
327
|
+
collect(): ConsoleLogEntry[];
|
|
328
|
+
/**
|
|
329
|
+
* Clear all console logs
|
|
330
|
+
*/
|
|
331
|
+
clear(): void;
|
|
332
|
+
/**
|
|
333
|
+
* Get the current number of logs
|
|
334
|
+
*/
|
|
335
|
+
size(): number;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Network activity collector - tracks HTTP requests
|
|
340
|
+
*/
|
|
341
|
+
|
|
342
|
+
declare class NetworkCollector implements ContextCollector<NetworkRequest[]> {
|
|
343
|
+
private requests;
|
|
344
|
+
private maxSize;
|
|
345
|
+
private originalFetch?;
|
|
346
|
+
private originalXHROpen?;
|
|
347
|
+
private originalXHRSend?;
|
|
348
|
+
private isActive;
|
|
349
|
+
private sensitiveHeaders;
|
|
350
|
+
constructor(maxSize?: number);
|
|
351
|
+
/**
|
|
352
|
+
* Start intercepting network requests
|
|
353
|
+
*/
|
|
354
|
+
start(): void;
|
|
355
|
+
/**
|
|
356
|
+
* Stop intercepting network requests
|
|
357
|
+
*/
|
|
358
|
+
stop(): void;
|
|
359
|
+
/**
|
|
360
|
+
* Intercept fetch API
|
|
361
|
+
*/
|
|
362
|
+
private interceptFetch;
|
|
363
|
+
/**
|
|
364
|
+
* Intercept XMLHttpRequest
|
|
365
|
+
*/
|
|
366
|
+
private interceptXHR;
|
|
367
|
+
/**
|
|
368
|
+
* Extract and sanitize headers
|
|
369
|
+
*/
|
|
370
|
+
private extractHeaders;
|
|
371
|
+
/**
|
|
372
|
+
* Add a network request
|
|
373
|
+
*/
|
|
374
|
+
private addRequest;
|
|
375
|
+
/**
|
|
376
|
+
* Collect all network requests
|
|
377
|
+
*/
|
|
378
|
+
collect(): NetworkRequest[];
|
|
379
|
+
/**
|
|
380
|
+
* Clear all network requests
|
|
381
|
+
*/
|
|
382
|
+
clear(): void;
|
|
383
|
+
/**
|
|
384
|
+
* Get the current number of requests
|
|
385
|
+
*/
|
|
386
|
+
size(): number;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Device and environment information collector
|
|
391
|
+
*/
|
|
392
|
+
|
|
393
|
+
declare class DeviceCollector {
|
|
394
|
+
/**
|
|
395
|
+
* Collect device and environment information
|
|
396
|
+
*/
|
|
397
|
+
static collect(): DeviceInfo;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Data redaction utilities
|
|
402
|
+
*/
|
|
403
|
+
/**
|
|
404
|
+
* Redact sensitive values from an object
|
|
405
|
+
*/
|
|
406
|
+
declare function redactObject(obj: any, customPatterns?: RegExp[]): any;
|
|
407
|
+
/**
|
|
408
|
+
* Redact sensitive data from strings
|
|
409
|
+
*/
|
|
410
|
+
declare function redactString(str: string): string;
|
|
411
|
+
/**
|
|
412
|
+
* Redact URL parameters
|
|
413
|
+
*/
|
|
414
|
+
declare function redactUrl(url: string, sensitiveParams?: string[]): string;
|
|
415
|
+
/**
|
|
416
|
+
* Redact headers
|
|
417
|
+
*/
|
|
418
|
+
declare function redactHeaders(headers: Record<string, string>): Record<string, string>;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Error and data serialization utilities
|
|
422
|
+
*/
|
|
423
|
+
/**
|
|
424
|
+
* Serialize an Error object
|
|
425
|
+
*/
|
|
426
|
+
declare function serializeError(error: Error): Record<string, any>;
|
|
427
|
+
/**
|
|
428
|
+
* Safely serialize any value, handling circular references
|
|
429
|
+
*/
|
|
430
|
+
declare function safeSerialize(value: any, maxDepth?: number): any;
|
|
431
|
+
/**
|
|
432
|
+
* Estimate the size of a serialized object in bytes
|
|
433
|
+
*/
|
|
434
|
+
declare function estimateSize(obj: any): number;
|
|
435
|
+
/**
|
|
436
|
+
* Truncate a string to a maximum length
|
|
437
|
+
*/
|
|
438
|
+
declare function truncateString(str: string, maxLength: number): string;
|
|
439
|
+
/**
|
|
440
|
+
* Trim an array to a maximum size
|
|
441
|
+
*/
|
|
442
|
+
declare function trimArray<T>(arr: T[], maxSize: number): T[];
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Size limiting utilities
|
|
446
|
+
*/
|
|
447
|
+
/**
|
|
448
|
+
* Limit the size of a payload
|
|
449
|
+
*/
|
|
450
|
+
declare function limitPayloadSize(payload: any, maxSize: number): any;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* CatchFn - Self-hosted bug reporting and context collection
|
|
454
|
+
* @module catchfn
|
|
455
|
+
*/
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Create a new CatchFn instance
|
|
459
|
+
*/
|
|
460
|
+
declare function catchFn(config: CatchFnConfig): CatchFn;
|
|
461
|
+
|
|
462
|
+
export { type AttachmentReference, type BeforeSendHook, type Breadcrumb, BreadcrumbCollector, type BreadcrumbType, type BugReportEvent, type BugSeverity, type CaptureBugOptions, CatchFn, type CatchFnConfig, ConsoleCollector, type ConsoleLogEntry, type ContextCollector, DeviceCollector, type DeviceInfo, type IgnorePattern, NetworkCollector, type NetworkRequest, catchFn, catchFn as default, estimateSize, limitPayloadSize, redactHeaders, redactObject, redactString, redactUrl, safeSerialize, serializeError, trimArray, truncateString };
|