@bugwatch/core 0.1.0 → 0.2.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/dist/index.d.mts CHANGED
@@ -131,6 +131,16 @@ interface ErrorEvent {
131
131
  */
132
132
  interface Transport {
133
133
  send(event: ErrorEvent): Promise<void>;
134
+ /**
135
+ * Flush any pending events.
136
+ * Ensures all queued events are sent before the promise resolves.
137
+ */
138
+ flush?(): Promise<void>;
139
+ /**
140
+ * Close the transport and release any resources.
141
+ * After calling this method, the transport should not be used again.
142
+ */
143
+ close?(): Promise<void>;
134
144
  }
135
145
  /**
136
146
  * Integration interface for platform-specific functionality
@@ -150,6 +160,16 @@ interface BugwatchClient {
150
160
  setTag(key: string, value: string): void;
151
161
  setExtra(key: string, value: unknown): void;
152
162
  getOptions(): BugwatchOptions;
163
+ /**
164
+ * Flush any pending events.
165
+ * Call this before process exit to ensure no events are lost.
166
+ */
167
+ flush(): Promise<void>;
168
+ /**
169
+ * Close the client and release any resources.
170
+ * This flushes any pending events and closes the transport.
171
+ */
172
+ close(): Promise<void>;
153
173
  }
154
174
 
155
175
  /**
@@ -218,6 +238,17 @@ declare class Bugwatch implements BugwatchClient {
218
238
  * Detect the current platform
219
239
  */
220
240
  private detectPlatform;
241
+ /**
242
+ * Flush any pending events.
243
+ * Call this before process exit to ensure no events are lost.
244
+ */
245
+ flush(): Promise<void>;
246
+ /**
247
+ * Close the client and release any resources.
248
+ * This flushes any pending events and closes the transport.
249
+ * After calling this method, the client should not be used again.
250
+ */
251
+ close(): Promise<void>;
221
252
  }
222
253
 
223
254
  /**
@@ -263,6 +294,10 @@ declare class BatchTransport implements Transport {
263
294
  flush(): Promise<void>;
264
295
  private startTimer;
265
296
  destroy(): void;
297
+ /**
298
+ * Close the transport, flushing any remaining events and stopping the timer.
299
+ */
300
+ close(): Promise<void>;
266
301
  }
267
302
 
268
303
  /**
@@ -288,36 +323,228 @@ declare function generateFingerprint(errorType: string, message: string, stacktr
288
323
  declare function fingerprintFromException(exception: ExceptionInfo): string;
289
324
 
290
325
  /**
291
- * Initialize the global Bugwatch client
326
+ * Environment variable utilities for Bugwatch SDK.
327
+ *
328
+ * This module provides functions for reading configuration from environment
329
+ * variables and validating API keys.
292
330
  */
