@maple-dev/browser 0.9.0 → 0.10.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
@@ -1,3 +1,4 @@
1
+ import "@opentelemetry/api";
1
2
  //#region ../browser-session/src/identity/identity.d.ts
2
3
  /**
3
4
  * Who the current visitor is.
@@ -34,11 +35,131 @@ type TrackProps = Readonly<Record<string, unknown>>;
34
35
  /** A Maple hosting region. Each is a separate instance with its own ingest keys. */
35
36
  type MapleRegion = "us" | "eu";
36
37
  //#endregion
38
+ //#region ../sdk-core/src/http-status.d.ts
39
+ /** A status code, or an inclusive `[from, to]` range. */
40
+ type HttpStatusRange = number | readonly [number, number];
41
+ //#endregion
42
+ //#region ../sdk-core/src/error-filters.d.ts
43
+ type ErrorSource = "captureException" | "window.onerror" | "unhandledrejection";
44
+ interface ErrorFilterHint {
45
+ readonly source: ErrorSource;
46
+ /** What was thrown, before it was normalized into an `Error`. */
47
+ readonly originalError: unknown;
48
+ }
49
+ interface ErrorFilterOptions {
50
+ /** Drop errors whose `Name: message` contains a string or matches a RegExp. */
51
+ readonly ignore?: ReadonlyArray<string | RegExp>;
52
+ /** Report only errors whose top frame's script URL matches one of these. Errors with no frames are kept. */
53
+ readonly allowUrls?: ReadonlyArray<string | RegExp>;
54
+ /** Drop errors whose top frame's script URL matches one of these. */
55
+ readonly denyUrls?: ReadonlyArray<string | RegExp>;
56
+ /** Return `false` to drop the error. Runs after the lists; if it throws, the error is kept. */
57
+ readonly beforeCapture?: (error: Error, hint: ErrorFilterHint) => boolean;
58
+ /**
59
+ * HTTP response statuses that make a client request span an error (and so an
60
+ * issue), e.g. `[[500, 599]]`. Default none: a response status alone is not
61
+ * an error, and a network failure always is.
62
+ */
63
+ readonly captureHttpStatus?: ReadonlyArray<HttpStatusRange>;
64
+ /**
65
+ * Drop errors thrown from browser extensions and the benign `ResizeObserver
66
+ * loop` notices. Default true.
67
+ */
68
+ readonly defaultFilters?: boolean;
69
+ }
70
+ //#endregion
71
+ //#region ../sdk-core/src/http-headers.d.ts
72
+ interface HeaderCaptureOptions {
73
+ readonly request?: ReadonlyArray<string>;
74
+ readonly response?: ReadonlyArray<string>;
75
+ }
76
+ //#endregion
77
+ //#region ../sdk-core/src/log-record.d.ts
78
+ type LogAttributeValue = string | number | boolean;
79
+ //#endregion
80
+ //#region ../sdk-core/src/options.d.ts
81
+ type ConsoleLevel = "debug" | "log" | "info" | "warn" | "error";
82
+ interface TracingSignalOptions {
83
+ /**
84
+ * Fraction of sessions whose traces are exported, 0–1. Default 1. Decided
85
+ * once per session, so a sampled session keeps every trace. Error spans are
86
+ * always exported.
87
+ */
88
+ readonly sampleRate?: number;
89
+ /**
90
+ * Request and response headers to record on HTTP client spans, as
91
+ * `http.request.header.<name>` / `http.response.header.<name>`. Default none.
92
+ * Credential headers (`authorization`, `cookie`, `set-cookie`, ...) are never recorded.
93
+ */
94
+ readonly captureHeaders?: HeaderCaptureOptions;
95
+ /** Span main-thread frames of 100ms or more. Default false. */
96
+ readonly longFrames?: boolean;
97
+ /** Span interactions of 200ms or more, split into input delay, processing and presentation. Default false. */
98
+ readonly slowInteractions?: boolean;
99
+ }
100
+ interface ReplayOptions {
101
+ /** Record session replays. Default true. */
102
+ readonly enabled?: boolean;
103
+ /** Fraction of sessions to record, 0–1. Default 1. */
104
+ readonly sampleRate?: number;
105
+ /**
106
+ * Fraction of the sessions not recorded that keep the last minute in memory,
107
+ * and upload it and record the rest of the session only if an error happens.
108
+ * 0–1, default 0.
109
+ */
110
+ readonly onErrorSampleRate?: number;
111
+ /**
112
+ * Record `<canvas>` content at this many frames per second. Off by default,
113
+ * and never with `maskAllText`: canvas pixels can hold text.
114
+ */
115
+ readonly canvasFps?: number;
116
+ /**
117
+ * Keep text bodies on the replay's network events for these full URLs, cut to
118
+ * `maxLength` characters (at most and by default 1,000). Nothing with
119
+ * `maskAllText`; request bodies only with `maskAllInputs` off.
120
+ */
121
+ readonly networkBodies?: {
122
+ readonly urls: ReadonlyArray<string | RegExp>;
123
+ readonly maxLength?: number;
124
+ };
125
+ }
126
+ /** The signal options shared verbatim by `MapleBrowser.init` and the Effect client presets. */
127
+ interface SignalOptions {
128
+ readonly tracing?: TracingSignalOptions;
129
+ /** Which captured errors to drop, and which HTTP statuses count as errors. */
130
+ readonly errors?: ErrorFilterOptions;
131
+ /** Report Core Web Vitals as `browser.web_vital` log events. Default true. */
132
+ readonly webVitals?: boolean;
133
+ /** Keep the last clicks, inputs, navigations and console lines, and export them with the next error. Default true. */
134
+ readonly breadcrumbs?: boolean;
135
+ readonly logs?: {
136
+ /** Console levels exported as logs as they happen, e.g. `["warn", "error"]`. Default none. */
137
+ readonly captureConsole?: ReadonlyArray<ConsoleLevel>;
138
+ };
139
+ readonly reporting?: {
140
+ /** Content Security Policy violations as `maple.browser.csp_violation` WARN logs. Default true. */
141
+ readonly csp?: boolean;
142
+ /** Browser deprecation and intervention reports as `maple.browser.report` WARN logs. Default false. */
143
+ readonly browserReports?: boolean;
144
+ };
145
+ readonly transport?: {
146
+ /**
147
+ * Keep batches that could not be sent in IndexedDB for up to 24 hours and
148
+ * send them once the browser is back online or on the next page load. Default false.
149
+ */
150
+ readonly offline?: boolean;
151
+ };
152
+ }
153
+ //#endregion
37
154
  //#region src/config.d.ts
