@logspace/sdk 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +269 -0
  2. package/package.json +3 -5
package/README.md ADDED
@@ -0,0 +1,269 @@
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logspace/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "LogSpace JavaScript SDK for session recording and logging",
5
5
  "type": "module",
6
6
  "main": "./logspace.umd.js",
@@ -19,6 +19,7 @@
19
19
  }
20
20
  },
21
21
  "files": [
22
+ "README.md",
22
23
  "logspace.esm.js",
23
24
  "logspace.esm.js.map",
24
25
  "logspace.umd.js",
@@ -37,8 +38,5 @@
37
38
  "monitoring"
38
39
  ],
39
40
  "author": "LogSpace",
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
- }
41
+ "license": "MIT"
44
42
  }