293
- declare function init(options: BugwatchOptions): Bugwatch;
331
+
332
+ /**
333
+ * Supported environment variables for Bugwatch configuration.
334
+ */
335
+ declare const ENV_VARS: {
336
+ readonly API_KEY: "BUGWATCH_API_KEY";
337
+ readonly ENVIRONMENT: "BUGWATCH_ENVIRONMENT";
338
+ readonly RELEASE: "BUGWATCH_RELEASE";
339
+ readonly DEBUG: "BUGWATCH_DEBUG";
340
+ readonly ENDPOINT: "BUGWATCH_ENDPOINT";
341
+ };
342
+ /**
343
+ * Read Bugwatch configuration from environment variables.
344
+ *
345
+ * Supported environment variables:
346
+ * - `BUGWATCH_API_KEY` - API key (required unless passed explicitly)
347
+ * - `BUGWATCH_ENVIRONMENT` - Environment tag (e.g., 'production', 'staging')
348
+ * - `BUGWATCH_RELEASE` - Release version
349
+ * - `BUGWATCH_DEBUG` - Enable debug mode ('true' to enable)
350
+ * - `BUGWATCH_ENDPOINT` - Custom API endpoint
351
+ *
352
+ * @returns Partial configuration from environment variables
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * // Set environment variables
357
+ * // BUGWATCH_API_KEY=bw_live_xxxxx
358
+ * // BUGWATCH_ENVIRONMENT=production
359
+ *
360
+ * const envConfig = getEnvConfig();
361
+ * // { apiKey: 'bw_live_xxxxx', environment: 'production' }
362
+ * ```
363
+ */
364
+ declare function getEnvConfig(): Partial<BugwatchOptions>;
365
+ /**
366
+ * Validate an API key and throw a clear error if invalid.
367
+ *
368
+ * @param key - The API key to validate
369
+ * @throws Error if the API key is missing or invalid
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * // Missing API key
374
+ * validateApiKey(undefined);
375
+ * // throws: "Bugwatch: API key required. Set BUGWATCH_API_KEY environment variable or pass { apiKey: '...' }"
376
+ *
377
+ * // Invalid format (logs warning but doesn't throw)
378
+ * validateApiKey("invalid-key");
379
+ * // warns: "Bugwatch: API key should start with 'bw_'. Got 'invali...'"
380
+ * ```
381
+ */
382
+ declare function validateApiKey(key: string | undefined): asserts key is string;
383
+ /**
384
+ * Check if API key is available (either in env or passed explicitly).
385
+ *
386
+ * @param explicitKey - Explicitly provided API key
387
+ * @returns true if an API key is available
388
+ */
389
+ declare function hasApiKey(explicitKey?: string): boolean;
390
+
391
+ /**
392
+ * Request-scoped context using AsyncLocalStorage.
393
+ *
394
+ * This module provides thread-safe, request-isolated context storage
395
+ * for Node.js environments. Each concurrent request gets its own
396
+ * isolated context that won't leak to other requests.
397
+ */
398
+
399
+ /**
400
+ * Request-scoped context that is isolated per request
401
+ */
402
+ interface ScopedContext {
403
+ user: UserContext | null;
404
+ tags: Record<string, string>;
405
+ extra: Record<string, unknown>;
406
+ breadcrumbs: Breadcrumb[];
407
+ }
408
+ /**
409
+ * Create a new empty scoped context
410
+ */
411
+ declare function createScopedContext(): ScopedContext;
412
+ /**
413
+ * Run a function within an isolated context.
414
+ *
415
+ * All context operations (setUser, setTag, etc.) within this function
416
+ * will be scoped to this context and won't affect other concurrent requests.
417
+ *
418
+ * @param context - The initial context for this scope
419
+ * @param fn - The function to run within the context
420
+ * @returns The result of the function
421
+ */
422
+ declare function runWithContext<T>(context: ScopedContext, fn: () => T): T;
423
+ /**
424
+ * Run an async function within an isolated context.
425
+ */
426
+ declare function runWithContextAsync<T>(context: ScopedContext, fn: () => Promise<T>): Promise<T>;
427
+ /**
428
+ * Get the current request-scoped context.
429
+ * Returns undefined if not running within a context scope.
430
+ */
431
+ declare function getRequestContext(): ScopedContext | undefined;
432
+ /**
433
+ * Check if we're currently running within a scoped context
434
+ */
435
+ declare function hasRequestContext(): boolean;
436
+ /**
437
+ * Set user in the current request context (if available)
438
+ * Returns true if the user was set in request context, false otherwise
439
+ */
440
+ declare function setRequestUser(user: UserContext | null): boolean;
441
+ /**
442
+ * Set a tag in the current request context (if available)
443
+ * Returns true if the tag was set in request context, false otherwise
444
+ */
445
+ declare function setRequestTag(key: string, value: string): boolean;
446
+ /**
447
+ * Set extra data in the current request context (if available)
448
+ * Returns true if the extra was set in request context, false otherwise
449
+ */
450
+ declare function setRequestExtra(key: string, value: unknown): boolean;
451
+ /**
452
+ * Add a breadcrumb to the current request context (if available)
453
+ * Returns true if the breadcrumb was added to request context, false otherwise
454
+ */
455
+ declare function addRequestBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): boolean;
456
+ /**
457
+ * Get the merged context from request scope and global scope
458
+ */
459
+ declare function getMergedContext(globalUser: UserContext | null, globalTags: Record<string, string>, globalExtra: Record<string, unknown>, globalBreadcrumbs: Breadcrumb[]): {
460
+ user: UserContext | null;
461
+ tags: Record<string, string>;
462
+ extra: Record<string, unknown>;
463
+ breadcrumbs: Breadcrumb[];
464
+ };
465
+
466
+ /**
467
+ * Initialize the global Bugwatch client.
468
+ *
469
+ * Reads configuration from environment variables if not explicitly provided:
470
+ * - `BUGWATCH_API_KEY` - API key (required)
471
+ * - `BUGWATCH_ENVIRONMENT` - Environment tag
472
+ * - `BUGWATCH_RELEASE` - Release version
473
+ * - `BUGWATCH_DEBUG` - Enable debug mode ('true')
474
+ *
475
+ * @param options - Configuration options (optional if BUGWATCH_API_KEY env var is set)
476
+ * @throws Error if no API key is provided and BUGWATCH_API_KEY is not set
477
+ *
478
+ * @example
479
+ * ```typescript
480
+ * // With env var BUGWATCH_API_KEY set
481
+ * init();
482
+ *
483
+ * // Or explicit configuration
484
+ * init({ apiKey: "bw_live_xxxxx" });
485
+ *
486
+ * // Mix of env vars and explicit options
487
+ * init({ environment: "staging" }); // Uses BUGWATCH_API_KEY from env
488
+ * ```
489
+ */
490
+ declare function init(options?: Partial<BugwatchOptions>): Bugwatch;
294
491
  /**
295
492
  * Get the global Bugwatch client
296
493
  */