38
- /** Public configuration for `MapleBrowser.init`. */
39
- interface MapleBrowserConfig {
40
- /** Public ingest key (`maple_pk_...`). */
41
- readonly ingestKey: string;
155
+ /** Public configuration for `MapleBrowser.init`. The signal groups are shared with the Effect SDK. */
156
+ interface MapleBrowserConfig extends SignalOptions {
157
+ /**
158
+ * Public ingest key (`maple_pk_...`), sent as `Authorization: Bearer …` and
159
+ * nothing else. Leave it unset when a proxy at `endpoint` adds auth: tracing
160
+ * and replay still run, sending without the header.
161
+ */
162
+ readonly ingestKey?: string;
42
163
  /** Service name reported on traces and stored on replay sessions. */
43
164
  readonly serviceName: string;
44
165
  /**
@@ -67,7 +188,7 @@ interface MapleBrowserConfig {
67
188
  readonly userId?: string | null | undefined;
68
189
  /** End-user identity attached to sessions and browser spans. */
69
190
  readonly user?: MapleIdentity | undefined;
70
- readonly tracing?: {
191
+ readonly tracing?: TracingSignalOptions & {
71
192
  /** Default true. */
72
193
  readonly enabled?: boolean;
73
194
  /**
@@ -77,6 +198,11 @@ interface MapleBrowserConfig {
77
198
  * sink, and disabling this avoids redundant duplicate network spans.
78
199
  */
79
200
  readonly instrumentFetch?: boolean;
201
+ /**
202
+ * Auto-instrument `XMLHttpRequest` (axios and older clients) the same way.
203
+ * Default true. Turn it off for the same reason as `instrumentFetch`.
204
+ */
205
+ readonly instrumentXhr?: boolean;
80
206
  /**
81
207
  * Capture uncaught errors and unhandled promise rejections as error
82
208
  * spans. Default true. Turn off only when another tracker already owns
@@ -91,12 +217,7 @@ interface MapleBrowserConfig {
91
217
  */
92
218
  readonly propagateTraceHeaderCorsUrls?: ReadonlyArray<string | RegExp>;
93
219
  };
94
- readonly replay?: {
95
- /** Default true. */
96
- readonly enabled?: boolean;
97
- /** Fraction of sessions to record, 0–1. Default 1. */
98
- readonly sampleRate?: number;
99
- };
220
+ readonly replay?: ReplayOptions;
100
221
  readonly privacy?: {
101
222
  /** Mask all `<input>` values. Default true. */
102
223
  readonly maskAllInputs?: boolean;
@@ -157,9 +278,24 @@ interface MapleBrowserHandle {
157
278
  readonly shutdown: () => Promise<void>;
158
279
  }
159
280
  //#endregion
281
+ //#region src/logger.d.ts
282
+ type LogMethod = (message: string, attributes?: Readonly<Record<string, LogAttributeValue>>) => void;
283
+ interface MapleLogger {
284
+ readonly debug: LogMethod;
285
+ readonly info: LogMethod;
286
+ readonly warn: LogMethod;
287
+ readonly error: LogMethod;
288
+ }
289
+ //#endregion
290
+ //#region src/navigation.d.ts
291
+ interface TracedOptions {
292
+ /** Return `false` for throws that aren't errors, like redirects or not-found. Default: every throw is an error. */
293
+ readonly isFailure?: ((error: unknown) => boolean) | undefined;
294
+ }
295
+ //#endregion
160
296
  //#region src/index.d.ts
161
297
  /** The `MapleBrowser` namespace object. */
162
- interface MapleBrowserApi {
298
+ export interface MapleBrowserApi {
163
299
  init: (config: MapleBrowserConfig) => MapleBrowserHandle;
164
300
  /**
165
301
  * Attach, replace, or clear the end-user identity on the active session.
@@ -185,6 +321,20 @@ interface MapleBrowserApi {
185
321
  captureException: (error: unknown, options?: CaptureExceptionOptions) => void;
186
322
  /** Grant or revoke consent when `privacy.requireConsent` is on. */
187
323
  setConsent: (granted: boolean) => void;
324
+ /** Call when a route change starts, with the new path. The first call in a page is the page load. */
325
+ startNavigation: (path: string) => void;
326
+ /** Call when the new route is ready, with its route pattern (`/projects/:id`), not the URL. */
327
+ endNavigation: (route?: string) => void;
328
+ /**
329
+ * Run data loading, like a route loader, in a span under the current navigation.
330
+ * Errors are recorded once and rethrown. Only requests started before `fn`'s first `await` nest under the span.
331
+ */
332
+ traced: <T>(name: string, fn: () => Promise<T>, options?: TracedOptions) => Promise<T>;
333
+ /**
334
+ * Structured logs, exported as OpenTelemetry log records linked to the active
335
+ * span and the session. Safe before `init`: records queue until it runs.
336
+ */
337
+ logger: MapleLogger;
188
338
  }
189
339
  /**
190
340
  * Maple browser SDK. One call wires up OpenTelemetry tracing and rrweb session
@@ -204,6 +354,6 @@ interface MapleBrowserApi {
204
354
  * MapleBrowser.track("checkout_completed", { plan: "pro", seats: 5 })
205
355
  * ```
206
356
  */
207
- declare const MapleBrowser: MapleBrowserApi;
357
+ export declare const MapleBrowser: MapleBrowserApi;
208
358
  //#endregion
209
- export { type CaptureExceptionOptions, type IdentifyInput, MapleBrowser, MapleBrowserApi, type MapleBrowserConfig, type MapleBrowserHandle, type MapleIdentity, type MapleRegion, type TrackProps, type TraitValue };
359
+ export type { CaptureExceptionOptions, ConsoleLevel, ErrorFilterHint, ErrorFilterOptions, ErrorSource, HttpStatusRange, IdentifyInput, LogAttributeValue, MapleBrowserConfig, MapleBrowserHandle, MapleIdentity, MapleLogger, MapleRegion, ReplayOptions, SignalOptions, TracedOptions, TracingSignalOptions, TrackProps, TraitValue };