@eventra_dev/eventra-sdk 0.1.2 → 0.1.4

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
@@ -1,194 +1,350 @@
1
1
  # Eventra SDK
2
2
 
3
- ![npm](https://img.shields.io/npm/v/@eventra/sdk)
4
- ![bundle size](https://img.shields.io/bundlephobia/minzip/@eventra/sdk)
5
- ![license](https://img.shields.io/npm/l/@eventra/sdk)
6
- ![types](https://img.shields.io/npm/types/@eventra/sdk)
3
+ [![npm version](https://img.shields.io/npm/v/@eventra_dev/eventra-sdk.svg)](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@eventra_dev/eventra-sdk.svg)](https://www.npmjs.com/package/@eventra_dev/eventra-sdk)
5
+ [![TypeScript](https://img.shields.io/badge/typescript-ready-blue.svg)](https://www.typescriptlang.org/)
7
6
 
8
- Production-grade TypeScript SDK for tracking product events across **browser, server, and edge runtimes**.
7
+ Eventra SDK allows you to send **feature usage and product analytics events** to the Eventra platform.
9
8
 
10
- Eventra is designed for **deterministic ingestion**, batching efficiency, and near-zero runtime overhead.
9
+ It is designed to be:
10
+
11
+ * lightweight
12
+ * runtime-agnostic
13
+ * resilient (batching + retry)
14
+ * production-safe
15
+ * TypeScript-first
11
16
 
12
17
  ---
13
18
 
14
- ## Features
19
+ # Installation
15
20
 
16
- - UUID v4 idempotency keys
17
- - Safe retry policy
18
- - Exponential backoff with jitter
19
- - sendBeacon support for browsers
20
- - Multi-runtime support (Browser / Node / Bun / Deno / Edge)
21
- - Optional multi-tab leader mode
22
- - Queue overflow protection
23
- - Zero dependencies
21
+ Install the SDK using your preferred package manager.
24
22
 
25
- ---
23
+ ### npm
24
+
25
+ ```bash
26
+ npm i @eventra_dev/eventra-sdk
27
+ ```
26
28
 
27
- ## Install
29
+ ### pnpm
28
30
 
29
31
  ```bash
30
- pnpm add @eventra/sdk
32
+ pnpm add @eventra_dev/eventra-sdk
31
33
  ```
32
34
 
33
- or
35
+ ### yarn
34
36
 
35
37
  ```bash
36
- npm install @eventra/sdk
38
+ yarn add @eventra_dev/eventra-sdk
37
39
  ```
38
40
 
39
41
  ---
40
42
 
41
- # Quick Start
42
-
43
- ## Browser
43
+ # Quick Start
44
44
 
45
45
  ```ts
46
- import { Eventra } from "@eventra/sdk";
46
+ import { Eventra } from "@eventra_dev/eventra-sdk";
47
47
 
48
48
  const tracker = new Eventra({
49
- apiKey: "YOUR_API_KEY"
49
+ apiKey: "YOUR_PROJECT_API_KEY",
50
50
  });
51
51
 
52
52
  tracker.track("checkout.completed", {
53
- userId: "user_123"
53
+ userId: "user_123",
54
54
  });
55
55
  ```
56
56
 
57
57
  ---
58
58
 
59
- ## Node / NestJS
59
+ # Where You Can Use Eventra SDK
60
+
61
+ Eventra SDK works in many environments:
62
+
63
+ * Browser applications
64
+ * React apps
65
+ * Next.js apps
66
+ * Node.js backends
67
+ * NestJS services
68
+ * Express APIs
69
+ * Vanilla JavaScript
70
+ * Edge runtimes
71
+ * Bun
72
+ * Deno
73
+
74
+ ---
75
+
76
+ # Browser Usage
60
77
 
61
78
  ```ts
62
- import { Eventra } from "@eventra/sdk";
79
+ import { Eventra } from "@eventra_dev/eventra-sdk";
63
80
 
64
81
  const tracker = new Eventra({
65
- apiKey: process.env.EVENTRA_API_KEY!
82
+ apiKey: "YOUR_PROJECT_API_KEY",
66
83
  });
67
84
 
68
- tracker.track("invoice.created", {
69
- userId: "user_123"
85
+ tracker.track("page.viewed", {
86
+ properties: {
87
+ path: window.location.pathname
88
+ }
70
89
  });
71
90
  ```
72
91
 
73
- ---
92
+ The SDK automatically:
74
93
 
75
- # Configuration
94
+ * batches events
95
+ * retries failed requests
96
+ * flushes on page exit
76
97
 
77
- | Option | Default |
78
- |------|------|
79
- | flushInterval | 2000 ms |
80
- | maxBatchSize | 50 |
81
- | maxRetries | 3 |
82
- | maxQueueSize | 10000 |
83
- | retryBaseDelayMs | 300 |
98
+ ---
84
99
 
85
- Example:
100
+ # React Usage
86
101
 
87
102
  ```ts
103
+ import { useEffect } from "react";
104
+ import { Eventra } from "@eventra_dev/eventra-sdk";
105
+
88
106
  const tracker = new Eventra({
89
- apiKey: "API_KEY",
90
- flushInterval: 2000,
91
- maxBatchSize: 50
107
+ apiKey: "YOUR_PROJECT_API_KEY",
92
108
  });
109
+
110
+ export function App() {
111
+
112
+ useEffect(() => {
113
+ tracker.track("app.loaded");
114
+ }, []);
115
+
116
+ return <div>Hello</div>;
117
+ }
93
118
  ```
94
119
 
95
120
  ---
96
121
 
97
- # Reliability Model
122
+ # Next.js Usage
123
+
124
+ Client component example:
98
125
 
99
- ### Idempotency
126
+ ```ts
127
+ "use client";
100
128
 
101
- Each event receives a **UUID v4 idempotency key**, ensuring:
129
+ import { Eventra } from "@eventra_dev/eventra-sdk";
102
130
 
103
- - safe retries
104
- - duplicate suppression
105
- - multi-tab safety
131
+ const tracker = new Eventra({
132
+ apiKey: "YOUR_PROJECT_API_KEY",
133
+ });
134
+
135
+ export function CheckoutButton() {
136
+ return (
137
+ <button
138
+ onClick={() => tracker.track("checkout.started")}
139
+ >
140
+ Checkout
141
+ </button>
142
+ );
143
+ }
144
+ ```
106
145
 
107
146
  ---
108
147
 
109
- ### Retry Policy
148
+ # Node.js Usage
149
+
150
+ ```ts
151
+ import { Eventra } from "@eventra_dev/eventra-sdk";
110
152
 
111
- The SDK retries only when safe:
153
+ const tracker = new Eventra({
154
+ apiKey: "YOUR_PROJECT_API_KEY",
155
+ });
112
156
 
113
- network failures
114
- HTTP 5xx
157
+ tracker.track("invoice.created", {
158
+ userId: "user_123",
159
+ });
160
+ ```
161
+
162
+ ---
115
163
 
116
- It does **not retry**:
164
+ # NestJS Usage
117
165
 
118
- ✖ HTTP 4xx
119
- validation errors
120
- authentication errors
166
+ ```ts
167
+ import { Injectable } from "@nestjs/common";
168
+ import { Eventra } from "@eventra_dev/eventra-sdk";
169
+
170
+ @Injectable()
171
+ export class BillingService {
172
+
173
+ private tracker = new Eventra({
174
+ apiKey: "YOUR_PROJECT_API_KEY",
175
+ });
176
+
177
+ charge(userId: string) {
178
+ this.tracker.track("invoice.created", {
179
+ userId
180
+ });
181
+ }
182
+ }
183
+ ```
121
184
 
122
185
  ---
123
186
 
124
- ### Backoff Strategy
187
+ # Express Usage
188
+
189
+ ```ts
190
+ import express from "express";
191
+ import { Eventra } from "@eventra_dev/eventra-sdk";
192
+
193
+ const app = express();
125
194
 
195
+ const tracker = new Eventra({
196
+ apiKey: "YOUR_PROJECT_API_KEY",
197
+ });
198
+
199
+ app.post("/checkout", (req, res) => {
200
+
201
+ tracker.track("checkout.completed");
202
+
203
+ res.sendStatus(200);
204
+ });
126
205
  ```
127
- delay = base * 2^attempt * jitter(0.5–1.5)
206
+
207
+ ---
208
+
209
+ # Vanilla JavaScript (CDN)
210
+
211
+ You can use Eventra without a bundler.
212
+
213
+ ```html
214
+ <script type="module">
215
+
216
+ import { Eventra } from "https://esm.sh/@eventra_dev/eventra-sdk";
217
+
218
+ const tracker = new Eventra({
219
+ apiKey: "YOUR_PROJECT_API_KEY",
220
+ });
221
+
222
+ tracker.track("page.viewed");
223
+
224
+ </script>
128
225
  ```
129
226
 
130
227
  ---
131
228
 
132
- # Multi-Tab Mode
229
+ # Configuration
133
230
 
134
- Default:
231
+ You can configure the SDK behaviour.
135
232
 
136
233
  ```ts
137
- multiTabMode: "independent"
234
+ const eventra = new Eventra({
235
+
236
+ apiKey: "YOUR_PROJECT_API_KEY",
237
+
238
+ endpoint: "https://api.eventra.dev/api/v1/events",
239
+
240
+ flushInterval: 2000,
241
+ maxBatchSize: 50,
242
+ maxQueueSize: 10000,
243
+ maxRetries: 3
244
+
245
+ });
138
246
  ```
139
247
 
140
- Leader mode:
248
+ ---
249
+
250
+ # Options
251
+
252
+ | option | description |
253
+ | ------------- | ---------------------------------- |
254
+ | apiKey | Project API key |
255
+ | endpoint | Event ingestion endpoint |
256
+ | flushInterval | Batch flush interval (ms) |
257
+ | maxBatchSize | Maximum events per batch |
258
+ | maxQueueSize | Maximum buffered events |
259
+ | maxRetries | Retry attempts for failed requests |
260
+ | multiTabMode | Browser tab coordination mode |
261
+
262
+ ---
263
+
264
+ # Multi-Tab Mode (Browser)
265
+
266
+ To avoid duplicate event sending across multiple tabs:
141
267
 
142
268
  ```ts
143
269
  const tracker = new Eventra({
144
- apiKey: "API_KEY",
270
+ apiKey: "YOUR_PROJECT_API_KEY",
145
271
  multiTabMode: "leader"
146
272
  });
147
273
  ```
148
274
 
149
- One tab becomes the sender and reduces duplicate traffic.
275
+ Only one tab will send events.
150
276
 
151
277
  ---
152
278
 
153
- # Architecture
279
+ # Manual Flush
154
280
 
281
+ ```ts
282
+ await tracker.flush();
155
283
  ```
156
- Application
157
-
158
-
159
- Eventra SDK
160
-
161
- batching + retry
162
-
163
-
164
- Eventra Ingest API
165
-
166
- idempotent pipeline
167
-
168
-
169
- Eventra Event Store
284
+
285
+ ---
286
+
287
+ # Shutdown / Cleanup
288
+
289
+ ```ts
290
+ tracker.destroy();
170
291
  ```
171
292
 
293
+ Stops timers and prevents further event sending.
294
+
172
295
  ---
173
296
 
174
- # Best Practices
297
+ # Runtime Support
175
298
 
176
- Use semantic event names.
299
+ Eventra SDK works in:
177
300
 
178
- Good:
301
+ * Node.js
302
+ * Browser
303
+ * Bun
304
+ * Deno
305
+ * Edge runtimes
306
+ * Serverless environments
179
307
 
180
- ```
181
- invoice.created
182
- checkout.completed
183
- team.invited
308
+ ---
309
+
310
+ # Event Format
311
+
312
+ Events are sent in batches:
313
+
314
+ ```json
315
+ {
316
+ "sentAt": "2026-03-12T10:00:00Z",
317
+ "sdk": {
318
+ "name": "@eventra_dev/eventra-sdk",
319
+ "version": "0.1.2",
320
+ "runtime": "node"
321
+ },
322
+ "events": [
323
+ {
324
+ "name": "user_signup",
325
+ "userId": "user_123",
326
+ "timestamp": "2026-03-12T10:00:00Z",
327
+ "properties": {}
328
+ }
329
+ ]
330
+ }
184
331
  ```
185
332
 
186
- Bad:
333
+ ---
187
334
 
188
- ```
189
- button_clicked
190
- modal_opened
191
- ```
335
+ # Error Handling
336
+
337
+ Client errors (4xx) are **not retried**.
338
+
339
+ Server errors (5xx) are retried using **exponential backoff**.
340
+
341
+ ---
342
+
343
+ # Documentation
344
+
345
+ Full documentation:
346
+
347
+ https://eventra.dev/docs
192
348
 
193
349
  ---
194
350
 
package/dist/index.cjs CHANGED
@@ -25,7 +25,7 @@ __export(index_exports, {
25
25
  module.exports = __toCommonJS(index_exports);
26
26
 
27
27
  // src/client.ts
28
- var SDK_VERSION = "0.1.2";
28
+ var SDK_VERSION = "0.1.4";
29
29
  var DEFAULTS = {
30
30
  endpoint: "http://api.eventra.dev/api/v1/ingest/batch",
31
31
  flushInterval: 2e3,
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/client.ts
2
- var SDK_VERSION = "0.1.2";
2
+ var SDK_VERSION = "0.1.4";
3
3
  var DEFAULTS = {
4
4
  endpoint: "http://api.eventra.dev/api/v1/ingest/batch",
5
5
  flushInterval: 2e3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventra_dev/eventra-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"