297
494
  declare function getClient(): Bugwatch | null;
298
495
  /**
299
- * Capture an exception using the global client
496
+ * Capture an exception using the global client.
497
+ *
498
+ * If the SDK is not initialized but BUGWATCH_API_KEY environment variable is set,
499
+ * the SDK will auto-initialize before capturing.
300
500
  */
301
501
  declare function captureException(error: Error, context?: Partial<ErrorEvent>): string;
302
502
  /**
303
- * Capture a message using the global client
503
+ * Capture a message using the global client.
504
+ *
505
+ * If the SDK is not initialized but BUGWATCH_API_KEY environment variable is set,
506
+ * the SDK will auto-initialize before capturing.
304
507
  */
305
508
  declare function captureMessage(message: string, level?: ErrorEvent["level"]): string;
306
509
  /**
307
- * Add a breadcrumb using the global client
510
+ * Add a breadcrumb using the global client.
511
+ * If called within a request context, adds to the request-scoped breadcrumbs.
308
512
  */
309
513
  declare function addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
310
514
  /**
311
- * Set user context on the global client
515
+ * Set user context.
516
+ * If called within a request context, sets the request-scoped user.
517
+ * Otherwise sets the global user context.
312
518
  */
313
519
  declare function setUser(user: UserContext | null): void;
314
520
  /**
315
- * Set a tag on the global client
521
+ * Set a tag.
522
+ * If called within a request context, sets the request-scoped tag.
523
+ * Otherwise sets the global tag.
316
524
  */
317
525
  declare function setTag(key: string, value: string): void;
318
526
  /**
319
- * Set extra context on the global client
527
+ * Set extra context.
528
+ * If called within a request context, sets the request-scoped extra.
529
+ * Otherwise sets the global extra context.
320
530
  */
321
531
  declare function setExtra(key: string, value: unknown): void;
