@logspace/sdk 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logspace/sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "LogSpace JavaScript SDK for session recording and logging",
5
5
  "type": "module",
6
6
  "main": "./logspace.umd.js",
@@ -19,7 +19,6 @@
19
19
  }
20
20
  },
21
21
  "files": [
22
- "README.md",
23
22
  "logspace.esm.js",
24
23
  "logspace.esm.js.map",
25
24
  "logspace.umd.js",
@@ -38,5 +37,8 @@
38
37
  "monitoring"
39
38
  ],
40
39
  "author": "LogSpace",
41
- "license": "MIT"
40
+ "license": "MIT",
41
+ "scripts": {
42
+ "preinstall": "npx only-allow bun && bun --version | grep -q '^1.2.21$' || (echo 'Error: Bun version 1.2.21 is required' && exit 1)"
43
+ }
42
44
  }
package/shared/types.d.ts CHANGED
@@ -235,6 +235,14 @@ export interface RecordingSettings {
235
235
  logLevels: LogSeverity[];
236
236
  }
237
237
  export declare const DEFAULT_SETTINGS: RecordingSettings;
238
+ export declare const API_TO_SETTINGS_KEY_MAP: Record<string, keyof RecordingSettings>;
239
+ export interface RemoteSettingsState {
240
+ disabledKeys: Set<keyof RecordingSettings>;
241
+ lastFetched: number | null;
242
+ loading: boolean;
243
+ error: string | null;
244
+ }
245
+ export declare function parseApiSettingValue(apiKey: string, value: string, valueType: string): any;
238
246
  export interface SessionStats {
239
247
  logCount: number;
240
248
  networkLogCount: number;
@@ -300,6 +308,95 @@ export declare enum MessageType {
300
308
  CSP_DETECTED = "CSP_DETECTED",// CSP blocked script injection
301
309
  FETCH_ASSIGNED_LOGS = "FETCH_ASSIGNED_LOGS"
302
310
  }
311
+ /**
312
+ * Internal message types used for communication between extension components
313
+ * These are not part of the public MessageType enum to avoid bloating it
314
+ *
315
+ * MESSAGE FLOW DOCUMENTATION:
316
+ *
317
+ * Background Script <-> Content Script:
318
+ * - REGISTER_TAB: Background registers a tab for recording
319
+ * - UNREGISTER_TAB: Background unregisters a tab
320
+ * - SHOW_COUNTDOWN: Background asks content to show countdown overlay
321
+ * - SELECT_AREA: Background asks content to show area selector
322
+ * - AREA_SELECTED: Content informs background of selected area
323
+ * - NETWORK_HEADERS_*: Background forwards network headers to content
324
+ * - show-webcam-overlay / hide-webcam-overlay: Webcam control
325
+ * - SAVE_ANNOTATION / SAVE_DRAWING_ANNOTATION: User annotations
326
+ * - STORAGE_SIZE_UPDATE: Background informs content of storage usage
327
+ * - SHOW_SAVE_MODAL / UPDATE_SAVE_MODAL_VIDEO: Save dialog control
328
+ *
329
+ * Background Script <-> Offscreen Document:
330
+ * - start-video-recording / stop-video-recording: Video recording control
331
+ * - start-display-media-recording: Screen capture control
332
+ * - test-microphone-permission / test-webcam-permission: Permission tests
333
+ * - start-microphone-visualization / stop-microphone-visualization: Audio levels
334
+ * - save-video: Offscreen sends video data to background
335
+ * - video-chunk-size: Offscreen reports chunk sizes
336
+ * - offscreen-log: Offscreen forwards logs to background
337
+ * - display-media-selected: User selected screen/window
338
+ * - microphone-audio-level: Audio visualization data
339
+ *
340
+ * Background Script <-> Popup:
341
+ * - CLOSE_POPUP: Background requests popup to close
342
+ * - RECORDING_STARTED / RECORDING_ERROR: Recording state notifications
343
+ * - All MessageType and AuthMessageType enums
344
+ */
345
+ export declare enum InternalMessageType {
346
+ PING = "ping",
347
+ SHOW_COUNTDOWN = "SHOW_COUNTDOWN",
348
+ COUNTDOWN_COMPLETE = "COUNTDOWN_COMPLETE",
349
+ SELECT_AREA = "SELECT_AREA",
350
+ AREA_SELECTED = "AREA_SELECTED",
351
+ NETWORK_HEADERS_REQUEST = "NETWORK_HEADERS_REQUEST",
352
+ NETWORK_HEADERS_RESPONSE = "NETWORK_HEADERS_RESPONSE",
353
+ SHOW_WEBCAM_OVERLAY = "show-webcam-overlay",
354
+ HIDE_WEBCAM_OVERLAY = "hide-webcam-overlay",
355
+ SAVE_ANNOTATION = "SAVE_ANNOTATION",
356
+ SAVE_DRAWING_ANNOTATION = "SAVE_DRAWING_ANNOTATION",
357
+ STORAGE_SIZE_UPDATE = "STORAGE_SIZE_UPDATE",
358
+ SHOW_SAVE_MODAL = "SHOW_SAVE_MODAL",
359
+ UPDATE_SAVE_MODAL_VIDEO = "UPDATE_SAVE_MODAL_VIDEO",
360
+ START_VIDEO_RECORDING = "start-video-recording",
361
+ STOP_VIDEO_RECORDING = "stop-video-recording",
362
+ START_DISPLAY_MEDIA_RECORDING = "start-display-media-recording",
363
+ TEST_MICROPHONE_PERMISSION = "test-microphone-permission",
364
+ TEST_WEBCAM_PERMISSION = "test-webcam-permission",
365
+ START_MICROPHONE_VISUALIZATION = "start-microphone-visualization",
366
+ STOP_MICROPHONE_VISUALIZATION = "stop-microphone-visualization",
367
+ SAVE_VIDEO = "save-video",
368
+ VIDEO_CHUNK_SIZE = "video-chunk-size",
369
+ OFFSCREEN_LOG = "offscreen-log",
370
+ DISPLAY_MEDIA_SELECTED = "display-media-selected",
371
+ MICROPHONE_AUDIO_LEVEL = "microphone-audio-level",
372
+ CLOSE_POPUP = "CLOSE_POPUP",
373
+ RECORDING_STARTED = "RECORDING_STARTED",
374
+ RECORDING_ERROR = "RECORDING_ERROR",
375
+ LOGIN_SUCCESS = "LOGIN_SUCCESS",
376
+ LOGIN_FAILED = "LOGIN_FAILED",
377
+ STATE_UPDATE = "STATE_UPDATE",
378
+ LOG_UPDATE = "LOG_UPDATE",
379
+ SAVE_RECORDING_METADATA = "SAVE_RECORDING_METADATA",
380
+ GET_SESSION_LOGS = "GET_SESSION_LOGS",
381
+ GET_UPLOAD_FORM_DATA = "GET_UPLOAD_FORM_DATA",
382
+ SEARCH_PROJECTS = "SEARCH_PROJECTS",
383
+ SEARCH_ENVIRONMENTS = "SEARCH_ENVIRONMENTS",
384
+ SEARCH_USERS = "SEARCH_USERS",
385
+ UPLOAD_RECORDING = "UPLOAD_RECORDING",
386
+ CONNECT = "CONNECT"
387
+ }
388
+ /**
389
+ * Validate that a message has a valid type
390
+ * @param message The message to validate
391
+ * @returns true if the message has a valid type property
392
+ */
393
+ export declare function isValidMessage(message: unknown): boolean;
394
+ /**
395
+ * Check if a message type is a known type
396
+ * @param type The message type to check
397
+ * @returns true if the type is in MessageType, AuthMessageType, or InternalMessageType
398
+ */
399
+ export declare function isKnownMessageType(type: string): boolean;
303
400
  export interface Message {
304
401
  type: MessageType;
305
402
  payload?: any;
@@ -352,5 +449,6 @@ export interface AuthPollingState {
352
449
  export declare enum AuthMessageType {
353
450
  LOGIN_START = "LOGIN_START",
354
451
  LOGOUT = "LOGOUT",
355
- VALIDATE_AUTH = "VALIDATE_AUTH"
452
+ VALIDATE_AUTH = "VALIDATE_AUTH",
453
+ SYNC_SETTINGS = "SYNC_SETTINGS"
356
454
  }
package/README.md DELETED
@@ -1,269 +0,0 @@
1
- # @logspace/sdk
2
-
3
- A lightweight JavaScript SDK for session recording and debugging. Capture user sessions with DOM replay, console logs, network requests, errors, and more.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @logspace/sdk
9
- ```
10
-
11
- ```bash
12
- yarn add @logspace/sdk
13
- ```
14
-
15
- ```bash
16
- pnpm add @logspace/sdk
17
- ```
18
-
19
- ## Quick Start
20
-
21
- ```javascript
22
- import LogSpace from '@logspace/sdk';
23
-
24
- // Initialize the SDK
25
- LogSpace.init({
26
- serverUrl: 'https://your-logspace-server.com',
27
- apiKey: 'project_id:environment_id',
28
- });
29
-
30
- // Start recording
31
- LogSpace.startSession();
32
-
33
- // Identify the user (optional)
34
- LogSpace.identify('user-123', {
35
- email: 'user@example.com',
36
- plan: 'pro',
37
- });
38
-
39
- // Track custom events
40
- LogSpace.track('button_clicked', { buttonId: 'submit' });
41
-
42
- // Add breadcrumbs for debugging
43
- LogSpace.breadcrumb('User opened settings', 'navigation');
44
-
45
- // Stop recording and send to server
46
- await LogSpace.stopSession();
47
- ```
48
-
49
- ## Features
50
-
51
- - 🎬 **DOM Recording** - Full visual replay using rrweb
52
- - 📝 **Console Logs** - Capture all console output (log, warn, error, debug)
53
- - 🌐 **Network Requests** - Track XHR and Fetch calls with timing
54
- - ❌ **Error Tracking** - Catch JavaScript errors and unhandled rejections
55
- - 🖱️ **User Interactions** - Record clicks, inputs, and scrolls
56
- - 📊 **Performance Metrics** - Core Web Vitals and resource timing
57
- - 🔌 **WebSocket & SSE** - Monitor real-time connections
58
- - 💾 **Storage Changes** - Track localStorage/sessionStorage modifications
59
- - 🔒 **Privacy First** - Built-in PII masking and data sanitization
60
-
61
- ## Configuration
62
-
63
- ```javascript
64
- LogSpace.init({
65
- // Server configuration
66
- serverUrl: 'https://your-server.com',
67
- apiKey: 'project_id:environment_id',
68
-
69
- // What to capture
70
- capture: {
71
- rrweb: true, // DOM recording
72
- console: true, // Console logs
73
- network: true, // Network requests
74
- errors: true, // JavaScript errors
75
- interactions: true, // User interactions
76
- performance: true, // Performance metrics
77
- websocket: true, // WebSocket connections
78
- sse: true, // Server-Sent Events
79
- storage: true, // localStorage/sessionStorage
80
- resources: true, // Resource loading
81
- spaNavigation: true, // SPA route changes
82
- },
83
-
84
- // rrweb settings
85
- rrweb: {
86
- maskAllInputs: false, // Mask all input values
87
- maskTextSelector: null, // CSS selector for text masking
88
- blockSelector: null, // CSS selector to block elements
89
- recordCanvas: false, // Record canvas content
90
- checkoutEveryNth: 200, // Full snapshot interval
91
- },
92
-
93
- // Privacy settings
94
- privacy: {
95
- maskSensitiveData: true, // Auto-mask PII patterns
96
- maskSelectors: [], // CSS selectors to mask
97
- excludeUrls: [], // URL patterns to exclude
98
- blockNetworkBodies: [], // Block request/response bodies
99
- redactHeaders: [], // Headers to redact
100
- logLevels: ['log', 'info', 'warn', 'error', 'debug'],
101
- },
102
-
103
- // Session limits
104
- limits: {
105
- maxLogs: 10000, // Max logs per session
106
- maxSize: 10 * 1024 * 1024, // Max session size (10MB)
107
- maxDuration: 300, // Max duration in seconds (5 min)
108
- idleTimeout: 30, // Idle timeout in seconds
109
- rateLimit: 100, // Max logs per second
110
- deduplicate: true, // Deduplicate consecutive logs
111
- },
112
-
113
- // Auto-end behavior
114
- autoEnd: {
115
- continueOnRefresh: true, // Continue session on page refresh
116
- onIdle: true, // End on idle timeout
117
- onLimitReached: true, // End when limits reached
118
- },
119
-
120
- // Sampling mode (only record on errors)
121
- sampling: {
122
- enabled: false,
123
- bufferBefore: 15, // Seconds before trigger
124
- recordAfter: 15, // Seconds after trigger
125
- triggers: {
126
- onError: true,
127
- onConsoleError: true,
128
- onNetworkStatus: [500, 502, 503, 504],
129
- },
130
- },
131
-
132
- // Lifecycle hooks
133
- hooks: {
134
- onAction: (log, session) => {},
135
- beforeSend: (logs) => logs,
136
- onSessionStart: (session) => {},
137
- onSessionEnd: (session, logs) => {},
138
- onLimitReached: (reason) => {},
139
- onSamplingTrigger: (trigger, log) => {},
140
- onError: (error) => {},
141
- },
142
-
143
- // Additional options
144
- headers: {}, // Custom API headers
145
- debug: false, // Enable debug logging
146
- });
147
- ```
148
-
149
- ## API Reference
150
-
151
- ### Initialization
152
-
153
- #### `LogSpace.init(config)`
154
-
155
- Initialize the SDK with configuration options.
156
-
157
- ### Session Control
158
-
159
- #### `LogSpace.startSession(metadata?)`
160
-
161
- Start a new recording session with optional metadata.
162
-
163
- ```javascript
164
- LogSpace.startSession({ page: 'checkout', variant: 'A' });
165
- ```
166
-
167
- #### `LogSpace.stopSession()`
168
-
169
- Stop recording and send the session to the server.
170
-
171
- ```javascript
172
- await LogSpace.stopSession();
173
- ```
174
-
175
- #### `LogSpace.pauseRecording()`
176
-
177
- Temporarily pause recording.
178
-
179
- #### `LogSpace.resumeRecording()`
180
-
181
- Resume a paused recording.
182
-
183
- ### User Identification
184
-
185
- #### `LogSpace.identify(userId, traits?)`
186
-
187
- Associate the session with a user.
188
-
189
- ```javascript
190
- LogSpace.identify('user-123', {
191
- email: 'user@example.com',
192
- name: 'John Doe',
193
- plan: 'enterprise',
194
- });
195
- ```
196
-
197
- ### Custom Events
198
-
199
- #### `LogSpace.track(event, properties?)`
200
-
201
- Track a custom event.
202
-
203
- ```javascript
204
- LogSpace.track('purchase_completed', {
205
- orderId: 'ORD-123',
206
- amount: 99.99,
207
- });
208
- ```
209
-
210
- #### `LogSpace.breadcrumb(message, category?)`
211
-
212
- Add a breadcrumb for debugging context.
213
-
214
- ```javascript
215
- LogSpace.breadcrumb('User clicked add to cart', 'action');
216
- ```
217
-
218
- ### Sampling Mode
219
-
220
- #### `LogSpace.trigger(reason?)`
221
-
222
- Manually trigger session capture in sampling mode.
223
-
224
- ```javascript
225
- LogSpace.trigger('user_reported_issue');
226
- ```
227
-
228
- ### Session Data
229
-
230
- #### `LogSpace.getSession()`
231
-
232
- Get the current session object.
233
-
234
- #### `LogSpace.getSessionLogs()`
235
-
236
- Get all logs for the current session.
237
-
238
- #### `LogSpace.getSessionData()`
239
-
240
- Get full session payload for local export.
241
-
242
- #### `LogSpace.getRRWebEvents()`
243
-
244
- Get rrweb events for the current session.
245
-
246
- ### Cleanup
247
-
248
- #### `LogSpace.destroy()`
249
-
250
- Destroy the SDK and clean up resources.
251
-
252
- ## Usage Formats
253
-
254
- The SDK supports multiple module formats:
255
-
256
- - **ESM**: `import LogSpace from '@logspace/sdk'`
257
- - **CommonJS**: `const LogSpace = require('@logspace/sdk')`
258
- - **IIFE**: `<script src="logspace.iife.js"></script>` (exposes `window.LogSpace`)
259
-
260
- ## Browser Support
261
-
262
- - Chrome 60+
263
- - Firefox 55+
264
- - Safari 12+
265
- - Edge 79+
266
-
267
- ## License
268
-
269
- MIT