@groundcover/browser 1.0.9 → 2.0.0-rc.1

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.ts CHANGED
@@ -1,19 +1,9 @@
1
1
  /**
2
- * The event kinds the browser SDK ships today. This is the DEFAULT vocabulary,
3
- * not the only permitted one — see `BaseEvent`.
2
+ * `TType` lets a platform name its own event kinds without editing core, and every core class
3
+ * flows it through. Defaults to `string`, because the set of NAMES is open — a platform that
4
+ * wants a closed union passes its own. Shared shapes stay shared; only the vocabulary is open.
4
5
  */
5
- type KnownEventType = "dom.event" | "exception" | "network" | "log" | "pageload" | "navigation" | "custom" | "performance" | "replay";
6
- /**
7
- * `TType` is what lets a platform package name its own event kinds without
8
- * editing core: React Native can pass `KnownEventType | "tap" | "screen_view"`
9
- * and every core class below flows it through. It defaults to
10
- * `KnownEventType`, so nothing that only deals in the shipped browser kinds
11
- * has to spell it out.
12
- *
13
- * Shared shapes are still shared — the point is that the set of names is open,
14
- * not that each platform reinvents the envelope.
15
- */
16
- type BaseEvent<TType extends string = KnownEventType> = {
6
+ type BaseEvent<TType extends string = string> = {
17
7
  type: TType;
18
8
  timestamp?: number;
19
9
  end_timestamp?: number;
@@ -33,30 +23,6 @@ type UserIdentifiers = {
33
23
  organization: string;
34
24
  properties: Record<string, unknown>;
35
25
  };
36
- type DomEventAttributes = {
37
- dom_event_type: string;
38
- dom_event_coordinates: {
39
- clientX: number;
40
- clientY: number;
41
- };
42
- dom_event_target: {
43
- tagName: string;
44
- id: string;
45
- className: string;
46
- text: string;
47
- role: string;
48
- accessibleName: string;
49
- ariaLabel: string;
50
- title: string;
51
- alt: string;
52
- placeholder: string;
53
- name: string;
54
- inputType: string;
55
- href: string;
56
- };
57
- dom_event_selector: string;
58
- dom_event_key_code: string;
59
- };
60
26
  type NetworkEventAttributes = {
61
27
  type: "HTTP";
62
28
  resource_name: string;
@@ -119,31 +85,6 @@ type LogEventAttributes = {
119
85
  message: string;
120
86
  level: string;
121
87
  } & Record<string, unknown>;
122
- type PageLoadEventAttributes = {
123
- page_url: string;
124
- page_resources: {
125
- count: number;
126
- totalSize: number;
127
- totalDuration: number;
128
- byType: {
129
- [key: string]: {
130
- count: number;
131
- size: number;
132
- duration: number;
133
- };
134
- };
135
- };
136
- page_referrer: string;
137
- page_load_time: number;
138
- };
139
- type NavigationEventAttributes = {
140
- page_url: string;
141
- from_url?: string;
142
- metadata?: Record<string, unknown>;
143
- duration_ms: number;
144
- start_timestamp: number;
145
- end_timestamp: number;
146
- };
147
88
  type UserDefinedEventAttributes = {
148
89
  custom_event_name: string;
149
90
  custom_event_attributes?: Record<string, unknown>;
@@ -154,44 +95,9 @@ type PerformanceEventAttributes = {
154
95
  performance_metric_id: string;
155
96
  performance_metric_navigation_type: string;
156
97
  };
157
- type ReplayEventAttributes = {
158
- /**
159
- * Groundcover session replay payload.
160
- *
161
- * NOTE: This key is intentionally prefixed to avoid collisions with customer attributes.
162
- */
163
- _gc_replay_data: {
164
- events: string[];
165
- };
166
- /**
167
- * Indicates this batch starts with a full DOM snapshot.
168
- * Full snapshots are taken at regular intervals to allow seeking directly to any point.
169
- * Queryable for filtering/indexing purposes.
170
- */
171
- replay_is_full_snapshot?: boolean;
172
- /**
173
- * Timestamp when the full snapshot was taken (if replay_is_full_snapshot is true).
174
- */
175
- replay_full_snapshot_timestamp?: number;
176
- };
177
98
 
178
- type Event$1<T extends string, A> = Omit<BaseEvent<T>, "attributes"> & {
179
- type: T;
180
- attributes: A;
181
- };
182
- type EventTypes$1 = {
183
- "dom.event": Event$1<"dom.event", DomEventAttributes>;
184
- exception: Event$1<"exception", ErrorEventAttributes>;
185
- network: Event$1<"network", NetworkEventAttributes>;
186
- log: Event$1<"log", LogEventAttributes>;
187
- pageload: Event$1<"pageload", PageLoadEventAttributes>;
188
- navigation: Event$1<"navigation", NavigationEventAttributes>;
189
- custom: Event$1<"custom", UserDefinedEventAttributes>;
190
- performance: Event$1<"performance", PerformanceEventAttributes>;
191
- replay: Event$1<"replay", ReplayEventAttributes>;
192
- };
193
99
  type PrivacyLevel = "mask-sensitive" | "mask-all" | "allow";
194
- /** The non-replay event surface a redactor field belongs to. */
100
+ /** The event surface a redactor field belongs to. */
195
101
  type RedactKind = "request-body" | "response-body" | "query" | "header" | "log" | "error";
196
102
  interface RedactField {
197
103
  /** Immediate key of the value; `""` for whole-string fields (log/error message). */
@@ -233,23 +139,19 @@ interface PrivacyOptions$1 {
233
139
  /** Extra case-insensitive key substrings treated as sensitive, merged with the built-in patterns. */
234
140
  sensitiveKeys?: string[];
235
141
  /**
236
- * Per-field custom redaction hook for non-replay events. Called on each leaf
142
+ * Per-field custom redaction hook for captured events. Called on each leaf
237
143
  * value during the redaction walk with the original typed value; see
238
144
  * {@link Redactor}. For arbitrary whole-event changes use `enrichEvent`.
239
145
  */
240
146
  redact?: Redactor;
241
- /**
242
- * Session-recording masking — replay is a platform feature (rrweb on the
243
- * browser), so its masking surface is typed by the platform package: the
244
- * browser SDK narrows this to `{ maskTextFn?, maskInputFn? }` over
245
- * HTMLElement (see the browser package's `config/types.ts`). Core never
246
- * reads it — it is resolved platform-side at record() time.
247
- */
248
- replay?: unknown;
249
147
  }
250
148
  /** Distributed-tracing header propagation for outgoing network requests. */
251
149
  interface TracingOptions {
252
- /** Request URLs (prefix match) that receive injected tracing headers. */
150
+ /**
151
+ * Request URLs that receive injected tracing headers: whole-URL matches where
152
+ * only `*` is a wildcard. Which strings a pattern is matched against is the
153
+ * platform's (the browser adds a same-origin request's path).
154
+ */
253
155
  propagationUrls?: string[];
254
156
  /** Inbound header names to read/propagate onto traced requests. */
255
157
  propagationHeaders?: string[];
@@ -269,25 +171,23 @@ interface TransportOptions {
269
171
  batchSize?: number;
270
172
  /** Max ms a batch waits before flushing regardless of size (default 10000). */
271
173
  batchTimeout?: number;
272
- /** Gzip-compress outgoing batches; offloaded to the Web Worker when available (default true). */
174
+ /** Gzip-compress outgoing batches; offloaded to the platform's async encoder when it has one (default true). */
273
175
  compression?: boolean;
274
176
  }
275
- interface SDKOptions$1<TEvent extends BaseEvent<string> = EventTypes$1[keyof EventTypes$1]> {
177
+ interface SDKOptions$1<TEvent extends BaseEvent<string> = BaseEvent<string>> {
276
178
  /**
277
179
  * Which signal listeners to enable, by name. Empty array = all. The NAMES
278
180
  * are platform-defined (each platform ships its own listener set) — the
279
- * platform package narrows this to its literal union (see the browser
280
- * package's `config/types.ts`).
181
+ * platform package narrows this to its literal union.
281
182
  */
282
183
  enabledEvents: string[];
283
- eventSampleRate: number;
284
184
  sessionSampleRate: number;
285
185
  debug: boolean;
286
186
  excludedUrls?: Array<string | RegExp>;
287
- beforeSend?: (event: TEvent) => boolean;
288
- enrichEvent?: (event: TEvent) => TEvent;
187
+ beforeSend?(event: TEvent): boolean;
188
+ enrichEvent?(event: TEvent): TEvent;
289
189
  /**
290
- * Unified privacy / data-masking config driving replay + non-replay masking.
190
+ * Unified privacy / data-masking config for every captured surface.
291
191
  * ON by default (`level: 'mask-sensitive'`); see {@link PrivacyOptions}.
292
192
  */
293
193
  privacy?: PrivacyOptions$1;
@@ -296,51 +196,16 @@ interface SDKOptions$1<TEvent extends BaseEvent<string> = EventTypes$1[keyof Eve
296
196
  /** Batching & delivery of outgoing events; see {@link TransportOptions}. */
297
197
  transport?: TransportOptions;
298
198
  /**
299
- * Session-recording controls — a platform feature slot core never reads.
300
- * The platform package types it (the browser SDK narrows this to its
301
- * rrweb `ReplayOptions`; platforms without recording ignore it).
302
- */
303
- replay?: unknown;
304
- /**
305
- * Target maximum wall-clock duration of a session, in milliseconds.
306
- *
307
- * Enforced LAZILY, on activity — not by a background timer. Once the cap has
308
- * elapsed, the next user/business event (click, navigation, log, custom,
309
- * network, exception, …) flushes buffered events under the current session
310
- * id, then mints a fresh session id and restarts replay recording if it was
311
- * active.
312
- *
313
- * Because it is activity-gated, this is NOT a hard upper bound: a session
314
- * only rotates when the next qualifying event arrives. An idle or
315
- * backgrounded tab that produces no such events — including one that is only
316
- * emitting session-replay heartbeats, which never trigger rotation on their
317
- * own — keeps the same session id past the cap until activity resumes. This
318
- * is deliberate: it avoids minting "phantom" sessions for dormant tabs. (An
319
- * idle tab with replay on is ultimately bounded by the 30-minute user-idle
320
- * pause — recording stops when no user presence is detected — not by this
321
- * cap.)
199
+ * Target maximum wall-clock duration of a session, in ms. Enforced LAZILY on activity, so NOT
200
+ * a hard bound — an idle session keeps its id past the cap, which deliberately avoids minting
201
+ * phantom sessions. Also bounded by a 30-minute inactivity gap, counting raw input as
202
+ * presence so passive reading does not end a session.
322
203
  *
323
- * Sessions are also bounded by a 30-minute inactivity gap, enforced the same
324
- * lazy way: when a user-interaction event (click, navigation, pageload,
325
- * custom — not background network/log/performance traffic) arrives after 30+
326
- * minutes without one, the session rotates first and replay recording
327
- * restarts for the returning user. Raw user input (scroll, pointer, key,
328
- * touch) also counts as presence even when it produces no SDK event, so
329
- * passive engagement — reading, watching — doesn't end the session. The
330
- * same gap check runs at init, so a reload after a long break also starts a
331
- * fresh session.
332
- *
333
- * The flush is best-effort and the rotation always proceeds — it does not
334
- * wait for or depend on successful delivery, so if that network request
335
- * fails the batch may be lost while the new session id still takes effect.
336
- *
337
- * Defaults to 4 hours when omitted; must be between 1 minute and 8 hours.
338
- * Values outside that range or otherwise invalid fall back to the 4-hour
339
- * default with a `console.warn`.
204
+ * Defaults to 4 hours; must be 1 minute to 8 hours, else falls back with a warning.
340
205
  */
341
206
  sessionMaxDuration?: number;
342
207
  }
343
- interface SDKConfigInput$1<TEvent extends BaseEvent<string> = EventTypes$1[keyof EventTypes$1]> {
208
+ interface SDKConfigInput$1<TEvent extends BaseEvent<string> = BaseEvent<string>> {
344
209
  apiKey: string;
345
210
  cluster: string;
346
211
  environment: string;
@@ -353,6 +218,76 @@ interface SDKConfigInput$1<TEvent extends BaseEvent<string> = EventTypes$1[keyof
353
218
  sessionId?: string;
354
219
  }
355
220
 
221
+ type DomEventAttributes = {
222
+ dom_event_type: string;
223
+ dom_event_coordinates: {
224
+ clientX: number;
225
+ clientY: number;
226
+ };
227
+ dom_event_target: {
228
+ tagName: string;
229
+ id: string;
230
+ className: string;
231
+ text: string;
232
+ role: string;
233
+ accessibleName: string;
234
+ ariaLabel: string;
235
+ title: string;
236
+ alt: string;
237
+ placeholder: string;
238
+ name: string;
239
+ inputType: string;
240
+ href: string;
241
+ };
242
+ dom_event_selector: string;
243
+ dom_event_key_code: string;
244
+ };
245
+ type PageLoadEventAttributes = {
246
+ page_url: string;
247
+ page_resources: {
248
+ count: number;
249
+ totalSize: number;
250
+ totalDuration: number;
251
+ byType: {
252
+ [key: string]: {
253
+ count: number;
254
+ size: number;
255
+ duration: number;
256
+ };
257
+ };
258
+ };
259
+ page_referrer: string;
260
+ page_load_time: number;
261
+ };
262
+ type NavigationEventAttributes = {
263
+ page_url: string;
264
+ from_url?: string;
265
+ metadata?: Record<string, unknown>;
266
+ duration_ms: number;
267
+ start_timestamp: number;
268
+ end_timestamp: number;
269
+ };
270
+ type ReplayEventAttributes = {
271
+ /**
272
+ * Groundcover session replay payload.
273
+ *
274
+ * NOTE: This key is intentionally prefixed to avoid collisions with customer attributes.
275
+ */
276
+ _gc_replay_data: {
277
+ events: string[];
278
+ };
279
+ /**
280
+ * Indicates this batch starts with a full DOM snapshot.
281
+ * Full snapshots are taken at regular intervals to allow seeking directly to any point.
282
+ * Queryable for filtering/indexing purposes.
283
+ */
284
+ replay_is_full_snapshot?: boolean;
285
+ /**
286
+ * Timestamp when the full snapshot was taken (if replay_is_full_snapshot is true).
287
+ */
288
+ replay_full_snapshot_timestamp?: number;
289
+ };
290
+
356
291
  /**
357
292
  * The view an event was captured on. Browser-owned: core has no notion of a
358
293
  * "current view" — it merges whatever the platform's `enrichAttributes`
@@ -412,13 +347,13 @@ interface ReplayMaskingOptions {
412
347
  /** rrweb `maskInputFn` pass-through. */
413
348
  maskInputFn?: (text: string, el: HTMLElement) => string;
414
349
  }
415
- interface PrivacyOptions extends Omit<PrivacyOptions$1, "replay"> {
350
+ interface PrivacyOptions extends PrivacyOptions$1 {
416
351
  /** CSS selectors whose text/inputs are always masked (replay + DOM), regardless of `level` except `'allow'`. */
417
352
  maskSelectors?: string[];
418
353
  /** Session-recording (rrweb replay) masking — the only place replay can be masked. */
419
354
  replay?: ReplayMaskingOptions;
420
355
  }
421
- interface SDKOptions extends Omit<SDKOptions$1, "privacy" | "replay" | "enabledEvents" | "beforeSend" | "enrichEvent"> {
356
+ interface SDKOptions extends Omit<SDKOptions$1, "privacy" | "enabledEvents" | "beforeSend" | "enrichEvent"> {
422
357
  /**
423
358
  * Inspect each event before it is queued; return false to drop it. Typed
424
359
  * over the BROWSER event map, so `attributes.location` is visible here.
@@ -442,7 +377,7 @@ interface SDKOptions extends Omit<SDKOptions$1, "privacy" | "replay" | "enabledE
442
377
  interface SDKConfigInput extends Omit<SDKConfigInput$1, "options"> {
443
378
  options?: Partial<SDKOptions>;
444
379
  }
445
- type SDKConfigUpdate = Partial<Omit<SDKConfigInput, "sessionId" | "user">> & {
380
+ type SDKConfigUpdate = Partial<Omit<SDKConfigInput, "appId" | "sessionId" | "user">> & {
446
381
  user?: SDKConfigInput["user"] | null;
447
382
  };
448
383
 
@@ -470,7 +405,6 @@ declare class SessionManager {
470
405
  setSessionId(newSessionId?: string): Promise<void>;
471
406
  startReplayRecording(): void;
472
407
  stopReplayRecording(): void;
473
- handoffForReinit(): void;
474
408
  destroy(): void;
475
409
  }
476
410
 
@@ -491,11 +425,11 @@ declare global {
491
425
  groundcover?: typeof groundcover;
492
426
  }
493
427
  }
494
- declare function init(params?: {
428
+ declare function init(params: {
495
429
  cluster?: string;
496
430
  environment?: string;
497
431
  namespace?: string;
498
- appId?: string;
432
+ appId: string;
499
433
  releaseId?: string;
500
434
  user?: Partial<UserIdentifiers>;
501
435
  dsn?: string;