Skip to content

Commit c049bd4

Browse files
committed
refactor(javascript): MessageProcessor abstraction added and implemented in catcher event processing pipeline
- MessageProcessor interface and MessageHint type - BrowserMessageProcessor, BreadcrumbsMessageProcessor, ConsoleCatcherMessageProcessor, DebugMessageProcessor - replaced inline addon logic with sequential MessageProcessor pipeline
1 parent 1b2b7df commit c049bd4

19 files changed

Lines changed: 541 additions & 215 deletions

packages/core/src/errors.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export type { Transport } from './transports/transport';
1010
export type { SanitizerTypeHandler } from './modules/sanitizer';
1111
export { StackParser } from './modules/stack-parser';
1212
export { buildElementSelector } from './utils/selector';
13-
export { EventRejectedError } from './errors';
1413
export { isErrorProcessed, markErrorAsProcessed } from './utils/event';
1514
export type { BreadcrumbStore, BreadcrumbsAPI, BreadcrumbHint, BreadcrumbInput } from './breadcrumbs/breadcrumb-store';
15+
export type { MessageProcessor, ProcessingPayload } from './messages/message-processor';
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { CatcherMessagePayload, CatcherMessageType } from '@hawk.so/types';
2+
3+
/**
4+
* Extracted addons type from catcher message payload.
5+
*
6+
* @typeParam T - catcher message type
7+
*/
8+
type ExtractAddons<T extends CatcherMessageType> =
9+
CatcherMessagePayload<T> extends { addons?: infer A } ? A : never;
10+
11+
/**
12+
* Payload type used during message processing pipeline.
13+
*
14+
* Same as {@link CatcherMessagePayload} but with `addons` always defined and partially filled —
15+
* processors may contribute individual addon fields independently of each other.
16+
*
17+
* @typeParam T - catcher message type this payload belongs to
18+
*/
19+
export type ProcessingPayload<T extends CatcherMessageType> =
20+
Omit<CatcherMessagePayload<T>, 'addons'> & {
21+
addons: Partial<ExtractAddons<T>>;
22+
};
23+
24+
/**
25+
* Single step in message processing pipeline before message is sent.
26+
*
27+
* @typeParam T - catcher message type this processor handles
28+
*/
29+
export interface MessageProcessor<T extends CatcherMessageType = CatcherMessageType> {
30+
/**
31+
* Handles input message. May mutate, replace or drop it.
32+
*
33+
* Dropped message won't be sent.
34+
*
35+
* @param payload - processed event message payload with partially-built addons
36+
* @param error - original error
37+
* @returns modified payload, or `null` to drop message
38+
*/
39+
apply(
40+
payload: ProcessingPayload<T>,
41+
error?: Error | string,
42+
): ProcessingPayload<T> | null
43+
}

packages/core/src/modules/sanitizer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ export class Sanitizer {
154154
depth: number,
155155
seen: WeakSet<object>
156156
): Record<string, any> | '<deep object>' | '<big object>' {
157-
158157
// If the maximum depth is reached, return a placeholder
159158
if (depth > Sanitizer.maxDepth) {
160159
return '<deep object>';

packages/javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hawk.so/javascript",
3-
"version": "3.2.20",
3+
"version": "3.2.21",
44
"description": "JavaScript errors tracking for Hawk.so",
55
"files": [
66
"dist"

packages/javascript/src/addons/userAgentInfo.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)