@mcp-fe/event-tracker 0.0.12 → 0.0.13

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/index.js CHANGED
@@ -1,4 +1,9 @@
1
1
  class g {
2
+ // Configurable worker script URLs (defaults kept for backward compatibility)
3
+ sharedWorkerUrl = "/mcp-shared-worker.js";
4
+ serviceWorkerUrl = "/mcp-service-worker.js";
5
+ // Backend websocket URL to pass into the worker(s)
6
+ backendWsUrl = "ws://localhost:3001";
2
7
  serviceWorkerRegistration = null;
3
8
  sharedWorker = null;
4
9
  sharedWorkerPort = null;
@@ -6,149 +11,164 @@ class g {
6
11
  pendingAuthToken = null;
7
12
  // connection status subscribers
8
13
  connectionStatusCallbacks = /* @__PURE__ */ new Set();
9
- serviceWorkerMessageHandler = null;
10
14
  // Mutex/promise to prevent concurrent init runs
11
15
  initPromise = null;
12
16
  // Initialize and choose worker implementation (prefer SharedWorker)
17
+ // Accept either a ServiceWorkerRegistration OR WorkerInitOptions to configure URLs
13
18
  async init(e) {
19
+ let r;
20
+ const i = e;
21
+ if (i && typeof i.scope == "string")
22
+ r = e;
23
+ else if (e) {
24
+ const o = e;
25
+ o.sharedWorkerUrl && (this.sharedWorkerUrl = o.sharedWorkerUrl), o.serviceWorkerUrl && (this.serviceWorkerUrl = o.serviceWorkerUrl), o.backendWsUrl && (this.backendWsUrl = o.backendWsUrl);
26
+ }
14
27
  return this.initPromise ? this.initPromise.then(async () => {
15
- e && this.workerType !== "service" && await this.init(e);
28
+ r && this.workerType !== "service" && await this.init(r);
16
29
  }) : (this.initPromise = (async () => {
17
30
  try {
18
- if (e) {
19
- this.serviceWorkerRegistration = e, this.workerType = "service", console.log("[WorkerClient] Using ServiceWorker (explicit registration)"), this.pendingAuthToken && (this.sendAuthTokenToServiceWorker(this.pendingAuthToken), this.pendingAuthToken = null);
20
- return;
21
- }
22
- if (typeof SharedWorker < "u")
31
+ if (r) {
32
+ this.serviceWorkerRegistration = r, this.workerType = "service", console.log(
33
+ "[WorkerClient] Using ServiceWorker (explicit registration)"
34
+ );
23
35
  try {
24
- if (this.sharedWorker = new SharedWorker("/mcp-shared-worker.js", { type: "module" }), this.sharedWorkerPort = this.sharedWorker.port, this.sharedWorkerPort.start(), this.pendingAuthToken && this.sharedWorkerPort)
25
- try {
26
- this.sharedWorkerPort.postMessage({ type: "SET_AUTH_TOKEN", token: this.pendingAuthToken });
27
- } catch (t) {
28
- console.warn("[WorkerClient] Immediate postMessage to SharedWorker failed (will retry after init):", t);
29
- }
30
- this.sharedWorker.onerror = (t) => {
31
- console.error("[WorkerClient] SharedWorker error:", t.message || t.error || t), this.workerType !== "shared" && this.initServiceWorkerFallback().catch((n) => {
32
- console.error("[WorkerClient] Failed to initialize ServiceWorker fallback:", n);
33
- });
34
- }, await new Promise((t, n) => {
35
- let s = !1;
36
- const a = setTimeout(() => {
37
- if (!s) {
38
- const i = this.sharedWorkerPort;
39
- i && (i.onmessage = null), n(new Error("SharedWorker initialization timeout"));
40
- }
41
- }, 2e3), l = this.sharedWorkerPort;
42
- if (!l)
43
- return clearTimeout(a), n(new Error("SharedWorker port not available"));
44
- l.onmessage = (i) => {
45
- try {
46
- const c = i.data;
47
- c && c.type === "CONNECTION_STATUS" && (clearTimeout(a), s = !0, this.workerType = "shared", l.onmessage = null, t());
48
- } catch {
49
- }
50
- };
51
- });
52
- const r = this.sharedWorkerPort;
53
- if (this.pendingAuthToken && r)
54
- try {
55
- r.postMessage({ type: "SET_AUTH_TOKEN", token: this.pendingAuthToken }), this.pendingAuthToken = null;
56
- } catch (t) {
57
- console.error("[WorkerClient] Failed to send pending auth token to SharedWorker:", t);
58
- }
59
- r && (r.onmessage = (t) => {
60
- try {
61
- const n = t.data;
62
- if (n && n.type === "CONNECTION_STATUS") {
63
- const s = !!n.connected;
64
- this.connectionStatusCallbacks.forEach((a) => {
65
- try {
66
- a(s);
67
- } catch {
68
- }
69
- });
70
- }
71
- } catch {
72
- }
73
- }), console.log("[WorkerClient] Using SharedWorker");
74
- return;
75
- } catch (r) {
76
- console.warn("[WorkerClient] SharedWorker not available, falling back to ServiceWorker:", r);
36
+ const n = { type: "INIT", backendUrl: this.backendWsUrl };
37
+ this.pendingAuthToken && (n.token = this.pendingAuthToken), this.serviceWorkerRegistration.active ? this.serviceWorkerRegistration.active.postMessage(n) : "serviceWorker" in navigator && navigator.serviceWorker.controller && navigator.serviceWorker.controller.postMessage(n);
38
+ } catch {
77
39
  }
78
- console.log("this should not be called"), await this.initServiceWorkerFallback(), this.pendingAuthToken && this.workerType === "service" && (this.sendAuthTokenToServiceWorker(this.pendingAuthToken), this.pendingAuthToken = null);
40
+ return;
41
+ }
42
+ if (await this.initSharedWorker()) return;
43
+ await this.initServiceWorkerFallback();
79
44
  } finally {
80
45
  this.initPromise = null;
81
46
  }
82
47
  })(), this.initPromise);
83
48
  }
84
- async initServiceWorkerFallback() {
85
- if (console.log("initServiceWorkerFallback called"), "serviceWorker" in navigator)
86
- try {
87
- const e = await navigator.serviceWorker.getRegistration();
88
- if (e) {
89
- this.serviceWorkerRegistration = e, this.workerType = "service", console.log("[WorkerClient] Using existing ServiceWorker registration");
90
- return;
49
+ async initSharedWorker() {
50
+ if (typeof SharedWorker > "u")
51
+ return !1;
52
+ try {
53
+ this.sharedWorker = new SharedWorker(this.sharedWorkerUrl, {
54
+ type: "module"
55
+ }), this.sharedWorkerPort = this.sharedWorker.port, this.sharedWorkerPort.start(), await new Promise((r, i) => {
56
+ let o = !1;
57
+ const n = setTimeout(() => {
58
+ if (!o) {
59
+ const a = this.sharedWorkerPort;
60
+ a && (a.onmessage = null), i(new Error("SharedWorker initialization timeout"));
61
+ }
62
+ }, 2e3), c = this.sharedWorkerPort;
63
+ if (!c)
64
+ return clearTimeout(n), i(new Error("SharedWorker port not available"));
65
+ c.onmessage = (a) => {
66
+ try {
67
+ const s = a.data;
68
+ s && s.type === "CONNECTION_STATUS" && (clearTimeout(n), o = !0, this.workerType = "shared", c.onmessage = null, r());
69
+ } catch {
70
+ }
71
+ };
72
+ });
73
+ const e = this.sharedWorkerPort;
74
+ if (e) {
75
+ try {
76
+ const r = { type: "INIT", backendUrl: this.backendWsUrl };
77
+ this.pendingAuthToken && (r.token = this.pendingAuthToken), e.postMessage(r), this.pendingAuthToken = null;
78
+ } catch (r) {
79
+ console.warn("[WorkerClient] Failed to send INIT to SharedWorker port:", r);
91
80
  }
92
- const r = await navigator.serviceWorker.register("/mcp-service-worker.js");
93
- this.serviceWorkerRegistration = r, this.workerType = "service", console.log("[WorkerClient] Using ServiceWorker (fallback)"), this.serviceWorkerMessageHandler && (navigator.serviceWorker.removeEventListener("message", this.serviceWorkerMessageHandler), this.serviceWorkerMessageHandler = null), this.serviceWorkerMessageHandler = (t) => {
81
+ e.onmessage = (r) => {
94
82
  try {
95
- const n = t.data;
96
- if (n && n.type === "CONNECTION_STATUS") {
97
- const s = !!n.connected;
98
- this.connectionStatusCallbacks.forEach((a) => {
83
+ const i = r.data;
84
+ if (i && i.type === "CONNECTION_STATUS") {
85
+ const o = !!i.connected;
86
+ this.connectionStatusCallbacks.forEach((n) => {
99
87
  try {
100
- a(s);
88
+ n(o);
101
89
  } catch {
102
90
  }
103
91
  });
104
92
  }
105
93
  } catch {
106
94
  }
107
- }, navigator.serviceWorker.addEventListener("message", this.serviceWorkerMessageHandler);
95
+ };
96
+ }
97
+ return console.log("[WorkerClient] Using SharedWorker"), !0;
98
+ } catch (e) {
99
+ return console.warn(
100
+ "[WorkerClient] SharedWorker not available, falling back to ServiceWorker:",
101
+ e
102
+ ), !1;
103
+ }
104
+ }
105
+ async initServiceWorkerFallback() {
106
+ if ("serviceWorker" in navigator)
107
+ try {
108
+ const e = await navigator.serviceWorker.getRegistration();
109
+ if (e) {
110
+ this.serviceWorkerRegistration = e, this.workerType = "service", console.log(
111
+ "[WorkerClient] Using existing ServiceWorker registration"
112
+ );
113
+ return;
114
+ }
115
+ this.serviceWorkerRegistration = await navigator.serviceWorker.register(
116
+ this.serviceWorkerUrl
117
+ ), this.workerType = "service", console.log("[WorkerClient] Using MCP ServiceWorker (fallback)");
118
+ try {
119
+ const r = { type: "INIT", backendUrl: this.backendWsUrl };
120
+ this.pendingAuthToken && (r.token = this.pendingAuthToken), this.serviceWorkerRegistration.active ? this.serviceWorkerRegistration.active.postMessage(r) : "serviceWorker" in navigator && navigator.serviceWorker.controller && navigator.serviceWorker.controller.postMessage(r), this.pendingAuthToken = null;
121
+ } catch {
122
+ }
108
123
  } catch (e) {
109
- throw console.error("[WorkerClient] Failed to register ServiceWorker:", e), e;
124
+ throw console.error(
125
+ "[WorkerClient] Failed to register ServiceWorker:",
126
+ e
127
+ ), e;
110
128
  }
111
129
  else
112
130
  throw new Error("Neither SharedWorker nor ServiceWorker is supported");
113
131
  }
114
132
  // Low-level request that expects a reply via MessageChannel
115
- async request(e, r, t = 5e3) {
133
+ async request(e, r, i = 5e3) {
116
134
  if (this.workerType === "shared" && this.sharedWorkerPort)
117
- return new Promise((n, s) => {
118
- const a = new MessageChannel(), l = setTimeout(() => {
119
- a.port1.onmessage = null, s(new Error("Request timeout"));
120
- }, t);
121
- a.port1.onmessage = (i) => {
122
- clearTimeout(l), i.data && i.data.success ? n(i.data) : i.data && i.data.success === !1 ? s(new Error(i.data.error || "Worker error")) : n(i.data);
135
+ return new Promise((o, n) => {
136
+ const c = new MessageChannel(), a = setTimeout(() => {
137
+ c.port1.onmessage = null, n(new Error("Request timeout"));
138
+ }, i);
139
+ c.port1.onmessage = (s) => {
140
+ clearTimeout(a), s.data && s.data.success ? o(s.data) : s.data && s.data.success === !1 ? n(new Error(s.data.error || "Worker error")) : o(s.data);
123
141
  };
124
142
  try {
125
- const i = this.sharedWorkerPort;
126
- if (!i)
127
- return clearTimeout(l), s(new Error("SharedWorker port not available"));
128
- i.postMessage({ type: e, ...r || {} }, [a.port2]);
129
- } catch (i) {
130
- clearTimeout(l), s(i instanceof Error ? i : new Error(String(i)));
143
+ const s = this.sharedWorkerPort;
144
+ if (!s)
145
+ return clearTimeout(a), n(new Error("SharedWorker port not available"));
146
+ s.postMessage({ type: e, ...r || {} }, [c.port2]);
147
+ } catch (s) {
148
+ clearTimeout(a), n(s instanceof Error ? s : new Error(String(s)));
131
149
  }
132
150
  });
133
151
  if (this.workerType === "service" && this.serviceWorkerRegistration) {
134
- const n = this.serviceWorkerRegistration;
135
- if (!n) throw new Error("Service worker registration missing");
136
- if (!n.active && (await navigator.serviceWorker.ready, !n.active))
152
+ const o = this.serviceWorkerRegistration;
153
+ if (!o) throw new Error("Service worker registration missing");
154
+ if (!o.active && (await navigator.serviceWorker.ready, !o.active))
137
155
  throw new Error("Service worker not active");
138
- return new Promise((s, a) => {
139
- const l = new MessageChannel(), i = setTimeout(() => {
140
- l.port1.onmessage = null, a(new Error("Request timeout"));
141
- }, t);
142
- l.port1.onmessage = (c) => {
143
- clearTimeout(i), c.data && c.data.success ? s(c.data) : c.data && c.data.success === !1 ? a(new Error(c.data.error || "Worker error")) : s(c.data);
156
+ return new Promise((n, c) => {
157
+ const a = new MessageChannel(), s = setTimeout(() => {
158
+ a.port1.onmessage = null, c(new Error("Request timeout"));
159
+ }, i);
160
+ a.port1.onmessage = (l) => {
161
+ clearTimeout(s), l.data && l.data.success ? n(l.data) : l.data && l.data.success === !1 ? c(new Error(l.data.error || "Worker error")) : n(l.data);
144
162
  };
145
163
  try {
146
- const c = n.active;
147
- if (!c)
148
- return clearTimeout(i), a(new Error("Service worker active instance not available"));
149
- c.postMessage({ type: e, ...r || {} }, [l.port2]);
150
- } catch (c) {
151
- clearTimeout(i), a(c instanceof Error ? c : new Error(String(c)));
164
+ const l = o.active;
165
+ if (!l)
166
+ return clearTimeout(s), c(
167
+ new Error("Service worker active instance not available")
168
+ );
169
+ l.postMessage({ type: e, ...r || {} }, [a.port2]);
170
+ } catch (l) {
171
+ clearTimeout(s), c(l instanceof Error ? l : new Error(String(l)));
152
172
  }
153
173
  });
154
174
  }
@@ -159,44 +179,68 @@ class g {
159
179
  if (this.workerType === "shared" && this.sharedWorkerPort) {
160
180
  try {
161
181
  this.sharedWorkerPort.postMessage({ type: e, ...r || {} });
162
- } catch (t) {
163
- console.error("[WorkerClient] Failed to post to SharedWorker:", t);
182
+ } catch (i) {
183
+ console.error("[WorkerClient] Failed to post to SharedWorker:", i);
164
184
  }
165
185
  return;
166
186
  }
167
187
  if (this.workerType === "service" && this.serviceWorkerRegistration?.active) {
168
188
  try {
169
- this.serviceWorkerRegistration.active.postMessage({ type: e, ...r || {} });
170
- } catch (t) {
171
- console.error("[WorkerClient] Failed to post to ServiceWorker (active):", t);
189
+ this.serviceWorkerRegistration.active.postMessage({
190
+ type: e,
191
+ ...r || {}
192
+ });
193
+ } catch (i) {
194
+ console.error(
195
+ "[WorkerClient] Failed to post to ServiceWorker (active):",
196
+ i
197
+ );
172
198
  }
173
199
  return;
174
200
  }
175
201
  if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
176
202
  try {
177
- navigator.serviceWorker.controller.postMessage({ type: e, ...r || {} });
178
- } catch (t) {
179
- console.error("[WorkerClient] Failed to post to ServiceWorker.controller:", t);
203
+ navigator.serviceWorker.controller.postMessage({
204
+ type: e,
205
+ ...r || {}
206
+ });
207
+ } catch (i) {
208
+ console.error(
209
+ "[WorkerClient] Failed to post to ServiceWorker.controller:",
210
+ i
211
+ );
180
212
  }
181
213
  return;
182
214
  }
183
215
  if (e === "SET_AUTH_TOKEN" && r) {
184
- const t = r.token;
185
- typeof t == "string" && (this.pendingAuthToken = t);
216
+ const i = r.token;
217
+ typeof i == "string" && (this.pendingAuthToken = i);
186
218
  }
187
219
  }
188
220
  sendAuthTokenToServiceWorker(e) {
189
221
  if (this.serviceWorkerRegistration?.active)
190
222
  try {
191
- this.serviceWorkerRegistration.active.postMessage({ type: "SET_AUTH_TOKEN", token: e });
223
+ this.serviceWorkerRegistration.active.postMessage({
224
+ type: "SET_AUTH_TOKEN",
225
+ token: e
226
+ });
192
227
  } catch (r) {
193
- console.error("[WorkerClient] Failed to send auth token to ServiceWorker:", r);
228
+ console.error(
229
+ "[WorkerClient] Failed to send auth token to ServiceWorker:",
230
+ r
231
+ );
194
232
  }
195
233
  else if ("serviceWorker" in navigator && navigator.serviceWorker.controller)
196
234
  try {
197
- navigator.serviceWorker.controller.postMessage({ type: "SET_AUTH_TOKEN", token: e });
235
+ navigator.serviceWorker.controller.postMessage({
236
+ type: "SET_AUTH_TOKEN",
237
+ token: e
238
+ });
198
239
  } catch (r) {
199
- console.error("[WorkerClient] Failed to send auth token to ServiceWorker.controller:", r);
240
+ console.error(
241
+ "[WorkerClient] Failed to send auth token to ServiceWorker.controller:",
242
+ r
243
+ );
200
244
  }
201
245
  else
202
246
  this.pendingAuthToken = e;
@@ -210,8 +254,12 @@ class g {
210
254
  }
211
255
  async getConnectionStatus() {
212
256
  try {
213
- const e = await this.request("GET_CONNECTION_STATUS", void 0, 2e3);
214
- return e && typeof e == "object" && "connected" in e, !!e.connected;
257
+ const e = await this.request(
258
+ "GET_CONNECTION_STATUS",
259
+ void 0,
260
+ 2e3
261
+ );
262
+ return e && typeof e == "object" && "connected" in e ? !!e.connected : !!e?.connected;
215
263
  } catch {
216
264
  return !1;
217
265
  }
@@ -221,80 +269,83 @@ class g {
221
269
  try {
222
270
  this.sharedWorkerPort.postMessage({ type: "SET_AUTH_TOKEN", token: e }), this.pendingAuthToken = null;
223
271
  } catch (r) {
224
- console.error("[WorkerClient] Failed to set auth token on SharedWorker:", r);
272
+ console.error(
273
+ "[WorkerClient] Failed to set auth token on SharedWorker:",
274
+ r
275
+ );
225
276
  }
226
277
  else this.workerType === "service" && (this.sendAuthTokenToServiceWorker(e), this.pendingAuthToken = null);
227
278
  }
228
279
  }
229
- const W = "user-activity-db", p = 1, k = "user-events";
230
- async function v() {
231
- return new Promise((o, e) => {
232
- const r = indexedDB.open(W, p);
233
- r.onerror = () => e(r.error), r.onsuccess = () => o(r.result), r.onupgradeneeded = (t) => {
234
- const n = t.target.result;
235
- if (!n.objectStoreNames.contains(k)) {
236
- const s = n.createObjectStore(k, { keyPath: "id" });
237
- s.createIndex("timestamp", "timestamp", { unique: !1 }), s.createIndex("type", "type", { unique: !1 }), s.createIndex("path", "path", { unique: !1 });
280
+ const W = "user-activity-db", v = 1, k = "user-events";
281
+ async function p() {
282
+ return new Promise((t, e) => {
283
+ const r = indexedDB.open(W, v);
284
+ r.onerror = () => e(r.error), r.onsuccess = () => t(r.result), r.onupgradeneeded = (i) => {
285
+ const o = i.target.result;
286
+ if (!o.objectStoreNames.contains(k)) {
287
+ const n = o.createObjectStore(k, { keyPath: "id" });
288
+ n.createIndex("timestamp", "timestamp", { unique: !1 }), n.createIndex("type", "type", { unique: !1 }), n.createIndex("path", "path", { unique: !1 });
238
289
  }
239
290
  };
240
291
  });
241
292
  }
242
- async function T(o) {
243
- const n = (await v()).transaction([k], "readonly").objectStore(k).index("timestamp");
244
- return new Promise((s, a) => {
245
- const l = n.getAll();
246
- l.onsuccess = () => {
247
- let i = l.result;
248
- i.sort((c, d) => d.timestamp - c.timestamp), s(i);
249
- }, l.onerror = () => a(l.error);
293
+ async function f(t) {
294
+ const o = (await p()).transaction([k], "readonly").objectStore(k).index("timestamp");
295
+ return new Promise((n, c) => {
296
+ const a = o.getAll();
297
+ a.onsuccess = () => {
298
+ let s = a.result;
299
+ s.sort((l, d) => d.timestamp - l.timestamp), n(s);
300
+ }, a.onerror = () => c(a.error);
250
301
  });
251
302
  }
252
303
  const h = new g();
253
- async function f(o) {
254
- return h.init(o);
304
+ async function T(t) {
305
+ return h.init(t);
255
306
  }
256
- async function u(o) {
257
- const e = { ...o, timestamp: Date.now() };
307
+ async function u(t) {
308
+ const e = { ...t, timestamp: Date.now() };
258
309
  await h.request("STORE_EVENT", { event: e });
259
310
  }
260
311
  async function m() {
261
- const o = await T();
262
- return Array.isArray(o) ? o : [];
312
+ const t = await f();
313
+ return Array.isArray(t) ? t : [];
263
314
  }
264
- async function S() {
315
+ async function w() {
265
316
  return h.getConnectionStatus();
266
317
  }
267
- function w(o) {
268
- h.setAuthToken(o);
318
+ function y(t) {
319
+ h.setAuthToken(t);
269
320
  }
270
- function y(o) {
271
- h.onConnectionStatus(o);
321
+ function S(t) {
322
+ h.onConnectionStatus(t);
272
323
  }
273
- function C(o) {
274
- h.offConnectionStatus(o);
324
+ function C(t) {
325
+ h.offConnectionStatus(t);
275
326
  }
276
- async function E(o, e, r) {
277
- return u({ type: "navigation", from: o, to: e, path: r || e });
327
+ async function E(t, e, r) {
328
+ return u({ type: "navigation", from: t, to: e, path: r || e });
278
329
  }
279
- async function A(o, e, r) {
280
- const t = o.id || void 0, n = o.className || void 0, s = o.textContent?.trim().substring(0, 100) || void 0, a = o.tagName.toLowerCase();
330
+ async function b(t, e, r) {
331
+ const i = t.id || void 0, o = t.className || void 0, n = t.textContent?.trim().substring(0, 100) || void 0, c = t.tagName.toLowerCase();
281
332
  return u({
282
333
  type: "click",
283
- element: a,
284
- elementId: t,
285
- elementClass: n,
286
- elementText: s,
334
+ element: c,
335
+ elementId: i,
336
+ elementClass: o,
337
+ elementText: n,
287
338
  path: e || window.location.pathname,
288
339
  metadata: r
289
340
  });
290
341
  }
291
- async function N(o, e, r) {
292
- const t = o.id || void 0, n = o.className || void 0, s = o.tagName.toLowerCase();
342
+ async function A(t, e, r) {
343
+ const i = t.id || void 0, o = t.className || void 0, n = t.tagName.toLowerCase();
293
344
  return u({
294
345
  type: "input",
295
- element: s,
296
- elementId: t,
297
- elementClass: n,
346
+ element: n,
347
+ elementId: i,
348
+ elementClass: o,
298
349
  path: r || window.location.pathname,
299
350
  metadata: {
300
351
  valueLength: e?.length || 0,
@@ -302,26 +353,26 @@ async function N(o, e, r) {
302
353
  }
303
354
  });
304
355
  }
305
- async function b(o, e, r) {
356
+ async function N(t, e, r) {
306
357
  return u({
307
358
  type: "custom",
308
359
  path: r || window.location.pathname,
309
360
  metadata: {
310
- eventName: o,
361
+ eventName: t,
311
362
  ...e
312
363
  }
313
364
  });
314
365
  }
315
366
  export {
316
- S as getConnectionStatus,
367
+ w as getConnectionStatus,
317
368
  m as getStoredEvents,
318
- f as initEventTracker,
369
+ T as initEventTracker,
319
370
  C as offConnectionStatus,
320
- y as onConnectionStatus,
321
- w as setAuthToken,
322
- A as trackClick,
323
- b as trackCustom,
371
+ S as onConnectionStatus,
372
+ y as setAuthToken,
373
+ b as trackClick,
374
+ N as trackCustom,
324
375
  u as trackEvent,
325
- N as trackInput,
376
+ A as trackInput,
326
377
  E as trackNavigation
327
378
  };
@@ -1,5 +1,5 @@
1
- import { UserEvent } from '@mcp-fe/mcp-worker';
2
- export type { UserEvent } from '@mcp-fe/mcp-worker';
1
+ import { UserEvent, WorkerClientInitOptions } from '@mcp-fe/mcp-worker';
2
+ export type { UserEvent, WorkerClientInitOptions } from '@mcp-fe/mcp-worker';
3
3
  export interface UserEventData {
4
4
  type: 'navigation' | 'click' | 'input' | 'custom';
5
5
  path?: string;
@@ -11,7 +11,7 @@ export interface UserEventData {
11
11
  elementText?: string;
12
12
  metadata?: Record<string, unknown>;
13
13
  }
14
- export declare function initEventTracker(registration?: ServiceWorkerRegistration): Promise<void>;
14
+ export declare function initEventTracker(registrationOrOptions?: ServiceWorkerRegistration | WorkerClientInitOptions): Promise<void>;
15
15
  export declare function trackEvent(event: UserEventData): Promise<void>;
16
16
  export declare function getStoredEvents(): Promise<UserEvent[]>;
17
17
  export declare function getConnectionStatus(): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"event-tracker.d.ts","sourceRoot":"","sources":["../../../../libs/event-tracker/src/lib/event-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAgB,MAAM,oBAAoB,CAAC;AAC/E,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAA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,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAEzE;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAE1E;AAGD,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5F;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAevH;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBnG;AAED,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CASrH"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mcp-fe/event-tracker",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./index.js",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
- "@mcp-fe/mcp-worker": "0.0.12"
9
+ "@mcp-fe/mcp-worker": "0.0.13"
10
10
  },
11
11
  "publishConfig": {
12
12
  "access": "public"