532
+ /**
533
+ * Flush any pending events using the global client.
534
+ * Call this before process exit to ensure no events are lost.
535
+ */
536
+ declare function flush(): Promise<void>;
537
+ /**
538
+ * Close the global client and release any resources.
539
+ * This flushes any pending events and closes the transport.
540
+ * After calling this method, the client should not be used again.
541
+ */
542
+ declare function close(): Promise<void>;
543
+ /**
544
+ * Reset the SDK state completely.
545
+ * Use this for testing or to allow re-initialization.
546
+ * Note: This does NOT flush pending events - call close() first if needed.
547
+ */
548
+ declare function reset(): void;
322
549
 
323
- export { BatchTransport, type Breadcrumb, Bugwatch, type BugwatchClient, type BugwatchOptions, ConsoleTransport, type ErrorEvent, type ExceptionInfo, HttpTransport, type Integration, NoopTransport, type RequestContext, type RuntimeInfo, type SdkInfo, type StackFrame, type Transport, type UserContext, addBreadcrumb, captureException, captureMessage, extractErrorInfo, fingerprintFromException, generateFingerprint, getClient, init, parseStackTrace, setExtra, setTag, setUser };
550
+ export { BatchTransport, type Breadcrumb, Bugwatch, type BugwatchClient, type BugwatchOptions, ConsoleTransport, ENV_VARS, type ErrorEvent, type ExceptionInfo, HttpTransport, type Integration, NoopTransport, type RequestContext, type RuntimeInfo, type ScopedContext, type SdkInfo, type StackFrame, type Transport, type UserContext, addBreadcrumb, addRequestBreadcrumb, captureException, captureMessage, close, createScopedContext, extractErrorInfo, fingerprintFromException, flush, generateFingerprint, getClient, getEnvConfig, getMergedContext, getRequestContext, hasApiKey, hasRequestContext, init, parseStackTrace, reset, runWithContext, runWithContextAsync, setExtra, setRequestExtra, setRequestTag, setRequestUser, setTag, setUser, validateApiKey };
package/dist/index.d.ts CHANGED
@@ -131,6 +131,16 @@ interface ErrorEvent {
131
131
  */
132
132
  interface Transport {
133
133
  send(event: ErrorEvent): Promise<void>;
134
+ /**
135
+ * Flush any pending events.
136
+ * Ensures all queued events are sent before the promise resolves.
137
+ */
138
+ flush?(): Promise<void>;
139
+ /**
140
+ * Close the transport and release any resources.
141
+ * After calling this method, the transport should not be used again.
142
+ */
143
+ close?(): Promise<void>;
134
144
  }
135
145
  /**
136
146
  * Integration interface for platform-specific functionality
@@ -150,6 +160,16 @@ interface BugwatchClient {
150
160
  setTag(key: string, value: string): void;
151
161
  setExtra(key: string, value: unknown): void;
152
162
  getOptions(): BugwatchOptions;
163
+ /**
164
+ * Flush any pending events.
165
+ * Call this before process exit to ensure no events are lost.
166
+ */
167
+ flush(): Promise<void>;
168
+ /**
169
+ * Close the client and release any resources.
170
+ * This flushes any pending events and closes the transport.
171
+ */
172
+ close(): Promise<void>;
153
173
  }
154
174
 
155
175
  /**
@@ -218,6 +238,17 @@ declare class Bugwatch implements BugwatchClient {
218
238
  * Detect the current platform
219
239
  */
220
240
  private detectPlatform;
241
+ /**
242
+ * Flush any pending events.
243
+ * Call this before process exit to ensure no events are lost.
244
+ */
245
+ flush(): Promise<void>;
246
+ /**
247
+ * Close the client and release any resources.
248
+ * This flushes any pending events and closes the transport.
249
+ * After calling this method, the client should not be used again.
250
+ */
251
+ close(): Promise<void>;
221
252
  }
222
253
 
