@spotify-confidence/session-recording 0.0.0 → 0.17.2

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.
@@ -0,0 +1,93 @@
1
+ //#region ../csr-common/src/events.d.ts
2
+ type ConsoleLogLevel = "log" | "warn" | "error" | "debug" | "info";
3
+ //#endregion
4
+ //#region ../csr-common/src/uploader/client-context.d.ts
5
+ /**
6
+ * JSON-shaped values accepted in a Context — matches `google.protobuf.Struct`.
7
+ */
8
+ type ContextValue = string | number | boolean | null | ContextValue[] | {
9
+ [key: string]: ContextValue;
10
+ };
11
+ /**
12
+ * Browser-environment metadata captured at session init. Sent verbatim in the
13
+ * `context` field of the InitSession request.
14
+ */
15
+ type UserAgentContext = {
16
+ userAgent?: string; /** Coarse OS family — `windows`, `macos`, `ios`, `android`, `linux`, or `unknown`. */
17
+ os?: string; /** Coarse browser family — `chrome`, `firefox`, `safari`, `edge`, or `unknown`. */
18
+ browser?: string; /** Browser major version. */
19
+ browserVersion?: string;
20
+ mobile?: boolean; /** BCP-47 language tag (e.g. `en-US`). */
21
+ languageCode?: string; /** IANA time zone (e.g. `Europe/Stockholm`). */
22
+ timeZone?: string; /** Viewport in CSS pixels. */
23
+ viewportWidth?: number;
24
+ viewportHeight?: number; /** Physical screen in CSS pixels. */
25
+ screenWidth?: number;
26
+ screenHeight?: number;
27
+ devicePixelRatio?: number; /** Initial document URI — without query/hash to avoid leaking PII. */
28
+ uri?: string;
29
+ referrer?: string;
30
+ };
31
+ interface ClientContext {
32
+ userAgent?: UserAgentContext;
33
+ [key: string]: ContextValue | undefined;
34
+ }
35
+ //#endregion
36
+ //#region src/index.d.ts
37
+ interface InitSessionRecorderOptions {
38
+ /** Per-tenant secret. */
39
+ clientSecret: string;
40
+ /** End-user identifier (visitor / device id). */
41
+ targetingKey?: string;
42
+ /** CSS selectors whose text content should be masked. */
43
+ maskSelectors?: string[];
44
+ /** CSS selectors whose subtrees should be blocked (replaced with a placeholder, never serialized). */
45
+ blockSelectors?: string[];
46
+ /** Mask values of every `<input>` / `<textarea>` / `contenteditable`. Defaults to `true`. */
47
+ maskInputs?: boolean;
48
+ /** Capture browser console output. Defaults to `false`. Pass `true` for all levels or `{ levels: [...] }` for specific ones. */
49
+ captureConsoleLogs?: boolean | {
50
+ levels: ConsoleLogLevel[];
51
+ };
52
+ /** Capture fetch/XHR metadata (method, URL, status, duration). Defaults to `false`. */
53
+ captureNetworkRequests?: boolean;
54
+ /** Capture client-side route changes (pathname only). Defaults to `true`. */
55
+ captureRouteChanges?: boolean;
56
+ /** Backend base URL. Defaults to the Confidence production endpoint. */
57
+ apiUrl?: string;
58
+ /** WebSocket ingest URL. Defaults to the Confidence production endpoint. */
59
+ websocketUrl?: string;
60
+ /** Application version or commit hash, e.g. "1.2.3" or "abc1234". Stored on the recording for filtering. */
61
+ appVersion?: string;
62
+ /** Custom dimensions merged into the session context alongside auto-collected browser metadata. */
63
+ context?: ClientContext;
64
+ /**
65
+ * `'automatic'` (default) — starts recording as soon as the session is established.
66
+ * `'manual'` — does nothing until `start()` is called, bypassing sampling and targeting rules.
67
+ */
68
+ mode?: "automatic" | "manual";
69
+ /** Verbose tracer for debugging — called with one-line lifecycle/transport messages. */
70
+ debugLogger?: (msg: string) => void;
71
+ }
72
+ interface SessionRecorder {
73
+ /** Start recording. In `automatic` mode this is a no-op. In `manual` mode it establishes a session and begins recording. */
74
+ start(): void;
75
+ /** Stop recording permanently. Idempotent. */
76
+ stop(): void;
77
+ /** Attach a custom tag to this recording. Tags with the same key accumulate values. Omit value for a valueless marker. */
78
+ tag(key: string, value?: string): void;
79
+ /** Record a numeric measurement. Measurements with the same key are summed. Omit value to count occurrences (each call adds 1). */
80
+ measure(key: string, value?: number): void;
81
+ /** Whether the recorder is actively capturing events. */
82
+ readonly isRecording: boolean;
83
+ }
84
+ /**
85
+ * Create a session recorder. In `automatic` mode (default) recording begins
86
+ * as soon as a session is established. In `manual` mode nothing happens
87
+ * until {@link SessionRecorder.start} is called.
88
+ *
89
+ * Always returns a {@link SessionRecorder} — safe to call, never throws.
90
+ */
91
+ declare function initSessionRecorder(options: InitSessionRecorderOptions): SessionRecorder;
92
+ //#endregion
93
+ export { InitSessionRecorderOptions, SessionRecorder, initSessionRecorder };
@@ -0,0 +1,93 @@
1
+ //#region ../csr-common/src/events.d.ts
2
+ type ConsoleLogLevel = "log" | "warn" | "error" | "debug" | "info";
3
+ //#endregion
4
+ //#region ../csr-common/src/uploader/client-context.d.ts
5
+ /**
6
+ * JSON-shaped values accepted in a Context — matches `google.protobuf.Struct`.
7
+ */
8
+ type ContextValue = string | number | boolean | null | ContextValue[] | {
9
+ [key: string]: ContextValue;
10
+ };
11
+ /**
12
+ * Browser-environment metadata captured at session init. Sent verbatim in the
13
+ * `context` field of the InitSession request.
14
+ */
15
+ type UserAgentContext = {
16
+ userAgent?: string; /** Coarse OS family — `windows`, `macos`, `ios`, `android`, `linux`, or `unknown`. */
17
+ os?: string; /** Coarse browser family — `chrome`, `firefox`, `safari`, `edge`, or `unknown`. */
18
+ browser?: string; /** Browser major version. */
19
+ browserVersion?: string;
20
+ mobile?: boolean; /** BCP-47 language tag (e.g. `en-US`). */
21
+ languageCode?: string; /** IANA time zone (e.g. `Europe/Stockholm`). */
22
+ timeZone?: string; /** Viewport in CSS pixels. */
23
+ viewportWidth?: number;
24
+ viewportHeight?: number; /** Physical screen in CSS pixels. */
25
+ screenWidth?: number;
26
+ screenHeight?: number;
27
+ devicePixelRatio?: number; /** Initial document URI — without query/hash to avoid leaking PII. */
28
+ uri?: string;
29
+ referrer?: string;
30
+ };
31
+ interface ClientContext {
32
+ userAgent?: UserAgentContext;
33
+ [key: string]: ContextValue | undefined;
34
+ }
35
+ //#endregion
36
+ //#region src/index.d.ts
37
+ interface InitSessionRecorderOptions {
38
+ /** Per-tenant secret. */
39
+ clientSecret: string;
40
+ /** End-user identifier (visitor / device id). */
41
+ targetingKey?: string;
42
+ /** CSS selectors whose text content should be masked. */
43
+ maskSelectors?: string[];
44
+ /** CSS selectors whose subtrees should be blocked (replaced with a placeholder, never serialized). */
45
+ blockSelectors?: string[];
46
+ /** Mask values of every `<input>` / `<textarea>` / `contenteditable`. Defaults to `true`. */
47
+ maskInputs?: boolean;
48
+ /** Capture browser console output. Defaults to `false`. Pass `true` for all levels or `{ levels: [...] }` for specific ones. */
49
+ captureConsoleLogs?: boolean | {
50
+ levels: ConsoleLogLevel[];
51
+ };
52
+ /** Capture fetch/XHR metadata (method, URL, status, duration). Defaults to `false`. */
53
+ captureNetworkRequests?: boolean;
54
+ /** Capture client-side route changes (pathname only). Defaults to `true`. */
55
+ captureRouteChanges?: boolean;
56
+ /** Backend base URL. Defaults to the Confidence production endpoint. */
57
+ apiUrl?: string;
58
+ /** WebSocket ingest URL. Defaults to the Confidence production endpoint. */
59
+ websocketUrl?: string;
60
+ /** Application version or commit hash, e.g. "1.2.3" or "abc1234". Stored on the recording for filtering. */
61
+ appVersion?: string;
62
+ /** Custom dimensions merged into the session context alongside auto-collected browser metadata. */
63
+ context?: ClientContext;
64
+ /**
65
+ * `'automatic'` (default) — starts recording as soon as the session is established.
66
+ * `'manual'` — does nothing until `start()` is called, bypassing sampling and targeting rules.
67
+ */
68
+ mode?: "automatic" | "manual";
69
+ /** Verbose tracer for debugging — called with one-line lifecycle/transport messages. */
70
+ debugLogger?: (msg: string) => void;
71
+ }
72
+ interface SessionRecorder {
73
+ /** Start recording. In `automatic` mode this is a no-op. In `manual` mode it establishes a session and begins recording. */
74
+ start(): void;
75
+ /** Stop recording permanently. Idempotent. */
76
+ stop(): void;
77
+ /** Attach a custom tag to this recording. Tags with the same key accumulate values. Omit value for a valueless marker. */
78
+ tag(key: string, value?: string): void;
79
+ /** Record a numeric measurement. Measurements with the same key are summed. Omit value to count occurrences (each call adds 1). */
80
+ measure(key: string, value?: number): void;
81
+ /** Whether the recorder is actively capturing events. */
82
+ readonly isRecording: boolean;
83
+ }
84
+ /**
85
+ * Create a session recorder. In `automatic` mode (default) recording begins
86
+ * as soon as a session is established. In `manual` mode nothing happens
87
+ * until {@link SessionRecorder.start} is called.
88
+ *
89
+ * Always returns a {@link SessionRecorder} — safe to call, never throws.
90
+ */
91
+ declare function initSessionRecorder(options: InitSessionRecorderOptions): SessionRecorder;
92
+ //#endregion
93
+ export { InitSessionRecorderOptions, SessionRecorder, initSessionRecorder };