-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmessage-processor.ts
More file actions
57 lines (52 loc) · 1.64 KB
/
message-processor.ts
File metadata and controls
57 lines (52 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type { Breadcrumb, CatcherMessagePayload, CatcherMessageType } from '@hawk.so/types';
/**
* Extracted addons type from catcher message payload.
*
* @typeParam T - catcher message type
*/
type ExtractAddons<T extends CatcherMessageType> =
CatcherMessagePayload<T> extends { addons?: infer A } ? A : never;
/**
* Payload type used during message processing pipeline.
*
* Same as {@link CatcherMessagePayload} but with `addons` always defined and partially filled —
* processors may contribute individual addon fields independently of each other.
*
* @typeParam T - catcher message type this payload belongs to
*/
export type ProcessingPayload<T extends CatcherMessageType> =
Omit<CatcherMessagePayload<T>, 'addons'> & {
addons: Partial<ExtractAddons<T>>;
};
/**
* Snapshot of event context captured synchronously at error time,
* before any processing.
*/
export interface MessageHint {
/**
* Original caught error.
*/
error?: Error | string;
/**
* Breadcrumbs captured at error time.
*/
breadcrumbs?: Breadcrumb[];
}
/**
* Single step in message processing pipeline before message is sent.
*
* @typeParam T - catcher message type this processor handles
*/
export interface MessageProcessor<T extends CatcherMessageType = CatcherMessageType> {
/**
* Handles input message. May mutate or replace it.
*
* @param payload - processed event message payload with partially-built addons
* @param hint - additional context about original error
* @returns modified payload, or `null` to drop event
*/
apply(
payload: ProcessingPayload<T>,
hint?: MessageHint,
): ProcessingPayload<T> | null
}