223
254
  /**
@@ -263,6 +294,10 @@ declare class BatchTransport implements Transport {
263
294
  flush(): Promise<void>;
264
295
  private startTimer;
265
296
  destroy(): void;
297
+ /**
298
+ * Close the transport, flushing any remaining events and stopping the timer.
299
+ */
300
+ close(): Promise<void>;
266
301
  }
267
302
 
268
303
  /**
@@ -288,36 +323,228 @@ declare function generateFingerprint(errorType: string, message: string, stacktr
288
323
  declare function fingerprintFromException(exception: ExceptionInfo): string;
289
324
 
290
325
  /**
291
- * Initialize the global Bugwatch client
326
+ * Environment variable utilities for Bugwatch SDK.
327
+ *
328
+ * This module provides functions for reading configuration from environment
329
+ * variables and validating API keys.
292
330
  */
293
- declare function init(options: BugwatchOptions): Bugwatch;
331
+
332
+ /**
333
+ * Supported environment variables for Bugwatch configuration.
334
+ */
335
+ declare const ENV_VARS: {
336
+ readonly API_KEY: "BUGWATCH_API_KEY";
337
+ readonly ENVIRONMENT: "BUGWATCH_ENVIRONMENT";
338
+ readonly RELEASE: "BUGWATCH_RELEASE";
339
+ readonly DEBUG: "BUGWATCH_DEBUG";
340
+ readonly ENDPOINT: "BUGWATCH_ENDPOINT";
341
+ };
342
+ /**
343
+ * Read Bugwatch configuration from environment variables.
344
+ *
345
+ * Supported environment variables:
346
+ * - `BUGWATCH_API_KEY` - API key (required unless passed explicitly)
347
+ * - `BUGWATCH_ENVIRONMENT` - Environment tag (e.g., 'production', 'staging')
348
+ * - `BUGWATCH_RELEASE` - Release version
349
+ * - `BUGWATCH_DEBUG` - Enable debug mode ('true' to enable)
350
+ * - `BUGWATCH_ENDPOINT` - Custom API endpoint
351
+ *
352
+ * @returns Partial configuration from environment variables
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * // Set environment variables
357
+ * // BUGWATCH_API_KEY=bw_live_xxxxx
358
+ * // BUGWATCH_ENVIRONMENT=production
359
+ *
360
+ * const envConfig = getEnvConfig();
361
+ * // { apiKey: 'bw_live_xxxxx', environment: 'production' }
362
+ * ```
363
+ */
364
+ declare function getEnvConfig(): Partial<BugwatchOptions>;
365
+ /**
366
+ * Validate an API key and throw a clear error if invalid.
367
+ *
368
+ * @param key - The API key to validate
369
+ * @throws Error if the API key is missing or invalid
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * // Missing API key
374
+ * validateApiKey(undefined);
375
+ * // throws: "Bugwatch: API key required. Set BUGWATCH_API_KEY environment variable or pass { apiKey: '...' }"
376
+ *
377
+ * // Invalid format (logs warning but doesn't throw)
378
+ * validateApiKey("invalid-key");
379
+ * // warns: "Bugwatch: API key should start with 'bw_'. Got 'invali...'"
380
+ * ```
381
+ */
382
+ declare function validateApiKey(key: string | undefined): asserts key is string;
383
+ /**
384
+ * Check if API key is available (either in env or passed explicitly).
385
+ *
386
+ * @param explicitKey - Explicitly provided API key
387
+ * @returns true if an API key is available
388
+ */
389
+ declare function hasApiKey(explicitKey?: string): boolean;
390
+
391
+ /**
392
+ * Request-scoped context using AsyncLocalStorage.
393
+ *
394
+ * This module provides thread-safe, request-isolated context storage
395
+ * for Node.js environments. Each concurrent request gets its own
396
+ * isolated context that won't leak to other requests.
397
+ */
398
+
399
+ /**
400
+ * Request-scoped context that is isolated per request
401
+ */
402
+ interface ScopedContext {
403
+ user: UserContext | null;
404
+ tags: Record<string, string>;
405
+ extra: Record<string, unknown>;
406
+ breadcrumbs: Breadcrumb[];
407
+ }
408
+ /**
409
+ * Create a new empty scoped context
410
+ */
411
+ declare function createScopedContext(): ScopedContext;
412
+ /**
413
+ * Run a function within an isolated context.
414
+ *
415
+ * All context operations (setUser, setTag, etc.) within this function
416
+ * will be scoped to this context and won't affect other concurrent requests.
417
+ *
418
+ * @param context - The initial context for this scope
419
+ * @param fn - The function to run within the context
420
+ * @returns The result of the function
421
+ */
422
+ declare function runWithContext<T>(context: ScopedContext, fn: () => T): T;
423
+ /**
424
+ * Run an async function within an isolated context.
425
+ */
426
+ declare function runWithContextAsync<T>(context: ScopedContext, fn: () => Promise<T>): Promise<T>;
427
+ /**
428
+ * Get the current request-scoped context.
429
+ * Returns undefined if not running within a context scope.
430
+ */
431
+ declare function getRequestContext(): ScopedContext | undefined;
432
+ /**
433
+ * Check if we're currently running within a scoped context
434
+ */
435
+ declare function hasRequestContext(): boolean;
436
+ /**
437
+ * Set user in the current request context (if available)
438
+ * Returns true if the user was set in request context, false otherwise
439
+ */
440
+ declare function setRequestUser(user: UserContext | null): boolean;
441
+ /**
442
+ * Set a tag in the current request context (if available)
443
+ * Returns true if the tag was set in request context, false otherwise
444
+ */
445
+ declare function setRequestTag(key: string, value: string): boolean;
446
+ /**
447
+ * Set extra data in the current request context (if available)
448
+ * Returns true if the extra was set in request context, false otherwise
449
+ */
450
+ declare function setRequestExtra(key: string, value: unknown): boolean;
451
+ /**
452
+ * Add a breadcrumb to the current request context (if available)
453
+ * Returns true if the breadcrumb was added to request context, false otherwise
454
+ */
455
+ declare function addRequestBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): boolean;
456
+ /**
457
+ * Get the merged context from request scope and global scope
458
+ */
459
+ declare function getMergedContext(globalUser: UserContext | null, globalTags: Record<string, string>, globalExtra: Record<string, unknown>, globalBreadcrumbs: Breadcrumb[]): {
460
+ user: UserContext | null;
461
+ tags: Record<string, string>;
462
+ extra: Record<string, unknown>;
463
+ breadcrumbs: Breadcrumb[];
464
+ };
465
+
466
+ /**
467
+ * Initialize the global Bugwatch client.
468
+ *
469
+ * Reads configuration from environment variables if not explicitly provided:
470
+ * - `BUGWATCH_API_KEY` - API key (required)
471
+ * - `BUGWATCH_ENVIRONMENT` - Environment tag
472
+ * - `BUGWATCH_RELEASE` - Release version
473
+ * - `BUGWATCH_DEBUG` - Enable debug mode ('true')
474
+ *
475
+ * @param options - Configuration options (optional if BUGWATCH_API_KEY env var is set)
476
+ * @throws Error if no API key is provided and BUGWATCH_API_KEY is not set
477
+ *
478
+ * @example
479
+ * ```typescript
480
+ * // With env var BUGWATCH_API_KEY set
481
+ * init();
482
+ *
483
+ * // Or explicit configuration
484
+ * init({ apiKey: "bw_live_xxxxx" });
485
+ *
486
+ * // Mix of env vars and explicit options
487
+ * init({ environment: "staging" }); // Uses BUGWATCH_API_KEY from env
488
+ * ```
489
+ */
490
+ declare function init(options?: Partial<BugwatchOptions>): Bugwatch;
294
491
  /**
295
492
  * Get the global Bugwatch client
296
493
  */
