@usereelay/browser 0.1.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/README.md +152 -0
- package/bin/reelay-sourcemaps.mjs +277 -0
- package/dist/index.cjs +14077 -0
- package/dist/index.d.cts +264 -0
- package/dist/index.d.ts +264 -0
- package/dist/index.js +14071 -0
- package/package.json +47 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types — mirror reelay-backend's ingest contract exactly
|
|
3
|
+
* (POST /api/ingest/errors, POST /api/ingest/sessions).
|
|
4
|
+
*/
|
|
5
|
+
interface StackFrame {
|
|
6
|
+
file: string;
|
|
7
|
+
line: number;
|
|
8
|
+
col?: number;
|
|
9
|
+
function?: string;
|
|
10
|
+
module?: string;
|
|
11
|
+
in_app: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Full minified script URL (before origin-stripping). The backend uses it as
|
|
14
|
+
* the release-scoped source-map match key; omitted for non-URL frames.
|
|
15
|
+
*/
|
|
16
|
+
abs_path?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Debug id of the bundle this frame belongs to, resolved at capture time from
|
|
19
|
+
* the build-injected debug-id registry. The unambiguous source-map match key.
|
|
20
|
+
*/
|
|
21
|
+
debug_id?: string;
|
|
22
|
+
}
|
|
23
|
+
interface ExceptionPayload {
|
|
24
|
+
type: string;
|
|
25
|
+
value: string;
|
|
26
|
+
mechanism?: string;
|
|
27
|
+
stacktrace?: StackFrame[];
|
|
28
|
+
}
|
|
29
|
+
interface TraceContext {
|
|
30
|
+
trace_id: string;
|
|
31
|
+
span_id?: string;
|
|
32
|
+
}
|
|
33
|
+
interface HTTPContext {
|
|
34
|
+
method: string;
|
|
35
|
+
url: string;
|
|
36
|
+
status_code?: number;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
}
|
|
39
|
+
interface TimelineLog {
|
|
40
|
+
ts: string;
|
|
41
|
+
level: string;
|
|
42
|
+
msg: string;
|
|
43
|
+
}
|
|
44
|
+
interface TimelineSpan {
|
|
45
|
+
span_id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
status?: string;
|
|
48
|
+
}
|
|
49
|
+
interface Timeline {
|
|
50
|
+
logs?: TimelineLog[];
|
|
51
|
+
spans?: TimelineSpan[];
|
|
52
|
+
}
|
|
53
|
+
interface Breadcrumb {
|
|
54
|
+
timestamp: number;
|
|
55
|
+
type: string;
|
|
56
|
+
category?: string;
|
|
57
|
+
message?: string;
|
|
58
|
+
}
|
|
59
|
+
interface ErrorEventPayload {
|
|
60
|
+
event_id: string;
|
|
61
|
+
kind: 'backend' | 'frontend';
|
|
62
|
+
platform: string;
|
|
63
|
+
timestamp: string;
|
|
64
|
+
release?: string;
|
|
65
|
+
environment?: string;
|
|
66
|
+
trace?: TraceContext;
|
|
67
|
+
session_id?: string;
|
|
68
|
+
exception: ExceptionPayload;
|
|
69
|
+
http?: HTTPContext;
|
|
70
|
+
timeline?: Timeline;
|
|
71
|
+
breadcrumbs?: Breadcrumb[];
|
|
72
|
+
}
|
|
73
|
+
/** Options shared by every Reelay SDK. */
|
|
74
|
+
interface CoreOptions {
|
|
75
|
+
/** Ingestion base URL, e.g. https://api.reelay.app */
|
|
76
|
+
endpoint: string;
|
|
77
|
+
/** The node's API key (rlyt_live_…). Never a ReelayID. */
|
|
78
|
+
token: string;
|
|
79
|
+
release?: string;
|
|
80
|
+
environment?: string;
|
|
81
|
+
/** 0–1 probability an error event is sent. Defaults to 1. */
|
|
82
|
+
sampleRate?: number;
|
|
83
|
+
/** Mutate or veto an event just before send. Return null to drop. */
|
|
84
|
+
beforeSend?: (event: ErrorEventPayload) => ErrorEventPayload | null;
|
|
85
|
+
/** Extra scrub patterns applied to all string values. */
|
|
86
|
+
scrubPatterns?: RegExp[];
|
|
87
|
+
/** Maximum buffered events while offline/rate-limited. Default 30. */
|
|
88
|
+
maxQueueSize?: number;
|
|
89
|
+
/** Emit SDK-internal diagnostics through this hook (never console by default). */
|
|
90
|
+
debug?: (message: string, detail?: unknown) => void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Fixed-capacity ring buffer for breadcrumbs: O(1) add, bounded memory, no
|
|
95
|
+
* allocation churn. The most recent `capacity` crumbs are kept.
|
|
96
|
+
*/
|
|
97
|
+
declare class BreadcrumbBuffer {
|
|
98
|
+
private readonly capacity;
|
|
99
|
+
private readonly items;
|
|
100
|
+
private head;
|
|
101
|
+
private size;
|
|
102
|
+
constructor(capacity?: number);
|
|
103
|
+
add(crumb: Breadcrumb): void;
|
|
104
|
+
/** Oldest → newest snapshot. */
|
|
105
|
+
snapshot(): Breadcrumb[];
|
|
106
|
+
clear(): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Client-side PII scrubbing. Runs before any payload leaves the host
|
|
111
|
+
* application (CLAUDE.md §6): secrets must never reach the wire.
|
|
112
|
+
*/
|
|
113
|
+
declare class Scrubber {
|
|
114
|
+
private readonly patterns;
|
|
115
|
+
constructor(extraPatterns?: RegExp[]);
|
|
116
|
+
scrubString(value: string): string;
|
|
117
|
+
/**
|
|
118
|
+
* Deep-scrubs any JSON-serializable value: sensitive keys are redacted
|
|
119
|
+
* wholesale; remaining strings run through the pattern engine. Depth-capped
|
|
120
|
+
* and cycle-safe — scrubbing must never throw or hang the host app.
|
|
121
|
+
*/
|
|
122
|
+
scrub<T>(value: T): T;
|
|
123
|
+
private walk;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Resilient, non-blocking transport (CLAUDE.md §4):
|
|
128
|
+
* - never throws into the host application;
|
|
129
|
+
* - bounded in-memory retry queue (drop-oldest, never block);
|
|
130
|
+
* - exponential backoff with full jitter;
|
|
131
|
+
* - honors 429 Retry-After;
|
|
132
|
+
* - drops (never retries) 4xx payload errors — they will never succeed.
|
|
133
|
+
*/
|
|
134
|
+
interface TransportOptions {
|
|
135
|
+
url: string;
|
|
136
|
+
token: string;
|
|
137
|
+
maxQueueSize: number;
|
|
138
|
+
/** Injectable for tests and for sendBeacon-style senders. */
|
|
139
|
+
fetchImpl?: typeof fetch;
|
|
140
|
+
debug?: (message: string, detail?: unknown) => void;
|
|
141
|
+
}
|
|
142
|
+
declare class Transport {
|
|
143
|
+
private readonly opts;
|
|
144
|
+
private readonly queue;
|
|
145
|
+
private flushPromise;
|
|
146
|
+
private pausedUntil;
|
|
147
|
+
constructor(opts: TransportOptions);
|
|
148
|
+
/** Number of payloads waiting to be delivered (for flush/drain logic). */
|
|
149
|
+
get pending(): number;
|
|
150
|
+
/**
|
|
151
|
+
* Enqueues a payload and schedules an async flush. Never blocks, never
|
|
152
|
+
* throws. When the queue is full the OLDEST item is dropped — fresh errors
|
|
153
|
+
* are worth more than stale ones.
|
|
154
|
+
*/
|
|
155
|
+
send(payload: unknown): void;
|
|
156
|
+
/**
|
|
157
|
+
* Drains the queue. Concurrent calls share the single running flush loop —
|
|
158
|
+
* awaiting flush() always waits for the actual drain (page unload and
|
|
159
|
+
* process exit depend on this).
|
|
160
|
+
*/
|
|
161
|
+
flush(): Promise<void>;
|
|
162
|
+
private drain;
|
|
163
|
+
private deliver;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface CaptureContext {
|
|
167
|
+
mechanism?: string;
|
|
168
|
+
trace?: TraceContext;
|
|
169
|
+
sessionId?: string;
|
|
170
|
+
http?: HTTPContext;
|
|
171
|
+
timeline?: Timeline;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* BaseClient holds the behavior both runtimes share: event assembly,
|
|
175
|
+
* sampling, scrubbing, beforeSend, breadcrumbs, transport. Platform SDKs
|
|
176
|
+
* subclass it and add their instrumentation. Every public method is wrapped
|
|
177
|
+
* so the SDK can never throw into the host application (CLAUDE.md §4).
|
|
178
|
+
*/
|
|
179
|
+
declare class BaseClient {
|
|
180
|
+
protected readonly options: CoreOptions;
|
|
181
|
+
protected readonly transport: Transport;
|
|
182
|
+
protected readonly scrubber: Scrubber;
|
|
183
|
+
protected readonly crumbs: BreadcrumbBuffer;
|
|
184
|
+
private readonly kind;
|
|
185
|
+
private readonly platform;
|
|
186
|
+
constructor(options: CoreOptions, kind: 'backend' | 'frontend', platform: string);
|
|
187
|
+
/** Records a breadcrumb (scrubbed, bounded). Safe to call from anywhere. */
|
|
188
|
+
addBreadcrumb(crumb: Breadcrumb): void;
|
|
189
|
+
/** Captures any thrown value. Returns the event id ('' when dropped). */
|
|
190
|
+
captureException(err: unknown, ctx?: CaptureContext): string;
|
|
191
|
+
/**
|
|
192
|
+
* Hook invoked after an error event is accepted for sending. Subclasses use
|
|
193
|
+
* it to attach side data to the captured event — e.g. the browser SDK flushes
|
|
194
|
+
* the buffered session replay clip for this error id. No-op by default.
|
|
195
|
+
*/
|
|
196
|
+
protected afterCapture(_eventId: string): void;
|
|
197
|
+
/** Captures a plain message as an error event. */
|
|
198
|
+
captureMessage(message: string, ctx?: CaptureContext): string;
|
|
199
|
+
/** Drains pending events (call before process exit / page hide). */
|
|
200
|
+
flush(): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Runs fn inside the SDK's defensive boundary: internal failures are
|
|
203
|
+
* reported to the debug hook and swallowed — never the host's problem.
|
|
204
|
+
*/
|
|
205
|
+
protected guard<T>(fn: () => T): T | undefined;
|
|
206
|
+
private sampled;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface BrowserOptions extends CoreOptions {
|
|
210
|
+
/**
|
|
211
|
+
* First-party origins that receive `traceparent` + `reelay-session-id`
|
|
212
|
+
* headers on outgoing fetch/XHR — the stitching allow-list (FRD E3.2).
|
|
213
|
+
* Origins only; never send trace headers cross-origin by default.
|
|
214
|
+
*/
|
|
215
|
+
tracePropagationTargets?: (string | RegExp)[];
|
|
216
|
+
/** Record DOM session replay. Default true. */
|
|
217
|
+
replay?: boolean;
|
|
218
|
+
/** Mask all text content in replay. Default true (PII-safe by default). */
|
|
219
|
+
maskAllText?: boolean;
|
|
220
|
+
}
|
|
221
|
+
declare class BrowserClient extends BaseClient {
|
|
222
|
+
readonly sessionId: string;
|
|
223
|
+
private readonly browserOptions;
|
|
224
|
+
private readonly tracedRequests;
|
|
225
|
+
private replayRecorder?;
|
|
226
|
+
private teardowns;
|
|
227
|
+
constructor(options: BrowserOptions);
|
|
228
|
+
install(): void;
|
|
229
|
+
uninstall(): void;
|
|
230
|
+
/** Captures with the browser session attached. */
|
|
231
|
+
capture(err: unknown, mechanism: string, trace?: TraceContext): string;
|
|
232
|
+
/**
|
|
233
|
+
* After an error is captured, flush the buffered rrweb replay clip for it —
|
|
234
|
+
* the ~30–60s of session leading up to this error, stored under a per-error
|
|
235
|
+
* replay id the dashboard reconstructs from the error event.
|
|
236
|
+
*/
|
|
237
|
+
protected afterCapture(eventId: string): void;
|
|
238
|
+
/** Decides whether an outgoing request URL gets trace headers. */
|
|
239
|
+
shouldPropagate(url: string): boolean;
|
|
240
|
+
/** Mints a trace context for an outgoing request and remembers it. */
|
|
241
|
+
startRequestTrace(url: string): {
|
|
242
|
+
headers: Record<string, string>;
|
|
243
|
+
trace: TraceContext;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Initializes the Reelay browser SDK once per page.
|
|
249
|
+
*
|
|
250
|
+
* ```ts
|
|
251
|
+
* import * as Reelay from '@usereelay/browser';
|
|
252
|
+
* Reelay.init({
|
|
253
|
+
* endpoint: 'https://api.reelay.app',
|
|
254
|
+
* token: 'rlyt_live_…',
|
|
255
|
+
* tracePropagationTargets: ['https://api.acme.com'],
|
|
256
|
+
* });
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
declare function init(options: BrowserOptions): BrowserClient;
|
|
260
|
+
declare function getClient(): BrowserClient | undefined;
|
|
261
|
+
declare function captureException(err: unknown): string;
|
|
262
|
+
declare function captureMessage(message: string): string;
|
|
263
|
+
|
|
264
|
+
export { type Breadcrumb, BrowserClient, type BrowserOptions, type CoreOptions, type ErrorEventPayload, captureException, captureMessage, getClient, init };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types — mirror reelay-backend's ingest contract exactly
|
|
3
|
+
* (POST /api/ingest/errors, POST /api/ingest/sessions).
|
|
4
|
+
*/
|
|
5
|
+
interface StackFrame {
|
|
6
|
+
file: string;
|
|
7
|
+
line: number;
|
|
8
|
+
col?: number;
|
|
9
|
+
function?: string;
|
|
10
|
+
module?: string;
|
|
11
|
+
in_app: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Full minified script URL (before origin-stripping). The backend uses it as
|
|
14
|
+
* the release-scoped source-map match key; omitted for non-URL frames.
|
|
15
|
+
*/
|
|
16
|
+
abs_path?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Debug id of the bundle this frame belongs to, resolved at capture time from
|
|
19
|
+
* the build-injected debug-id registry. The unambiguous source-map match key.
|
|
20
|
+
*/
|
|
21
|
+
debug_id?: string;
|
|
22
|
+
}
|
|
23
|
+
interface ExceptionPayload {
|
|
24
|
+
type: string;
|
|
25
|
+
value: string;
|
|
26
|
+
mechanism?: string;
|
|
27
|
+
stacktrace?: StackFrame[];
|
|
28
|
+
}
|
|
29
|
+
interface TraceContext {
|
|
30
|
+
trace_id: string;
|
|
31
|
+
span_id?: string;
|
|
32
|
+
}
|
|
33
|
+
interface HTTPContext {
|
|
34
|
+
method: string;
|
|
35
|
+
url: string;
|
|
36
|
+
status_code?: number;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
}
|
|
39
|
+
interface TimelineLog {
|
|
40
|
+
ts: string;
|
|
41
|
+
level: string;
|
|
42
|
+
msg: string;
|
|
43
|
+
}
|
|
44
|
+
interface TimelineSpan {
|
|
45
|
+
span_id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
status?: string;
|
|
48
|
+
}
|
|
49
|
+
interface Timeline {
|
|
50
|
+
logs?: TimelineLog[];
|
|
51
|
+
spans?: TimelineSpan[];
|
|
52
|
+
}
|
|
53
|
+
interface Breadcrumb {
|
|
54
|
+
timestamp: number;
|
|
55
|
+
type: string;
|
|
56
|
+
category?: string;
|
|
57
|
+
message?: string;
|
|
58
|
+
}
|
|
59
|
+
interface ErrorEventPayload {
|
|
60
|
+
event_id: string;
|
|
61
|
+
kind: 'backend' | 'frontend';
|
|
62
|
+
platform: string;
|
|
63
|
+
timestamp: string;
|
|
64
|
+
release?: string;
|
|
65
|
+
environment?: string;
|
|
66
|
+
trace?: TraceContext;
|
|
67
|
+
session_id?: string;
|
|
68
|
+
exception: ExceptionPayload;
|
|
69
|
+
http?: HTTPContext;
|
|
70
|
+
timeline?: Timeline;
|
|
71
|
+
breadcrumbs?: Breadcrumb[];
|
|
72
|
+
}
|
|
73
|
+
/** Options shared by every Reelay SDK. */
|
|
74
|
+
interface CoreOptions {
|
|
75
|
+
/** Ingestion base URL, e.g. https://api.reelay.app */
|
|
76
|
+
endpoint: string;
|
|
77
|
+
/** The node's API key (rlyt_live_…). Never a ReelayID. */
|
|
78
|
+
token: string;
|
|
79
|
+
release?: string;
|
|
80
|
+
environment?: string;
|
|
81
|
+
/** 0–1 probability an error event is sent. Defaults to 1. */
|
|
82
|
+
sampleRate?: number;
|
|
83
|
+
/** Mutate or veto an event just before send. Return null to drop. */
|
|
84
|
+
beforeSend?: (event: ErrorEventPayload) => ErrorEventPayload | null;
|
|
85
|
+
/** Extra scrub patterns applied to all string values. */
|
|
86
|
+
scrubPatterns?: RegExp[];
|
|
87
|
+
/** Maximum buffered events while offline/rate-limited. Default 30. */
|
|
88
|
+
maxQueueSize?: number;
|
|
89
|
+
/** Emit SDK-internal diagnostics through this hook (never console by default). */
|
|
90
|
+
debug?: (message: string, detail?: unknown) => void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Fixed-capacity ring buffer for breadcrumbs: O(1) add, bounded memory, no
|
|
95
|
+
* allocation churn. The most recent `capacity` crumbs are kept.
|
|
96
|
+
*/
|
|
97
|
+
declare class BreadcrumbBuffer {
|
|
98
|
+
private readonly capacity;
|
|
99
|
+
private readonly items;
|
|
100
|
+
private head;
|
|
101
|
+
private size;
|
|
102
|
+
constructor(capacity?: number);
|
|
103
|
+
add(crumb: Breadcrumb): void;
|
|
104
|
+
/** Oldest → newest snapshot. */
|
|
105
|
+
snapshot(): Breadcrumb[];
|
|
106
|
+
clear(): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Client-side PII scrubbing. Runs before any payload leaves the host
|
|
111
|
+
* application (CLAUDE.md §6): secrets must never reach the wire.
|
|
112
|
+
*/
|
|
113
|
+
declare class Scrubber {
|
|
114
|
+
private readonly patterns;
|
|
115
|
+
constructor(extraPatterns?: RegExp[]);
|
|
116
|
+
scrubString(value: string): string;
|
|
117
|
+
/**
|
|
118
|
+
* Deep-scrubs any JSON-serializable value: sensitive keys are redacted
|
|
119
|
+
* wholesale; remaining strings run through the pattern engine. Depth-capped
|
|
120
|
+
* and cycle-safe — scrubbing must never throw or hang the host app.
|
|
121
|
+
*/
|
|
122
|
+
scrub<T>(value: T): T;
|
|
123
|
+
private walk;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Resilient, non-blocking transport (CLAUDE.md §4):
|
|
128
|
+
* - never throws into the host application;
|
|
129
|
+
* - bounded in-memory retry queue (drop-oldest, never block);
|
|
130
|
+
* - exponential backoff with full jitter;
|
|
131
|
+
* - honors 429 Retry-After;
|
|
132
|
+
* - drops (never retries) 4xx payload errors — they will never succeed.
|
|
133
|
+
*/
|
|
134
|
+
interface TransportOptions {
|
|
135
|
+
url: string;
|
|
136
|
+
token: string;
|
|
137
|
+
maxQueueSize: number;
|
|
138
|
+
/** Injectable for tests and for sendBeacon-style senders. */
|
|
139
|
+
fetchImpl?: typeof fetch;
|
|
140
|
+
debug?: (message: string, detail?: unknown) => void;
|
|
141
|
+
}
|
|
142
|
+
declare class Transport {
|
|
143
|
+
private readonly opts;
|
|
144
|
+
private readonly queue;
|
|
145
|
+
private flushPromise;
|
|
146
|
+
private pausedUntil;
|
|
147
|
+
constructor(opts: TransportOptions);
|
|
148
|
+
/** Number of payloads waiting to be delivered (for flush/drain logic). */
|
|
149
|
+
get pending(): number;
|
|
150
|
+
/**
|
|
151
|
+
* Enqueues a payload and schedules an async flush. Never blocks, never
|
|
152
|
+
* throws. When the queue is full the OLDEST item is dropped — fresh errors
|
|
153
|
+
* are worth more than stale ones.
|
|
154
|
+
*/
|
|
155
|
+
send(payload: unknown): void;
|
|
156
|
+
/**
|
|
157
|
+
* Drains the queue. Concurrent calls share the single running flush loop —
|
|
158
|
+
* awaiting flush() always waits for the actual drain (page unload and
|
|
159
|
+
* process exit depend on this).
|
|
160
|
+
*/
|
|
161
|
+
flush(): Promise<void>;
|
|
162
|
+
private drain;
|
|
163
|
+
private deliver;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface CaptureContext {
|
|
167
|
+
mechanism?: string;
|
|
168
|
+
trace?: TraceContext;
|
|
169
|
+
sessionId?: string;
|
|
170
|
+
http?: HTTPContext;
|
|
171
|
+
timeline?: Timeline;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* BaseClient holds the behavior both runtimes share: event assembly,
|
|
175
|
+
* sampling, scrubbing, beforeSend, breadcrumbs, transport. Platform SDKs
|
|
176
|
+
* subclass it and add their instrumentation. Every public method is wrapped
|
|
177
|
+
* so the SDK can never throw into the host application (CLAUDE.md §4).
|
|
178
|
+
*/
|
|
179
|
+
declare class BaseClient {
|
|
180
|
+
protected readonly options: CoreOptions;
|
|
181
|
+
protected readonly transport: Transport;
|
|
182
|
+
protected readonly scrubber: Scrubber;
|
|
183
|
+
protected readonly crumbs: BreadcrumbBuffer;
|
|
184
|
+
private readonly kind;
|
|
185
|
+
private readonly platform;
|
|
186
|
+
constructor(options: CoreOptions, kind: 'backend' | 'frontend', platform: string);
|
|
187
|
+
/** Records a breadcrumb (scrubbed, bounded). Safe to call from anywhere. */
|
|
188
|
+
addBreadcrumb(crumb: Breadcrumb): void;
|
|
189
|
+
/** Captures any thrown value. Returns the event id ('' when dropped). */
|
|
190
|
+
captureException(err: unknown, ctx?: CaptureContext): string;
|
|
191
|
+
/**
|
|
192
|
+
* Hook invoked after an error event is accepted for sending. Subclasses use
|
|
193
|
+
* it to attach side data to the captured event — e.g. the browser SDK flushes
|
|
194
|
+
* the buffered session replay clip for this error id. No-op by default.
|
|
195
|
+
*/
|
|
196
|
+
protected afterCapture(_eventId: string): void;
|
|
197
|
+
/** Captures a plain message as an error event. */
|
|
198
|
+
captureMessage(message: string, ctx?: CaptureContext): string;
|
|
199
|
+
/** Drains pending events (call before process exit / page hide). */
|
|
200
|
+
flush(): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Runs fn inside the SDK's defensive boundary: internal failures are
|
|
203
|
+
* reported to the debug hook and swallowed — never the host's problem.
|
|
204
|
+
*/
|
|
205
|
+
protected guard<T>(fn: () => T): T | undefined;
|
|
206
|
+
private sampled;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface BrowserOptions extends CoreOptions {
|
|
210
|
+
/**
|
|
211
|
+
* First-party origins that receive `traceparent` + `reelay-session-id`
|
|
212
|
+
* headers on outgoing fetch/XHR — the stitching allow-list (FRD E3.2).
|
|
213
|
+
* Origins only; never send trace headers cross-origin by default.
|
|
214
|
+
*/
|
|
215
|
+
tracePropagationTargets?: (string | RegExp)[];
|
|
216
|
+
/** Record DOM session replay. Default true. */
|
|
217
|
+
replay?: boolean;
|
|
218
|
+
/** Mask all text content in replay. Default true (PII-safe by default). */
|
|
219
|
+
maskAllText?: boolean;
|
|
220
|
+
}
|
|
221
|
+
declare class BrowserClient extends BaseClient {
|
|
222
|
+
readonly sessionId: string;
|
|
223
|
+
private readonly browserOptions;
|
|
224
|
+
private readonly tracedRequests;
|
|
225
|
+
private replayRecorder?;
|
|
226
|
+
private teardowns;
|
|
227
|
+
constructor(options: BrowserOptions);
|
|
228
|
+
install(): void;
|
|
229
|
+
uninstall(): void;
|
|
230
|
+
/** Captures with the browser session attached. */
|
|
231
|
+
capture(err: unknown, mechanism: string, trace?: TraceContext): string;
|
|
232
|
+
/**
|
|
233
|
+
* After an error is captured, flush the buffered rrweb replay clip for it —
|
|
234
|
+
* the ~30–60s of session leading up to this error, stored under a per-error
|
|
235
|
+
* replay id the dashboard reconstructs from the error event.
|
|
236
|
+
*/
|
|
237
|
+
protected afterCapture(eventId: string): void;
|
|
238
|
+
/** Decides whether an outgoing request URL gets trace headers. */
|
|
239
|
+
shouldPropagate(url: string): boolean;
|
|
240
|
+
/** Mints a trace context for an outgoing request and remembers it. */
|
|
241
|
+
startRequestTrace(url: string): {
|
|
242
|
+
headers: Record<string, string>;
|
|
243
|
+
trace: TraceContext;
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Initializes the Reelay browser SDK once per page.
|
|
249
|
+
*
|
|
250
|
+
* ```ts
|
|
251
|
+
* import * as Reelay from '@usereelay/browser';
|
|
252
|
+
* Reelay.init({
|
|
253
|
+
* endpoint: 'https://api.reelay.app',
|
|
254
|
+
* token: 'rlyt_live_…',
|
|
255
|
+
* tracePropagationTargets: ['https://api.acme.com'],
|
|
256
|
+
* });
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
declare function init(options: BrowserOptions): BrowserClient;
|
|
260
|
+
declare function getClient(): BrowserClient | undefined;
|
|
261
|
+
declare function captureException(err: unknown): string;
|
|
262
|
+
declare function captureMessage(message: string): string;
|
|
263
|
+
|
|
264
|
+
export { type Breadcrumb, BrowserClient, type BrowserOptions, type CoreOptions, type ErrorEventPayload, captureException, captureMessage, getClient, init };
|