@eventra_dev/eventra-sdk 1.0.7 → 1.1.1
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 +131 -246
- package/dist/index.cjs +172 -165
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -17
- package/dist/index.d.ts +18 -17
- package/dist/index.mjs +175 -168
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,131 +1,162 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
retryBaseDelay: 300
|
|
10
|
-
};
|
|
11
|
-
function getGlobalFetch() {
|
|
12
|
-
if (typeof fetch !== "undefined") {
|
|
13
|
-
return fetch.bind(globalThis);
|
|
14
|
-
}
|
|
15
|
-
return void 0;
|
|
2
|
+
function detectRuntime() {
|
|
3
|
+
const g = globalThis;
|
|
4
|
+
if (typeof window !== "undefined") return "browser";
|
|
5
|
+
if (g.EdgeRuntime) return "edge";
|
|
6
|
+
if (g.process?.env?.AWS_LAMBDA_FUNCTION_NAME) return "serverless";
|
|
7
|
+
if (g.process?.versions?.node) return "node";
|
|
8
|
+
return "unknown";
|
|
16
9
|
}
|
|
17
|
-
function
|
|
18
|
-
if (typeof crypto !== "undefined" &&
|
|
10
|
+
function uuid() {
|
|
11
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
19
12
|
return crypto.randomUUID();
|
|
20
13
|
}
|
|
21
|
-
|
|
22
|
-
const ts = Date.now().toString(16);
|
|
23
|
-
return `${ts}-${rnd}`;
|
|
24
|
-
}
|
|
25
|
-
function isBrowser() {
|
|
26
|
-
return typeof window !== "undefined";
|
|
14
|
+
return `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
27
15
|
}
|
|
28
16
|
function sleep(ms) {
|
|
29
17
|
return new Promise((r) => setTimeout(r, ms));
|
|
30
18
|
}
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
);
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
const parsed = JSON.parse(raw);
|
|
46
|
-
if (now - parsed.ts > LEADER_TTL) {
|
|
47
|
-
localStorage.setItem(
|
|
48
|
-
LEADER_KEY,
|
|
49
|
-
JSON.stringify({ ts: now })
|
|
50
|
-
);
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
} catch {
|
|
55
|
-
return true;
|
|
19
|
+
var Storage = class {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.enabled = false;
|
|
22
|
+
try {
|
|
23
|
+
if (typeof localStorage !== "undefined") {
|
|
24
|
+
localStorage.setItem("__t", "1");
|
|
25
|
+
localStorage.removeItem("__t");
|
|
26
|
+
this.enabled = true;
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
56
30
|
}
|
|
57
|
-
|
|
31
|
+
get(key) {
|
|
32
|
+
if (!this.enabled) return null;
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(localStorage.getItem(key) || "null");
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
set(key, value) {
|
|
40
|
+
if (!this.enabled) return;
|
|
41
|
+
try {
|
|
42
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var Leader = class {
|
|
48
|
+
constructor(enabled) {
|
|
49
|
+
this.isLeader = true;
|
|
50
|
+
if (!enabled) return;
|
|
51
|
+
if (typeof BroadcastChannel !== "undefined") {
|
|
52
|
+
this.channel = new BroadcastChannel("eventra");
|
|
53
|
+
this.channel.onmessage = (e) => {
|
|
54
|
+
if (e.data === "leader") this.isLeader = false;
|
|
55
|
+
};
|
|
56
|
+
this.channel.postMessage("leader");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
canSend() {
|
|
60
|
+
return this.isLeader;
|
|
61
|
+
}
|
|
62
|
+
destroy() {
|
|
63
|
+
this.channel?.close();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
58
66
|
var Eventra = class {
|
|
59
67
|
constructor(options) {
|
|
60
68
|
this.queue = [];
|
|
61
69
|
this.inFlight = false;
|
|
62
70
|
this.destroyed = false;
|
|
63
|
-
this.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
this.storage = new Storage();
|
|
72
|
+
this.leader = null;
|
|
73
|
+
this.failureCount = 0;
|
|
74
|
+
this.circuitOpenUntil = 0;
|
|
75
|
+
this.exitHandlers = [];
|
|
76
|
+
if (!options.apiKey) throw new Error("apiKey required");
|
|
77
|
+
if (!options.endpoint) throw new Error("endpoint required");
|
|
78
|
+
this.options = options;
|
|
67
79
|
this.apiKey = options.apiKey;
|
|
68
|
-
this.endpoint = options.endpoint
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
79
|
-
if (!this.fetchImpl) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
"Eventra: fetch is not available. Provide fetchImpl."
|
|
82
|
-
);
|
|
83
|
-
}
|
|
80
|
+
this.endpoint = options.endpoint;
|
|
81
|
+
this.runtime = detectRuntime();
|
|
82
|
+
this.fetch = options.fetchImpl ?? globalThis.fetch;
|
|
83
|
+
if (!this.fetch) {
|
|
84
|
+
throw new Error("fetch not available \u2014 provide fetchImpl");
|
|
85
|
+
}
|
|
86
|
+
this.maxBatch = options.maxBatchSize ?? 50;
|
|
87
|
+
this.maxQueue = options.maxQueueSize ?? 1e4;
|
|
88
|
+
this.flushInterval = options.flushInterval ?? 2e3;
|
|
89
|
+
this.retries = options.maxRetries ?? 3;
|
|
90
|
+
this.retryDelay = options.retryBaseDelayMs ?? 300;
|
|
84
91
|
this.sdkInfo = {
|
|
85
92
|
name: "@eventra_dev/eventra-sdk",
|
|
86
|
-
version:
|
|
87
|
-
runtime: this.
|
|
93
|
+
version: "1.0.0",
|
|
94
|
+
runtime: this.runtime
|
|
88
95
|
};
|
|
96
|
+
if (this.runtime === "browser") {
|
|
97
|
+
const saved = this.storage.get("__eventra_q__");
|
|
98
|
+
if (Array.isArray(saved)) this.queue = saved;
|
|
99
|
+
}
|
|
100
|
+
if (this.runtime === "browser" && options.multiTabMode === "leader") {
|
|
101
|
+
this.leader = new Leader(true);
|
|
102
|
+
}
|
|
89
103
|
if (!options.disableTimer) {
|
|
90
104
|
this.startTimer();
|
|
91
105
|
}
|
|
92
|
-
if (
|
|
93
|
-
this.
|
|
106
|
+
if (this.runtime === "browser") {
|
|
107
|
+
this.setupBrowserExit();
|
|
108
|
+
}
|
|
109
|
+
if (options.autoFlushOnExit !== false && this.runtime !== "browser") {
|
|
110
|
+
this.setupProcessExit();
|
|
94
111
|
}
|
|
95
|
-
this.onEventsDropped = options.onEventsDropped;
|
|
96
112
|
}
|
|
97
|
-
|
|
113
|
+
// ================= PUBLIC =================
|
|
98
114
|
track(name, options) {
|
|
99
115
|
if (this.destroyed) return;
|
|
100
|
-
if (this.queue.length >= this.
|
|
101
|
-
this.
|
|
102
|
-
this.onEventsDropped?.(this.droppedEvents);
|
|
116
|
+
if (this.queue.length >= this.maxQueue) {
|
|
117
|
+
this.options.onEventsDropped?.(1);
|
|
103
118
|
return;
|
|
104
119
|
}
|
|
105
|
-
|
|
106
|
-
idempotencyKey:
|
|
120
|
+
const event = {
|
|
121
|
+
idempotencyKey: uuid(),
|
|
107
122
|
name,
|
|
108
123
|
userId: options?.userId,
|
|
109
124
|
properties: options?.properties ?? {},
|
|
110
125
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
111
|
-
}
|
|
112
|
-
|
|
126
|
+
};
|
|
127
|
+
this.queue.push(event);
|
|
128
|
+
if (this.runtime === "browser") {
|
|
129
|
+
this.persist();
|
|
130
|
+
}
|
|
131
|
+
if (this.queue.length >= this.maxBatch) {
|
|
132
|
+
void this.flush();
|
|
133
|
+
}
|
|
134
|
+
if (this.runtime === "serverless") {
|
|
113
135
|
void this.flush();
|
|
114
136
|
}
|
|
115
137
|
}
|
|
116
138
|
async flush() {
|
|
117
|
-
if (this.destroyed) return;
|
|
118
|
-
if (this.
|
|
119
|
-
if (this.
|
|
120
|
-
if (
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
139
|
+
if (this.inFlight || this.destroyed) return;
|
|
140
|
+
if (!this.queue.length) return;
|
|
141
|
+
if (this.leader && !this.leader.canSend()) return;
|
|
142
|
+
if (Date.now() < this.circuitOpenUntil) return;
|
|
123
143
|
this.inFlight = true;
|
|
124
|
-
const batch = this.queue.splice(0, this.
|
|
144
|
+
const batch = this.queue.splice(0, this.maxBatch);
|
|
145
|
+
if (this.runtime === "browser") {
|
|
146
|
+
this.persist();
|
|
147
|
+
}
|
|
125
148
|
try {
|
|
126
149
|
await this.send(batch);
|
|
150
|
+
this.failureCount = 0;
|
|
127
151
|
} catch {
|
|
128
|
-
this.queue
|
|
152
|
+
this.queue = [...batch, ...this.queue];
|
|
153
|
+
if (this.runtime === "browser") {
|
|
154
|
+
this.persist();
|
|
155
|
+
}
|
|
156
|
+
this.failureCount++;
|
|
157
|
+
if (this.failureCount >= 5) {
|
|
158
|
+
this.circuitOpenUntil = Date.now() + 5e3;
|
|
159
|
+
}
|
|
129
160
|
} finally {
|
|
130
161
|
this.inFlight = false;
|
|
131
162
|
}
|
|
@@ -133,113 +164,89 @@ var Eventra = class {
|
|
|
133
164
|
destroy() {
|
|
134
165
|
this.destroyed = true;
|
|
135
166
|
if (this.timer) clearInterval(this.timer);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!isBrowser()) return false;
|
|
140
|
-
try {
|
|
141
|
-
if (navigator.sendBeacon) {
|
|
142
|
-
const blob = new Blob([payload], {
|
|
143
|
-
type: "application/json"
|
|
144
|
-
});
|
|
145
|
-
return navigator.sendBeacon(this.endpoint, blob);
|
|
146
|
-
}
|
|
147
|
-
} catch {
|
|
167
|
+
this.leader?.destroy();
|
|
168
|
+
for (const off of this.exitHandlers) {
|
|
169
|
+
off();
|
|
148
170
|
}
|
|
149
|
-
return false;
|
|
150
171
|
}
|
|
172
|
+
// ================= SEND =================
|
|
151
173
|
async send(events) {
|
|
152
174
|
const payload = JSON.stringify({
|
|
153
175
|
sentAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
154
176
|
sdk: this.sdkInfo,
|
|
155
177
|
events
|
|
156
178
|
});
|
|
157
|
-
if (
|
|
158
|
-
|
|
179
|
+
if (this.runtime === "browser" && typeof navigator !== "undefined" && navigator.sendBeacon && payload.length < 6e4 && document.visibilityState === "hidden") {
|
|
180
|
+
navigator.sendBeacon(this.endpoint, payload);
|
|
181
|
+
return;
|
|
159
182
|
}
|
|
160
183
|
let attempt = 0;
|
|
161
|
-
while (attempt <= this.
|
|
184
|
+
while (attempt <= this.retries) {
|
|
162
185
|
try {
|
|
163
|
-
const
|
|
186
|
+
const controller = new AbortController();
|
|
187
|
+
const timeout = setTimeout(() => controller.abort(), 5e3);
|
|
188
|
+
const res = await this.fetch(this.endpoint, {
|
|
164
189
|
method: "POST",
|
|
165
190
|
headers: {
|
|
166
191
|
"Content-Type": "application/json",
|
|
167
192
|
"x-api-key": this.apiKey
|
|
168
193
|
},
|
|
169
|
-
body: payload
|
|
194
|
+
body: payload,
|
|
195
|
+
signal: controller.signal
|
|
170
196
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (!res.ok) {
|
|
178
|
-
throw new Error(`HTTP ${res.status}`);
|
|
179
|
-
}
|
|
197
|
+
clearTimeout(timeout);
|
|
198
|
+
if (res.status >= 400 && res.status < 500) return;
|
|
199
|
+
if (!res.ok) throw new Error();
|
|
180
200
|
return;
|
|
181
|
-
} catch
|
|
201
|
+
} catch {
|
|
182
202
|
attempt++;
|
|
183
|
-
if (attempt > this.
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
const jitter = 0.5 + Math.random();
|
|
187
|
-
const delay = this.retryBaseDelay * 2 ** (attempt - 1) * jitter;
|
|
188
|
-
await sleep(delay);
|
|
203
|
+
if (attempt > this.retries) throw new Error();
|
|
204
|
+
await sleep(this.retryDelay * 2 ** attempt);
|
|
189
205
|
}
|
|
190
206
|
}
|
|
191
207
|
}
|
|
192
|
-
|
|
193
|
-
detectRuntime() {
|
|
194
|
-
const g = globalThis;
|
|
195
|
-
if (typeof g["EdgeRuntime"] !== "undefined") {
|
|
196
|
-
return "edge-vercel";
|
|
197
|
-
}
|
|
198
|
-
if (typeof g["WebSocketPair"] !== "undefined" && typeof g["caches"] !== "undefined") {
|
|
199
|
-
return "edge-cloudflare";
|
|
200
|
-
}
|
|
201
|
-
if (g["Deno"]) return "deno";
|
|
202
|
-
if (g["Bun"]) return "bun";
|
|
203
|
-
if (typeof window !== "undefined") {
|
|
204
|
-
return "browser";
|
|
205
|
-
}
|
|
206
|
-
if (typeof self !== "undefined" && typeof window === "undefined") {
|
|
207
|
-
return "worker";
|
|
208
|
-
}
|
|
209
|
-
const maybeProcess = g["process"];
|
|
210
|
-
if (maybeProcess?.versions?.node) {
|
|
211
|
-
return "node";
|
|
212
|
-
}
|
|
213
|
-
return "unknown";
|
|
214
|
-
}
|
|
215
|
-
/* ---------------- Timer ---------------- */
|
|
208
|
+
// ================= INTERNAL =================
|
|
216
209
|
startTimer() {
|
|
217
210
|
this.timer = setInterval(() => {
|
|
218
211
|
void this.flush();
|
|
219
212
|
}, this.flushInterval);
|
|
220
213
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
214
|
+
setupBrowserExit() {
|
|
215
|
+
const handler = () => {
|
|
216
|
+
if (document.visibilityState === "hidden") {
|
|
217
|
+
void this.flush();
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
window.addEventListener("visibilitychange", handler);
|
|
221
|
+
this.exitHandlers.push(() => {
|
|
222
|
+
window.removeEventListener("visibilitychange", handler);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
setupProcessExit() {
|
|
230
226
|
const g = globalThis;
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
227
|
+
const flushSafe = async () => {
|
|
228
|
+
try {
|
|
229
|
+
await this.flush();
|
|
230
|
+
} catch {
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const beforeExit = () => {
|
|
234
|
+
void flushSafe();
|
|
235
|
+
};
|
|
236
|
+
const sigint = async () => {
|
|
237
|
+
await flushSafe();
|
|
238
|
+
g.exit();
|
|
239
|
+
};
|
|
240
|
+
g?.on?.("beforeExit", beforeExit);
|
|
241
|
+
g?.on?.("SIGINT", sigint);
|
|
242
|
+
this.exitHandlers.push(() => {
|
|
243
|
+
g?.off?.("beforeExit", beforeExit);
|
|
244
|
+
g?.off?.("SIGINT", sigint);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
persist() {
|
|
248
|
+
if (this.runtime !== "browser") return;
|
|
249
|
+
this.storage.set("__eventra_q__", this.queue);
|
|
243
250
|
}
|
|
244
251
|
};
|
|
245
252
|
export {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import {\n TrackerOptions,\n TrackEvent,\n SdkInfo,\n} from \"./types\";\n\n/* ---------------- Constants ---------------- */\n\n\ndeclare const __SDK_VERSION__: string;\ndeclare const __EVENTRA_ENDPOINT__: string | undefined;\n\nconst SDK_VERSION = __SDK_VERSION__;\n\nconst DEFAULTS = {\n endpoint: __EVENTRA_ENDPOINT__ ?? \"\",\n flushInterval: 2000,\n maxBatchSize: 50,\n maxQueueSize: 10_000,\n maxRetries: 3,\n retryBaseDelay: 300,\n};\n\n/* ---------------- Helpers ---------------- */\n\nfunction getGlobalFetch(): typeof fetch | undefined {\n if (typeof fetch !== \"undefined\") {\n return fetch.bind(globalThis);\n }\n return undefined;\n}\n\nfunction generateUUIDv4(): string {\n if (\n typeof crypto !== \"undefined\" &&\n typeof crypto.randomUUID === \"function\"\n ) {\n return crypto.randomUUID();\n }\n\n // ultra-rare fallback\n const rnd = Math.random().toString(16).slice(2);\n const ts = Date.now().toString(16);\n return `${ts}-${rnd}`;\n}\n\nfunction isBrowser(): boolean {\n return typeof window !== \"undefined\";\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((r) => setTimeout(r, ms));\n}\n\n/* ---------------- Leader Election (minimal) ---------------- */\n\nconst LEADER_KEY = \"__eventra_sdk_leader__\";\nconst LEADER_TTL = 4000;\n\nfunction tryBecomeLeader(): boolean {\n if (!isBrowser()) return true;\n\n try {\n const now = Date.now();\n const raw = localStorage.getItem(LEADER_KEY);\n\n if (!raw) {\n localStorage.setItem(\n LEADER_KEY,\n JSON.stringify({ ts: now })\n );\n return true;\n }\n\n const parsed = JSON.parse(raw) as { ts: number };\n\n if (now - parsed.ts > LEADER_TTL) {\n localStorage.setItem(\n LEADER_KEY,\n JSON.stringify({ ts: now })\n );\n return true;\n }\n\n return false;\n } catch {\n return true; // fail-open\n }\n}\n\n/* ============================================================ */\n\nexport class Eventra {\n private apiKey: string;\n private endpoint: string;\n private flushInterval: number;\n private maxBatchSize: number;\n private maxQueueSize: number;\n private maxRetries: number;\n private retryBaseDelay: number;\n private multiTabMode: \"independent\" | \"leader\";\n\n private fetchImpl?: typeof fetch;\n private queue: TrackEvent[] = [];\n private timer?: ReturnType<typeof setInterval>;\n private inFlight = false;\n private destroyed = false;\n private droppedEvents = 0;\n\n private sdkInfo: SdkInfo;\n\n constructor(options: TrackerOptions) {\n if (!options.apiKey) {\n throw new Error(\"Eventra: apiKey is required\");\n }\n\n this.apiKey = options.apiKey;\n\n this.endpoint = options.endpoint ?? DEFAULTS.endpoint ?? \"\";\n if (!this.endpoint) {\n throw new Error(\"Eventra: endpoint is not configured\");\n }\n\n this.flushInterval =\n options.flushInterval ?? DEFAULTS.flushInterval;\n\n this.maxBatchSize =\n options.maxBatchSize ?? DEFAULTS.maxBatchSize;\n\n this.maxQueueSize =\n options.maxQueueSize ?? DEFAULTS.maxQueueSize;\n\n this.maxRetries =\n options.maxRetries ?? DEFAULTS.maxRetries;\n\n this.retryBaseDelay =\n options.retryBaseDelayMs ?? DEFAULTS.retryBaseDelay;\n\n this.multiTabMode =\n options.multiTabMode ?? \"independent\";\n\n this.fetchImpl =\n options.fetchImpl ?? getGlobalFetch();\n\n if (!this.fetchImpl) {\n throw new Error(\n \"Eventra: fetch is not available. Provide fetchImpl.\"\n );\n }\n\n this.sdkInfo = {\n name: \"@eventra_dev/eventra-sdk\",\n version: SDK_VERSION,\n runtime: this.detectRuntime(),\n };\n\n if (!options.disableTimer) {\n this.startTimer();\n }\n\n if (options.autoFlushOnExit !== false) {\n this.setupExitHandlers();\n }\n\n this.onEventsDropped = options.onEventsDropped;\n }\n\n private onEventsDropped?: (count: number) => void;\n\n /* ---------------- Public API ---------------- */\n\n track(\n name: string,\n options?: {\n userId?: string;\n properties?: Record<string, unknown>;\n }\n ) {\n if (this.destroyed) return;\n\n if (this.queue.length >= this.maxQueueSize) {\n this.droppedEvents++;\n this.onEventsDropped?.(this.droppedEvents);\n return;\n }\n\n this.queue.push({\n idempotencyKey: generateUUIDv4(),\n name,\n userId: options?.userId,\n properties: options?.properties ?? {},\n timestamp: new Date().toISOString(),\n });\n\n if (this.queue.length >= this.maxBatchSize) {\n void this.flush();\n }\n }\n\n async flush(): Promise<void> {\n if (this.destroyed) return;\n if (this.inFlight) return;\n if (this.queue.length === 0) return;\n\n if (\n this.multiTabMode === \"leader\" &&\n !tryBecomeLeader()\n ) {\n return;\n }\n\n this.inFlight = true;\n\n const batch = this.queue.splice(0, this.queue.length);\n\n try {\n await this.send(batch);\n } catch {\n this.queue.unshift(...batch);\n } finally {\n this.inFlight = false;\n }\n }\n\n destroy() {\n this.destroyed = true;\n if (this.timer) clearInterval(this.timer);\n }\n\n /* ---------------- Transport ---------------- */\n\n private trySendBeacon(payload: string): boolean {\n if (!isBrowser()) return false;\n\n try {\n if (navigator.sendBeacon) {\n const blob = new Blob([payload], {\n type: \"application/json\",\n });\n return navigator.sendBeacon(this.endpoint, blob);\n }\n } catch {\n // ignore\n }\n\n return false;\n }\n\n private async send(events: TrackEvent[]) {\n const payload = JSON.stringify({\n sentAt: new Date().toISOString(),\n sdk: this.sdkInfo,\n events,\n });\n\n // beacon fast-path (browser only)\n if (\n isBrowser() &&\n payload.length < 60_000 &&\n document.visibilityState === \"hidden\"\n ) {\n if (this.trySendBeacon(payload)) return;\n }\n\n let attempt = 0;\n\n while (attempt <= this.maxRetries) {\n try {\n const res = await this.fetchImpl!(this.endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": this.apiKey,\n },\n body: payload,\n });\n\n // ❗ DO NOT retry client errors\n if (res.status >= 400 && res.status < 500) {\n if (res.status === 401 || res.status === 403) {\n console.error(\"Eventra: Invalid API key\");\n }\n return;\n }\n\n if (!res.ok) {\n throw new Error(`HTTP ${res.status}`);\n }\n\n return;\n } catch (err) {\n attempt++;\n\n if (attempt > this.maxRetries) {\n throw err;\n }\n\n const jitter = 0.5 + Math.random(); // 0.5–1.5\n const delay =\n this.retryBaseDelay *\n 2 ** (attempt - 1) *\n jitter;\n\n await sleep(delay);\n }\n }\n }\n\n /* ---------------- Runtime ---------------- */\n\n private detectRuntime(): string {\n const g = globalThis as Record<string, unknown>;\n\n // Edge (Vercel)\n if (typeof g[\"EdgeRuntime\"] !== \"undefined\") {\n return \"edge-vercel\";\n }\n\n // Cloudflare Workers\n if (\n typeof g[\"WebSocketPair\"] !== \"undefined\" &&\n typeof g[\"caches\"] !== \"undefined\"\n ) {\n return \"edge-cloudflare\";\n }\n\n // Deno\n if (g[\"Deno\"]) return \"deno\";\n\n // Bun\n if (g[\"Bun\"]) return \"bun\";\n\n // Browser (window)\n if (typeof window !== \"undefined\") {\n return \"browser\";\n }\n\n // Web Worker / Service Worker\n if (\n typeof self !== \"undefined\" &&\n typeof window === \"undefined\"\n ) {\n return \"worker\";\n }\n\n // Node\n const maybeProcess = g[\"process\"] as\n | { versions?: { node?: string } }\n | undefined;\n\n if (maybeProcess?.versions?.node) {\n return \"node\";\n }\n\n return \"unknown\";\n }\n\n /* ---------------- Timer ---------------- */\n\n private startTimer() {\n this.timer = setInterval(() => {\n void this.flush();\n }, this.flushInterval);\n }\n\n /* ---------------- Exit handling ---------------- */\n\n private setupExitHandlers() {\n // browser\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"visibilitychange\", () => {\n if (document.visibilityState === \"hidden\") {\n void this.flush();\n }\n });\n }\n\n // node\n const g = globalThis as Record<string, unknown>;\n\n const maybeProcess = g[\"process\"] as\n | { once?: (event: string, cb: () => void) => void }\n | undefined;\n\n if (typeof maybeProcess?.once === \"function\") {\n const shutdown = async () => {\n try {\n await this.flush();\n } catch {}\n };\n\n maybeProcess.once(\"SIGINT\", shutdown);\n maybeProcess.once(\"SIGTERM\", shutdown);\n maybeProcess.once(\"beforeExit\", shutdown);\n }\n }\n}\n\nexport * from \"./types\";\n"],"mappings":";AAYA,IAAM,cAAc;AAEpB,IAAM,WAAW;AAAA,EACf,UAAU;AAAA,EACV,eAAe;AAAA,EACf,cAAc;AAAA,EACd,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,g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B;AAE1B,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO,iBAAiB,oBAAoB,MAAM;AAChD,YAAI,SAAS,oBAAoB,UAAU;AACzC,eAAK,KAAK,MAAM;AAAA,QAClB;AAAA,MACF,CAAC;AAAA,IACH;AAGA,UAAM,IAAI;AAEV,UAAM,eAAe,EAAE,SAAS;AAIhC,QAAI,OAAO,cAAc,SAAS,YAAY;AAC5C,YAAM,WAAW,YAAY;AAC3B,YAAI;AACF,gBAAM,KAAK,MAAM;AAAA,QACnB,QAAQ;AAAA,QAAC;AAAA,MACX;AAEA,mBAAa,KAAK,UAAU,QAAQ;AACpC,mBAAa,KAAK,WAAW,QAAQ;AACrC,mBAAa,KAAK,cAAc,QAAQ;AAAA,IAC1C;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { TrackerOptions, TrackEvent, SdkInfo } from \"./types\";\n\n// ================= RUNTIME =================\ntype Runtime = \"browser\" | \"node\" | \"edge\" | \"serverless\" | \"unknown\";\n\nfunction detectRuntime(): Runtime {\n const g = globalThis as any;\n\n if (typeof window !== \"undefined\") return \"browser\";\n if (g.EdgeRuntime) return \"edge\";\n if (g.process?.env?.AWS_LAMBDA_FUNCTION_NAME) return \"serverless\";\n if (g.process?.versions?.node) return \"node\";\n\n return \"unknown\";\n}\n\n// ================= HELPERS =================\nfunction uuid(): string {\n if (typeof crypto !== \"undefined\" && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n return `${Date.now()}-${Math.random().toString(16).slice(2)}`;\n}\n\nfunction sleep(ms: number) {\n return new Promise((r) => setTimeout(r, ms));\n}\n\n// ================= STORAGE =================\nclass Storage {\n private enabled = false;\n\n constructor() {\n try {\n if (typeof localStorage !== \"undefined\") {\n localStorage.setItem(\"__t\", \"1\");\n localStorage.removeItem(\"__t\");\n this.enabled = true;\n }\n } catch {}\n }\n\n get(key: string): any {\n if (!this.enabled) return null;\n try {\n return JSON.parse(localStorage.getItem(key) || \"null\");\n } catch {\n return null;\n }\n }\n\n set(key: string, value: any) {\n if (!this.enabled) return;\n try {\n localStorage.setItem(key, JSON.stringify(value));\n } catch {}\n }\n}\n\n// ================= LEADER =================\nclass Leader {\n private channel?: BroadcastChannel;\n private isLeader = true;\n\n constructor(enabled: boolean) {\n if (!enabled) return;\n\n if (typeof BroadcastChannel !== \"undefined\") {\n this.channel = new BroadcastChannel(\"eventra\");\n\n this.channel.onmessage = (e) => {\n if (e.data === \"leader\") this.isLeader = false;\n };\n\n this.channel.postMessage(\"leader\");\n }\n }\n\n canSend() {\n return this.isLeader;\n }\n\n destroy() {\n this.channel?.close();\n }\n}\n\n// ================= SDK =================\nexport class Eventra {\n private apiKey: string;\n private endpoint: string;\n private runtime: Runtime;\n private fetch: typeof fetch;\n\n private queue: TrackEvent[] = [];\n private inFlight = false;\n private destroyed = false;\n\n private maxBatch: number;\n private maxQueue: number;\n private flushInterval: number;\n private retries: number;\n private retryDelay: number;\n\n private timer?: any;\n\n private storage = new Storage();\n private leader: Leader | null = null;\n\n private failureCount = 0;\n private circuitOpenUntil = 0;\n\n private sdkInfo: SdkInfo;\n private options: TrackerOptions;\n\n private exitHandlers: Array<() => void> = [];\n\n constructor(options: TrackerOptions) {\n if (!options.apiKey) throw new Error(\"apiKey required\");\n if (!options.endpoint) throw new Error(\"endpoint required\");\n\n this.options = options;\n this.apiKey = options.apiKey;\n this.endpoint = options.endpoint;\n this.runtime = detectRuntime();\n\n this.fetch = options.fetchImpl ?? globalThis.fetch;\n if (!this.fetch) {\n throw new Error(\"fetch not available — provide fetchImpl\");\n }\n\n this.maxBatch = options.maxBatchSize ?? 50;\n this.maxQueue = options.maxQueueSize ?? 10000;\n this.flushInterval = options.flushInterval ?? 2000;\n this.retries = options.maxRetries ?? 3;\n this.retryDelay = options.retryBaseDelayMs ?? 300;\n\n this.sdkInfo = {\n name: \"@eventra_dev/eventra-sdk\",\n version: \"1.0.0\",\n runtime: this.runtime,\n };\n\n // restore browser queue\n if (this.runtime === \"browser\") {\n const saved = this.storage.get(\"__eventra_q__\");\n if (Array.isArray(saved)) this.queue = saved;\n }\n\n // leader (browser only)\n if (this.runtime === \"browser\" && options.multiTabMode === \"leader\") {\n this.leader = new Leader(true);\n }\n\n // timer\n if (!options.disableTimer) {\n this.startTimer();\n }\n\n // browser exit\n if (this.runtime === \"browser\") {\n this.setupBrowserExit();\n }\n\n // node / serverless exit\n if (options.autoFlushOnExit !== false && this.runtime !== \"browser\") {\n this.setupProcessExit();\n }\n }\n\n // ================= PUBLIC =================\n track(name: string, options?: any) {\n if (this.destroyed) return;\n\n if (this.queue.length >= this.maxQueue) {\n this.options.onEventsDropped?.(1);\n return;\n }\n\n const event: TrackEvent = {\n idempotencyKey: uuid(),\n name,\n userId: options?.userId,\n properties: options?.properties ?? {},\n timestamp: new Date().toISOString(),\n };\n\n this.queue.push(event);\n\n if (this.runtime === \"browser\") {\n this.persist();\n }\n\n if (this.queue.length >= this.maxBatch) {\n void this.flush();\n }\n\n if (this.runtime === \"serverless\") {\n void this.flush();\n }\n }\n\n async flush() {\n if (this.inFlight || this.destroyed) return;\n if (!this.queue.length) return;\n\n if (this.leader && !this.leader.canSend()) return;\n if (Date.now() < this.circuitOpenUntil) return;\n\n this.inFlight = true;\n\n const batch = this.queue.splice(0, this.maxBatch);\n\n if (this.runtime === \"browser\") {\n this.persist();\n }\n\n try {\n await this.send(batch);\n this.failureCount = 0;\n } catch {\n // возвращаем батч назад (без dedupe — это задача backend)\n this.queue = [...batch, ...this.queue];\n\n if (this.runtime === \"browser\") {\n this.persist();\n }\n\n this.failureCount++;\n\n if (this.failureCount >= 5) {\n this.circuitOpenUntil = Date.now() + 5000;\n }\n } finally {\n this.inFlight = false;\n }\n }\n\n destroy() {\n this.destroyed = true;\n\n if (this.timer) clearInterval(this.timer);\n\n this.leader?.destroy();\n\n // remove process listeners\n for (const off of this.exitHandlers) {\n off();\n }\n }\n\n // ================= SEND =================\n private async send(events: TrackEvent[]) {\n const payload = JSON.stringify({\n sentAt: new Date().toISOString(),\n sdk: this.sdkInfo,\n events,\n });\n\n if (\n this.runtime === \"browser\" &&\n typeof navigator !== \"undefined\" &&\n navigator.sendBeacon &&\n payload.length < 60000 &&\n document.visibilityState === \"hidden\"\n ) {\n navigator.sendBeacon(this.endpoint, payload);\n return;\n }\n\n let attempt = 0;\n\n while (attempt <= this.retries) {\n try {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), 5000);\n\n const res = await this.fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": this.apiKey,\n },\n body: payload,\n signal: controller.signal,\n });\n\n clearTimeout(timeout);\n\n if (res.status >= 400 && res.status < 500) return;\n if (!res.ok) throw new Error();\n\n return;\n } catch {\n attempt++;\n if (attempt > this.retries) throw new Error();\n await sleep(this.retryDelay * 2 ** attempt);\n }\n }\n }\n\n // ================= INTERNAL =================\n private startTimer() {\n this.timer = setInterval(() => {\n void this.flush();\n }, this.flushInterval);\n }\n\n private setupBrowserExit() {\n const handler = () => {\n if (document.visibilityState === \"hidden\") {\n void this.flush();\n }\n };\n\n window.addEventListener(\"visibilitychange\", handler);\n\n this.exitHandlers.push(() => {\n window.removeEventListener(\"visibilitychange\", handler);\n });\n }\n\n private setupProcessExit() {\n\n const g = globalThis as any;\n\n const flushSafe = async () => {\n try {\n await this.flush();\n } catch {}\n };\n\n const beforeExit = () => {\n void flushSafe();\n };\n\n const sigint = async () => {\n await flushSafe();\n g.exit();\n };\n\n g?.on?.(\"beforeExit\", beforeExit);\n g?.on?.(\"SIGINT\", sigint);\n\n this.exitHandlers.push(() => {\n g?.off?.(\"beforeExit\", beforeExit);\n g?.off?.(\"SIGINT\", sigint);\n });\n }\n\n private persist() {\n if (this.runtime !== \"browser\") return;\n this.storage.set(\"__eventra_q__\", this.queue);\n }\n}\n"],"mappings":";AAKA,SAAS,gBAAyB;AAChC,QAAM,IAAI;AAEV,MAAI,OAAO,WAAW,YAAa,QA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