@eventra_dev/eventra-sdk 1.1.3 → 1.1.5

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/README.md CHANGED
@@ -57,7 +57,6 @@ import { Eventra } from "@eventra_dev/eventra-sdk";
57
57
 
58
58
  const tracker = new Eventra({
59
59
  apiKey: "YOUR_PROJECT_API_KEY",
60
- endpoint: "https://api.eventra.dev/ingest",
61
60
  });
62
61
 
63
62
  tracker.track("checkout.completed", {
@@ -67,6 +66,8 @@ tracker.track("checkout.completed", {
67
66
 
68
67
  That's it.
69
68
 
69
+ By default, events are sent to `https://api.eventra.dev/api/v1/ingest/batch`.
70
+
70
71
  The SDK automatically handles:
71
72
 
72
73
  - batching
@@ -114,6 +115,8 @@ Minimal:
114
115
  tracker.track("app.loaded");
115
116
  ```
116
117
 
118
+ Event names are trimmed to 64 characters, `userId` to 120 (API limits).
119
+
117
120
  ---
118
121
 
119
122
  ## Common Examples
@@ -198,7 +201,16 @@ tracker.track("page.viewed");
198
201
  - batching
199
202
  - retry
200
203
  - persistence (localStorage)
201
- - flush on tab close
204
+ - flush on tab close (`fetch` with `keepalive`)
205
+
206
+ Optional — single sender across tabs:
207
+
208
+ ```ts
209
+ const tracker = new Eventra({
210
+ apiKey: "...",
211
+ multiTabMode: "leader",
212
+ });
213
+ ```
202
214
 
203
215
  ---
204
216
 
@@ -229,6 +241,8 @@ export default async function handler(req, res) {
229
241
 
230
242
  tracker.track("function.called");
231
243
 
244
+ await tracker.flush();
245
+
232
246
  res.status(200).end();
233
247
  }
234
248
  ```
@@ -244,11 +258,29 @@ export default async function handler(req, res) {
244
258
  ```ts
245
259
  const tracker = new Eventra({
246
260
  apiKey: "YOUR_PROJECT_API_KEY",
247
- endpoint: "CUSTOM_ENDPOINT",
248
261
  flushInterval: 2000,
249
262
  maxBatchSize: 50,
250
263
  maxQueueSize: 10000,
251
264
  maxRetries: 3,
265
+ retryBaseDelayMs: 300,
266
+ maxPayloadBytes: 60000,
267
+ onEventsDropped: (count) => {
268
+ console.warn(`Dropped ${count} event(s) — queue full`);
269
+ },
270
+ onDeliveryFailed: ({ status, events }) => {
271
+ console.error(`Ingest rejected batch (${status})`, events.length);
272
+ },
273
+ });
274
+ ```
275
+
276
+ `endpoint` is optional — omit it to use the production ingest URL.
277
+
278
+ For self-hosted or local development:
279
+
280
+ ```ts
281
+ const tracker = new Eventra({
282
+ apiKey: "...",
283
+ endpoint: "...",
252
284
  });
253
285
  ```
254
286
 
@@ -256,14 +288,22 @@ const tracker = new Eventra({
256
288
 
257
289
  ## Options
258
290
 
259
- | option | description |
260
- | ------------- | ----------------------------- |
261
- | apiKey | Project API key |
262
- | endpoint | Event ingestion endpoint |
263
- | flushInterval | Flush interval (ms) |
264
- | maxBatchSize | Events per batch |
265
- | maxQueueSize | Max buffer size |
266
- | maxRetries | Retry attempts |
291
+ | option | description |
292
+ | ------------- | --------------------------- |
293
+ | apiKey | Project API key (required) |
294
+ | endpoint | Ingest batch URL |
295
+ | flushInterval | Flush interval (ms) |
296
+ | maxBatchSize | Events per batch |
297
+ | maxQueueSize | Max buffer size |
298
+ | maxRetries | Total delivery attempts per batch (default: 3) |
299
+ | retryBaseDelayMs | Base delay for exponential backoff (ms) |
300
+ | maxPayloadBytes | Max serialized batch size (default: 60000) |
301
+ | fetchImpl | Custom `fetch` (Node without native fetch, tests) |
302
+ | autoFlushOnExit | Flush on process exit (Node / serverless, default: `true`) |
303
+ | disableTimer | Disable periodic flush timer |
304
+ | onEventsDropped | Callback when queue is full |
305
+ | onDeliveryFailed | Callback on permanent ingest errors (4xx except 429) |
306
+ | multiTabMode | `"independent"` (default) or `"leader"` (browser only) |
267
307
 
268
308
  ---
269
309
 
@@ -275,13 +315,22 @@ await tracker.flush();
275
315
 
276
316
  ---
277
317
 
278
- ## Cleanup
318
+ ## Shutdown
319
+
320
+ Graceful shutdown — flush first, then cleanup:
279
321
 
280
322
  ```ts
281
- tracker.destroy();
323
+ await tracker.shutdown();
282
324
  ```
283
325
 
284
- Stops timers, removes listeners, and clears internal state.
326
+ For Node / serverless, prefer explicit shutdown over relying on process signals:
327
+
328
+ ```ts
329
+ await tracker.flush();
330
+ await tracker.shutdown();
331
+ ```
332
+
333
+ `destroy()` stops timers and listeners immediately without flushing.
285
334
 
286
335
  ---
287
336
 
@@ -289,12 +338,19 @@ Stops timers, removes listeners, and clears internal state.
289
338
 
290
339
  Eventra SDK includes:
291
340
 
292
- - Idempotency (stable event IDs during retries)
293
- - Retry with exponential backoff
294
- - Circuit breaker (prevents overload)
341
+ - Idempotency (UUID v4 per event, stable across retries)
342
+ - Retry with exponential backoff + jitter (capped)
343
+ - Circuit breaker with half-open recovery
295
344
  - Queue-based delivery (all runtimes)
296
- - Queue persistence (browser)
297
- - sendBeacon optimization (browser exit)
345
+ - Safe dequeue (events removed only after successful ingest)
346
+ - Queue persistence (browser) with merge + cross-tab sync
347
+ - Multi-tab leader election with re-election
348
+ - `fetch` + `keepalive` on tab close (with `x-api-key`, size-checked)
349
+ - `pagehide` + `visibilitychange` flush hooks
350
+ - Property validation at `track()` (depth + size)
351
+ - Payload byte limits per batch
352
+ - Permanent error handling via `onDeliveryFailed` (401, 422, etc.)
353
+ - Automatic requeue on network errors and 429 / 5xx
298
354
 
299
355
  ---
300
356
 
@@ -305,12 +361,12 @@ Eventra SDK includes:
305
361
  "sentAt": "2026-03-12T10:00:00Z",
306
362
  "sdk": {
307
363
  "name": "@eventra_dev/eventra-sdk",
308
- "version": "1.1.3",
364
+ "version": "<sdk-version>",
309
365
  "runtime": "browser"
310
366
  },
311
367
  "events": [
312
368
  {
313
- "idempotencyKey": "uuid",
369
+ "idempotencyKey": "550e8400-e29b-41d4-a716-446655440000",
314
370
  "name": "user_signup",
315
371
  "userId": "user_123",
316
372
  "timestamp": "2026-03-12T10:00:00Z",
@@ -320,6 +376,18 @@ Eventra SDK includes:
320
376
  }
321
377
  ```
322
378
 
379
+ Limits enforced by the SDK at `track()` time:
380
+
381
+ | Field | Limit |
382
+ |-------|-------|
383
+ | `name` | trimmed, ≤ 64 chars |
384
+ | `userId` | ≤ 120 chars |
385
+ | `properties` (JSON serialized) | ≤ 32,000 bytes per event |
386
+ | Property nesting depth | ≤ 8 |
387
+ | Batch payload | ≤ `maxPayloadBytes` (default 60,000) |
388
+ | Fetch timeout | 5,000 ms |
389
+ | Circuit breaker | opens after 5 consecutive failures, cools down 5,000 ms |
390
+
323
391
  ---
324
392
 
325
393
  ## Docs