297
494
  declare function getClient(): Bugwatch | null;
298
495
  /**
299
- * Capture an exception using the global client
496
+ * Capture an exception using the global client.
497
+ *
498
+ * If the SDK is not initialized but BUGWATCH_API_KEY environment variable is set,
499
+ * the SDK will auto-initialize before capturing.
300
500
  */
301
501
  declare function captureException(error: Error, context?: Partial<ErrorEvent>): string;
302
502
  /**
303
- * Capture a message using the global client
503
+ * Capture a message using the global client.
504
+ *
505
+ * If the SDK is not initialized but BUGWATCH_API_KEY environment variable is set,
506
+ * the SDK will auto-initialize before capturing.
304
507
  */
305
508
  declare function captureMessage(message: string, level?: ErrorEvent["level"]): string;
306
509
  /**
307
- * Add a breadcrumb using the global client
510
+ * Add a breadcrumb using the global client.
511
+ * If called within a request context, adds to the request-scoped breadcrumbs.
308
512
  */
309
513
  declare function addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
310
514
  /**
311
- * Set user context on the global client
515
+ * Set user context.
516
+ * If called within a request context, sets the request-scoped user.
517
+ * Otherwise sets the global user context.
312
518
  */
313
519
  declare function setUser(user: UserContext | null): void;
