Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export { buildElementSelector } from './utils/selector';
export { EventRejectedError } from './errors';
export { isErrorProcessed, markErrorAsProcessed } from './utils/event';
export type { BreadcrumbStore, BreadcrumbsAPI, BreadcrumbHint, BreadcrumbInput } from './breadcrumbs/breadcrumb-store';
export type { MessageHint, MessageProcessor } from './messages/message-processor';
export { BreadcrumbsMessageProcessor } from './messages/breadcrumbs-message-processor';;
25 changes: 25 additions & 0 deletions packages/core/src/messages/breadcrumbs-message-processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { CatcherMessagePayload } from '@hawk.so/types';
import type { MessageHint, MessageProcessor } from './message-processor';

/**
* Attaches breadcrumbs snapshot from {@link hint} to payload.
*/
export class BreadcrumbsMessageProcessor implements MessageProcessor<'errors/javascript'> {
/**
* Sets `payload.breadcrumbs` from hint snapshot if non-empty; skips otherwise.
*
* @param payload - event message payload to enrich
* @param hint - hint carrying breadcrumbs snapshot captured at error time
* @returns modified payload with breadcrumbs set, or original payload unchanged

Check warning on line 13 in packages/core/src/messages/breadcrumbs-message-processor.ts

View workflow job for this annotation

GitHub Actions / lint

Missing JSDoc @returns type
*/
public apply(
payload: CatcherMessagePayload<'errors/javascript'>,
hint?: MessageHint
): CatcherMessagePayload<'errors/javascript'> | null {
if (hint?.breadcrumbs && hint.breadcrumbs.length > 0) {
payload.breadcrumbs = hint.breadcrumbs;
}

return payload;
}
}
36 changes: 36 additions & 0 deletions packages/core/src/messages/message-processor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Breadcrumb, CatcherMessagePayload, CatcherMessageType } from '@hawk.so/types';

/**
* 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

Check warning on line 22 in packages/core/src/messages/message-processor.ts

View workflow job for this annotation

GitHub Actions / lint

Invalid JSDoc tag name "typeParam"
*/
export interface MessageProcessor<T extends CatcherMessageType = CatcherMessageType> {
/**
* Handles input message. May mutate or replace it.
*
* @param payload - processed event message payload
* @param hint - additional context about original error
* @returns modified payload, or `null` to drop event
*/
apply(
payload: CatcherMessagePayload<T>,
hint?: MessageHint,
): CatcherMessagePayload<T> | null
}
1 change: 0 additions & 1 deletion packages/core/src/modules/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
private static readonly maxArrayLength: number = 10;

/**
* Custom type handlers registered via {@link registerHandler}.

Check warning on line 52 in packages/core/src/modules/sanitizer.ts

View workflow job for this annotation

GitHub Actions / lint

The type 'sanitize' is undefined

Check warning on line 52 in packages/core/src/modules/sanitizer.ts

View workflow job for this annotation

GitHub Actions / lint

The type 'registerHandler' is undefined
*
* Checked in {@link sanitize} before built-in type checks.
*/
Expand Down Expand Up @@ -154,7 +154,6 @@
depth: number,
seen: WeakSet<object>
): Record<string, any> | '<deep object>' | '<big object>' {

// If the maximum depth is reached, return a placeholder
if (depth > Sanitizer.maxDepth) {
return '<deep object>';
Expand Down
17 changes: 0 additions & 17 deletions packages/javascript/src/addons/userAgentInfo.ts

This file was deleted.

Loading
Loading