@maple-dev/browser 0.8.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.
@@ -26,18 +27,148 @@ interface MapleIdentity {
26
27
  */
27
28
  type IdentifyInput = string | null | undefined | MapleIdentity;
28
29
  //#endregion
29
- //#region ../browser-session/src/events/track.d.ts
30
+ //#region ../browser-session/src/events/props.d.ts
30
31
  /** Properties a host app may attach to a custom event. */
31
32
  type TrackProps = Readonly<Record<string, unknown>>;
32
33
  //#endregion
34
+ //#region ../browser-session/src/platform/region.d.ts
35
+ /** A Maple hosting region. Each is a separate instance with its own ingest keys. */
36
+ type MapleRegion = "us" | "eu";
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
33
154
  //#region src/config.d.ts
34
- /** Public configuration for `MapleBrowser.init`. */
35
- interface MapleBrowserConfig {
36
- /** Public ingest key (`maple_pk_...`). */
37
- 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;
38
163
  /** Service name reported on traces and stored on replay sessions. */
39
164
  readonly serviceName: string;
40
- /** Maple ingest base URL. Defaults to `https://ingest.maple.dev`. */
165
+ /**
166
+ * Region your Maple organization lives in: `"us"` (default,
167
+ * `https://ingest.maple.dev`) or `"eu"` (`https://ingest.eu.maple.dev`).
168
+ * Ingest keys belong to one region. Ignored when `endpoint` is set.
169
+ */
170
+ readonly region?: MapleRegion;
171
+ /** Maple ingest base URL. Overrides `region`; use it for a proxy or self-hosted ingest. */
41
172
  readonly endpoint?: string;
42
173
  /**
43
174
  * Logical group this service belongs to, emitted as the OTel
@@ -57,7 +188,7 @@ interface MapleBrowserConfig {
57
188
  readonly userId?: string | null | undefined;
58
189
  /** End-user identity attached to sessions and browser spans. */
59
190
  readonly user?: MapleIdentity | undefined;
60
- readonly tracing?: {
191
+ readonly tracing?: TracingSignalOptions & {
61
192
  /** Default true. */
62
193
  readonly enabled?: boolean;
63
194
  /**
@@ -67,13 +198,26 @@ interface MapleBrowserConfig {
67
198
  * sink, and disabling this avoids redundant duplicate network spans.
68
199
  */
69
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;
206
+ /**
207
+ * Capture uncaught errors and unhandled promise rejections as error
208
+ * spans. Default true. Turn off only when another tracker already owns
209
+ * the page's global error handlers, or the same crash lands twice.
210
+ */
211
+ readonly captureErrors?: boolean;
212
+ /**
213
+ * Cross-origin URLs whose `fetch()` requests carry the W3C `traceparent`
214
+ * header, so the browser span and your backend's span join one trace.
215
+ * Same-origin requests always carry it. Your API must allow the
216
+ * `traceparent` header in CORS. Example: `[/^https:\/\/api\.example\.com\//]`.
217
+ */
218
+ readonly propagateTraceHeaderCorsUrls?: ReadonlyArray<string | RegExp>;
70
219
  };
71
- readonly replay?: {
72
- /** Default true. */
73
- readonly enabled?: boolean;
74
- /** Fraction of sessions to record, 0–1. Default 1. */
75
- readonly sampleRate?: number;
76
- };
220
+ readonly replay?: ReplayOptions;
77
221
  readonly privacy?: {
78
222
  /** Mask all `<input>` values. Default true. */
79
223
  readonly maskAllInputs?: boolean;
@@ -107,9 +251,25 @@ interface MapleBrowserConfig {
107
251
  readonly captureUserEmail?: boolean;
108
252
  /** Treat `navigator.doNotTrack` like Global Privacy Control. Default false. */
109
253
  readonly respectDoNotTrack?: boolean;
254
+ /**
255
+ * Rewrite every URL before it leaves the page: session entry and exit
256
+ * URLs, event rows, network events, replay meta events, and span
257
+ * attributes. Runs after the built-in redaction, which already replaces
258
+ * the values of credential-shaped query and fragment parameters
259
+ * (`token`, `code`, `access_token`, `password`, …).
260
+ */
261
+ readonly sanitizeUrl?: (url: string) => string;
110
262
  };
111
263
  }
112
264
  //#endregion
265
+ //#region src/errors.d.ts
266
+ interface CaptureExceptionOptions {
267
+ /** Span name. Default `"exception"`. */
268
+ readonly name?: string | undefined;
269
+ /** Extra span attributes. */
270
+ readonly attributes?: Record<string, string | number | boolean> | undefined;
271
+ }
272
+ //#endregion
113
273
  //#region src/init.d.ts
114
274
  interface MapleBrowserHandle {
115
275
  /** Empty until consent is granted when `requireConsent` is enabled. */
@@ -118,7 +278,64 @@ interface MapleBrowserHandle {
118
278
  readonly shutdown: () => Promise<void>;
119
279
  }
120
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
121
296
  //#region src/index.d.ts
297
+ /** The `MapleBrowser` namespace object. */
298
+ export interface MapleBrowserApi {
299
+ init: (config: MapleBrowserConfig) => MapleBrowserHandle;
300
+ /**
301
+ * Attach, replace, or clear the end-user identity on the active session.
302
+ * Accepts a bare user id or the full identity object. Safe to call repeatedly,
303
+ * and before `init` (the latest call is applied when `init` runs).
304
+ */
305
+ identify: (input?: IdentifyInput) => void;
306
+ /**
307
+ * Record a custom product event against the active session. Safe to call
308
+ * before `init` — events are queued (capped) and drained once the session
309
+ * starts.
310
+ */
311
+ track: (name: string, props?: TrackProps) => void;
312
+ /**
313
+ * Report an error your app already caught — the case the global handlers
314
+ * cannot see, because catching it is what stops it reaching them. A
315
+ * framework error boundary is the canonical caller. The same error object
316
+ * is recorded once, even if it is rethrown afterwards.
317
+ *
318
+ * BOUNDARY: a thrown value is unparsed by definition — JavaScript can throw
319
+ * anything. `captureException` narrows it before it reaches a span.
320
+ */
321
+ captureException: (error: unknown, options?: CaptureExceptionOptions) => void;
322
+ /** Grant or revoke consent when `privacy.requireConsent` is on. */
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;
338
+ }
122
339
  /**
123
340
  * Maple browser SDK. One call wires up OpenTelemetry tracing and rrweb session
124
341
  * replay, both tagged with a shared session id.
@@ -130,27 +347,13 @@ interface MapleBrowserHandle {
130
347
  * MapleBrowser.init({
131
348
  * ingestKey: "maple_pk_...",
132
349
  * serviceName: "acme-web",
350
+ * region: "eu", // omit for the US region
133
351
  * })
134
352
  *
135
353
  * MapleBrowser.identify({ id: user.id, email: user.email, groupId: org.id, groupName: org.name })
136
354
  * MapleBrowser.track("checkout_completed", { plan: "pro", seats: 5 })
137
355
  * ```
138
356
  */
139
- declare const MapleBrowser: {
140
- init: (config: MapleBrowserConfig) => MapleBrowserHandle;
141
- /**
142
- * Attach, replace, or clear the end-user identity on the active session.
143
- * Accepts a bare user id or the full identity object. Safe to call repeatedly.
144
- */
145
- identify: (input?: IdentifyInput) => void;
146
- /**
147
- * Record a custom product event against the active session. Safe to call
148
- * before `init` — events are queued (capped) and drained once the session
149
- * starts.
150
- */
151
- track: (name: string, props?: TrackProps) => void;
152
- /** Grant or revoke consent when `privacy.requireConsent` is on. */
153
- setConsent: (granted: boolean) => void;
154
- };
357
+ export declare const MapleBrowser: MapleBrowserApi;
155
358
  //#endregion
156
- export { type IdentifyInput, MapleBrowser, type MapleBrowserConfig, type MapleBrowserHandle, type MapleIdentity, 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 };