314
520
  /**
315
- * Set a tag on the global client
521
+ * Set a tag.
522
+ * If called within a request context, sets the request-scoped tag.
523
+ * Otherwise sets the global tag.
316
524
  */
317
525
  declare function setTag(key: string, value: string): void;
318
526
  /**
319
- * Set extra context on the global client
527
+ * Set extra context.
528
+ * If called within a request context, sets the request-scoped extra.
529
+ * Otherwise sets the global extra context.
320
530
  */
321
531
  declare function setExtra(key: string, value: unknown): void;
532
+ /**
533
+ * Flush any pending events using the global client.
534
+ * Call this before process exit to ensure no events are lost.
535
+ */
536
+ declare function flush(): Promise<void>;
537
+ /**
538
+ * Close the global client and release any resources.
539
+ * This flushes any pending events and closes the transport.
540
+ * After calling this method, the client should not be used again.
541
+ */
542
+ declare function close(): Promise<void>;
543
+ /**
544
+ * Reset the SDK state completely.
545
+ * Use this for testing or to allow re-initialization.
546
+ * Note: This does NOT flush pending events - call close() first if needed.
547
+ */
548
+ declare function reset(): void;
322
549
 
323
- export { BatchTransport, type Breadcrumb, Bugwatch, type BugwatchClient, type BugwatchOptions, ConsoleTransport, type ErrorEvent, type ExceptionInfo, HttpTransport, type Integration, NoopTransport, type RequestContext, type RuntimeInfo, type SdkInfo, type StackFrame, type Transport, type UserContext, addBreadcrumb, captureException, captureMessage, extractErrorInfo, fingerprintFromException, generateFingerprint, getClient, init, parseStackTrace, setExtra, setTag, setUser };
550
+ export { BatchTransport, type Breadcrumb, Bugwatch, type BugwatchClient, type BugwatchOptions, ConsoleTransport, ENV_VARS, type ErrorEvent, type ExceptionInfo, HttpTransport, type Integration, NoopTransport, type RequestContext, type RuntimeInfo, type ScopedContext, type SdkInfo, type StackFrame, type Transport, type UserContext, addBreadcrumb, addRequestBreadcrumb, captureException, captureMessage, close, createScopedContext, extractErrorInfo, fingerprintFromException, flush, generateFingerprint, getClient, getEnvConfig, getMergedContext, getRequestContext, hasApiKey, hasRequestContext, init, parseStackTrace, reset, runWithContext, runWithContextAsync, setExtra, setRequestExtra, setRequestTag, setRequestUser, setTag, setUser, validateApiKey };