@stacksee/analytics 0.9.6 → 0.9.8

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.
@@ -13,6 +13,17 @@ export interface UserContext<TTraits extends Record<string, unknown> = Record<st
13
13
  email?: string;
14
14
  traits?: TTraits;
15
15
  }
16
+ /**
17
+ * Server-side context enrichment
18
+ * Used by server analytics to add request-specific metadata
19
+ */
20
+ export interface ServerContext {
21
+ userAgent?: string;
22
+ ip?: string;
23
+ requestId?: string;
24
+ timestamp?: number;
25
+ [key: string]: unknown;
26
+ }
16
27
  export interface EventContext<TTraits extends Record<string, unknown> = Record<string, unknown>> {
17
28
  user?: UserContext<TTraits>;
18
29
  page?: {
@@ -31,6 +42,7 @@ export interface EventContext<TTraits extends Record<string, unknown> = Record<s
31
42
  userAgent?: string;
32
43
  language?: string;
33
44
  timezone?: string;
45
+ ip?: string;
34
46
  screen?: {
35
47
  width?: number;
36
48
  height?: number;
@@ -45,6 +57,7 @@ export interface EventContext<TTraits extends Record<string, unknown> = Record<s
45
57
  medium?: string;
46
58
  name?: string;
47
59
  };
60
+ server?: ServerContext;
48
61
  }
49
62
  export interface AnalyticsProvider {
50
63
  name: string;
@@ -1,16 +1,16 @@
1
- var j = Object.defineProperty;
2
- var q = (d, h, i) => h in d ? j(d, h, { enumerable: !0, configurable: !0, writable: !0, value: i }) : d[h] = i;
3
- var g = (d, h, i) => q(d, typeof h != "symbol" ? h + "" : h, i);
1
+ var q = Object.defineProperty;
2
+ var D = (p, u, i) => u in p ? q(p, u, { enumerable: !0, configurable: !0, writable: !0, value: i }) : p[u] = i;
3
+ var t = (p, u, i) => D(p, typeof u != "symbol" ? u + "" : u, i);
4
4
  import { B as V } from "../base.provider-AfFL5W_P.js";
5
5
  import { P as Q } from "../server-DjEk1fUD.js";
6
- class M extends V {
6
+ class N extends V {
7
7
  constructor(i) {
8
8
  super({ debug: i.debug, enabled: i.enabled });
9
- g(this, "name", "Bento-Server");
10
- g(this, "client");
11
- g(this, "initialized", !1);
12
- g(this, "config");
13
- g(this, "currentUserEmail");
9
+ t(this, "name", "Bento-Server");
10
+ t(this, "client");
11
+ t(this, "initialized", !1);
12
+ t(this, "config");
13
+ t(this, "currentUserEmail");
14
14
  this.config = i;
15
15
  }
16
16
  async initialize() {
@@ -23,8 +23,8 @@ class M extends V {
23
23
  if (!((e = this.config.authentication) != null && e.secretKey) || typeof this.config.authentication.secretKey != "string")
24
24
  throw new Error("Bento requires authentication.secretKey");
25
25
  try {
26
- const { Analytics: r } = await import("../bento-node-sdk.esm-CWEAoj97.js"), { debug: s, enabled: a, ...u } = this.config;
27
- this.client = new r(u), this.initialized = !0, this.log("Initialized successfully", {
26
+ const { Analytics: r } = await import("../bento-node-sdk.esm-CWEAoj97.js"), { debug: h, enabled: s, ...d } = this.config;
27
+ this.client = new r(d), this.initialized = !0, this.log("Initialized successfully", {
28
28
  siteUuid: this.config.siteUuid
29
29
  });
30
30
  } catch (r) {
@@ -43,25 +43,25 @@ class M extends V {
43
43
  return;
44
44
  }
45
45
  this.currentUserEmail = r;
46
- const s = e ? { ...e } : {};
47
- delete s.email, this.client.V1.addSubscriber({
46
+ const h = e ? { ...e } : {};
47
+ delete h.email, this.client.V1.addSubscriber({
48
48
  email: r,
49
- fields: s
50
- }).catch((a) => {
51
- console.error("[Bento-Server] Failed to identify user:", a);
49
+ fields: h
50
+ }).catch((s) => {
51
+ console.error("[Bento-Server] Failed to identify user:", s);
52
52
  }), this.log("Identified user", { userId: i, email: r, traits: e });
53
53
  }
54
54
  async track(i, e) {
55
- var u, l, p, n;
55
+ var d, g, n, l;
56
56
  if (!this.isEnabled() || !this.initialized || !this.client) return;
57
- const r = ((u = e == null ? void 0 : e.user) == null ? void 0 : u.email) || this.currentUserEmail || ((l = e == null ? void 0 : e.user) == null ? void 0 : l.userId) || i.userId;
57
+ const r = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.email) || this.currentUserEmail || ((g = e == null ? void 0 : e.user) == null ? void 0 : g.userId) || i.userId;
58
58
  if (!r || !r.includes("@")) {
59
59
  console.warn(
60
60
  "[Bento-Server] Skipping event - Bento requires an email address. Anonymous events are not currently supported by the Bento Node SDK. For now, use the Bento client provider for anonymous tracking. If you're using a proxy, use the hybrid pattern as described in the docs. For identified users, call identify() with a valid email before tracking events."
61
61
  );
62
62
  return;
63
63
  }
64
- const s = {
64
+ const h = {
65
65
  ...i.properties,
66
66
  category: i.category,
67
67
  timestamp: i.timestamp || Date.now(),
@@ -80,30 +80,30 @@ class M extends V {
80
80
  ...(e == null ? void 0 : e.device) && { device: e.device },
81
81
  ...(e == null ? void 0 : e.utm) && { utm: e.utm },
82
82
  site: this.config.siteUuid,
83
- ...((p = e == null ? void 0 : e.user) == null ? void 0 : p.userId) && { visitor: e.user.userId }
84
- }, a = ((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) || {};
83
+ ...((n = e == null ? void 0 : e.user) == null ? void 0 : n.userId) && { visitor: e.user.userId }
84
+ }, s = ((l = e == null ? void 0 : e.user) == null ? void 0 : l.traits) || {};
85
85
  try {
86
86
  await this.client.V1.track({
87
87
  email: r,
88
88
  type: `$${i.action}`,
89
- details: s,
90
- fields: a
89
+ details: h,
90
+ fields: s
91
91
  }), this.log("Tracked event", { event: i, context: e });
92
- } catch (v) {
93
- console.error("[Bento-Server] Failed to track event:", v);
92
+ } catch (a) {
93
+ console.error("[Bento-Server] Failed to track event:", a);
94
94
  }
95
95
  }
96
96
  pageView(i, e) {
97
- var u, l, p;
97
+ var d, g, n;
98
98
  if (!this.isEnabled() || !this.initialized || !this.client) return;
99
- const r = ((u = e == null ? void 0 : e.user) == null ? void 0 : u.email) || this.currentUserEmail;
99
+ const r = ((d = e == null ? void 0 : e.user) == null ? void 0 : d.email) || this.currentUserEmail;
100
100
  if (!r || !r.includes("@")) {
101
101
  console.warn(
102
102
  "[Bento-Server] Skipping pageView - Bento requires an email address. Anonymous events are not currently supported by the Bento Node SDK. For now, use the Bento client provider for anonymous tracking. If you're using a proxy, use the hybrid pattern as described in the docs. For identified users, call identify() with a valid email before tracking events."
103
103
  );
104
104
  return;
105
105
  }
106
- const s = {
106
+ const h = {
107
107
  ...i,
108
108
  date: (/* @__PURE__ */ new Date()).toISOString(),
109
109
  ...(e == null ? void 0 : e.page) && {
@@ -118,15 +118,15 @@ class M extends V {
118
118
  }
119
119
  },
120
120
  site: this.config.siteUuid,
121
- ...((l = e == null ? void 0 : e.user) == null ? void 0 : l.userId) && { visitor: e.user.userId }
122
- }, a = ((p = e == null ? void 0 : e.user) == null ? void 0 : p.traits) || {};
121
+ ...((g = e == null ? void 0 : e.user) == null ? void 0 : g.userId) && { visitor: e.user.userId }
122
+ }, s = ((n = e == null ? void 0 : e.user) == null ? void 0 : n.traits) || {};
123
123
  this.client.V1.track({
124
124
  email: r,
125
125
  type: "$view",
126
- details: s,
127
- fields: a
128
- }).catch((n) => {
129
- console.error("[Bento-Server] Failed to track page view:", n);
126
+ details: h,
127
+ fields: s
128
+ }).catch((l) => {
129
+ console.error("[Bento-Server] Failed to track page view:", l);
130
130
  }), this.log("Tracked page view", { properties: i, context: e });
131
131
  }
132
132
  async reset() {
@@ -136,32 +136,37 @@ class M extends V {
136
136
  this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
137
137
  }
138
138
  }
139
- class N extends V {
139
+ class W extends V {
140
140
  constructor(i) {
141
141
  super({ debug: i.debug, enabled: i.enabled });
142
- g(this, "name", "Pirsch-Server");
143
- g(this, "client");
144
- g(this, "initialized", !1);
145
- g(this, "config");
142
+ t(this, "name", "Pirsch-Server");
143
+ t(this, "client");
144
+ t(this, "initialized", !1);
145
+ t(this, "config");
146
146
  this.config = i;
147
147
  }
148
148
  async initialize() {
149
- if (this.isEnabled() && !this.initialized) {
150
- if (!this.config.hostname || typeof this.config.hostname != "string")
151
- throw new Error("Pirsch requires a hostname");
152
- if (!this.config.clientSecret || typeof this.config.clientSecret != "string")
153
- throw new Error("Pirsch requires a clientSecret (or access key)");
154
- try {
155
- const { Pirsch: i } = await import("../index-zS7gy63J.js").then((a) => a.i), { debug: e, enabled: r, ...s } = this.config;
156
- this.client = new i(s), this.initialized = !0, this.log("Initialized successfully", {
157
- hostname: this.config.hostname
158
- });
159
- } catch (i) {
160
- throw console.error(
161
- "[Pirsch-Server] Failed to initialize. Make sure pirsch-sdk is installed:",
162
- i
163
- ), i;
164
- }
149
+ if (!this.isEnabled() || this.initialized) return;
150
+ if (!this.config.hostname || typeof this.config.hostname != "string")
151
+ throw new Error("Pirsch requires a hostname");
152
+ if (!this.config.clientSecret || typeof this.config.clientSecret != "string")
153
+ throw new Error("Pirsch requires a clientSecret (or access key)");
154
+ const i = this.config.clientSecret.startsWith("pa_");
155
+ if (!i && !this.config.clientId)
156
+ throw new Error(
157
+ "Pirsch requires a clientId when using OAuth authentication (clientSecret doesn't start with 'pa_'). Either provide a clientId or use an access key (starts with 'pa_') as clientSecret."
158
+ );
159
+ try {
160
+ const { Pirsch: e } = await import("../index-zS7gy63J.js").then((d) => d.i), { debug: r, enabled: h, ...s } = this.config;
161
+ this.client = new e(s), this.initialized = !0, this.log("Initialized successfully", {
162
+ hostname: this.config.hostname,
163
+ authMode: i ? "access-key" : "oauth"
164
+ });
165
+ } catch (e) {
166
+ throw console.error(
167
+ "[Pirsch-Server] Failed to initialize. Make sure pirsch-sdk is installed:",
168
+ e
169
+ ), e;
165
170
  }
166
171
  }
167
172
  identify(i, e) {
@@ -170,34 +175,43 @@ class N extends V {
170
175
  url: "https://identify",
171
176
  ip: "0.0.0.0",
172
177
  user_agent: "analytics-library"
173
- }, s = {
178
+ }, h = {
174
179
  userId: i,
175
180
  ...e && Object.fromEntries(
176
181
  Object.entries(e).filter(
177
- ([, a]) => typeof a == "string" || typeof a == "number" || typeof a == "boolean"
182
+ ([, s]) => typeof s == "string" || typeof s == "number" || typeof s == "boolean"
178
183
  )
179
184
  )
180
185
  };
181
- this.client.event("user_identified", r, 0, s).catch((a) => {
182
- console.error("[Pirsch-Server] Failed to track identify event:", a);
186
+ this.client.event("user_identified", r, 0, h).catch((s) => {
187
+ console.error("[Pirsch-Server] Failed to track identify event:", s);
183
188
  }), this.log("Identified user via event", { userId: i, traits: e });
184
189
  }
185
190
  async track(i, e) {
186
- var v, f, y, t, w, m, b, c, k, S, _, E, I, z, P, B, F, o, $, A, K, O;
191
+ var a, o, f, y, c, w, m, b, S, k, I, _, E, P, z, B, A, F, v, $, K, j, O;
187
192
  if (!this.isEnabled() || !this.initialized || !this.client) return;
188
- const r = e, s = ((v = r == null ? void 0 : r.device) == null ? void 0 : v.ip) || "0.0.0.0", a = ((f = r == null ? void 0 : r.server) == null ? void 0 : f.userAgent) || ((y = r == null ? void 0 : r.device) == null ? void 0 : y.userAgent) || "unknown", l = {
189
- url: ((t = e == null ? void 0 : e.page) == null ? void 0 : t.url) || ((w = e == null ? void 0 : e.page) != null && w.protocol && ((m = e == null ? void 0 : e.page) != null && m.host) && ((b = e == null ? void 0 : e.page) != null && b.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (c = e == null ? void 0 : e.page) != null && c.path ? `https://${this.config.hostname}${e.page.path}` : "https://event"),
190
- ip: s,
191
- user_agent: a,
193
+ const r = e, h = ((a = r == null ? void 0 : r.device) == null ? void 0 : a.ip) || ((o = r == null ? void 0 : r.server) == null ? void 0 : o.ip), s = ((f = r == null ? void 0 : r.server) == null ? void 0 : f.userAgent) || ((y = r == null ? void 0 : r.device) == null ? void 0 : y.userAgent);
194
+ if (!h || !s) {
195
+ this.log("Skipping event - missing required IP or user-agent from context", {
196
+ hasIp: !!h,
197
+ hasUserAgent: !!s,
198
+ event: i.action
199
+ });
200
+ return;
201
+ }
202
+ const g = {
203
+ url: ((c = e == null ? void 0 : e.page) == null ? void 0 : c.url) || ((w = e == null ? void 0 : e.page) != null && w.protocol && ((m = e == null ? void 0 : e.page) != null && m.host) && ((b = e == null ? void 0 : e.page) != null && b.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (S = e == null ? void 0 : e.page) != null && S.path ? `https://${this.config.hostname}${e.page.path}` : "https://event"),
204
+ ip: h,
205
+ user_agent: s,
192
206
  ...((k = e == null ? void 0 : e.page) == null ? void 0 : k.title) && { title: e.page.title },
193
- ...((S = e == null ? void 0 : e.page) == null ? void 0 : S.referrer) && { referrer: e.page.referrer },
207
+ ...((I = e == null ? void 0 : e.page) == null ? void 0 : I.referrer) && { referrer: e.page.referrer },
194
208
  ...((E = (_ = e == null ? void 0 : e.device) == null ? void 0 : _.screen) == null ? void 0 : E.width) && { screen_width: e.device.screen.width },
195
- ...((z = (I = e == null ? void 0 : e.device) == null ? void 0 : I.screen) == null ? void 0 : z.height) && { screen_height: e.device.screen.height },
196
- ...((B = (P = e == null ? void 0 : e.device) == null ? void 0 : P.viewport) == null ? void 0 : B.width) && { sec_ch_viewport_width: String(e.device.viewport.width) },
209
+ ...((z = (P = e == null ? void 0 : e.device) == null ? void 0 : P.screen) == null ? void 0 : z.height) && { screen_height: e.device.screen.height },
210
+ ...((A = (B = e == null ? void 0 : e.device) == null ? void 0 : B.viewport) == null ? void 0 : A.width) && { sec_ch_viewport_width: String(e.device.viewport.width) },
197
211
  ...((F = e == null ? void 0 : e.device) == null ? void 0 : F.language) && { accept_language: e.device.language },
198
- ...((o = e == null ? void 0 : e.device) == null ? void 0 : o.type) && { sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0" },
212
+ ...((v = e == null ? void 0 : e.device) == null ? void 0 : v.type) && { sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0" },
199
213
  ...(($ = e == null ? void 0 : e.device) == null ? void 0 : $.os) && { sec_ch_ua_platform: e.device.os }
200
- }, n = {
214
+ }, l = {
201
215
  ...Object.fromEntries(
202
216
  Object.entries(i.properties).filter(
203
217
  ([, U]) => typeof U == "string" || typeof U == "number" || typeof U == "boolean"
@@ -207,41 +221,49 @@ class N extends V {
207
221
  timestamp: String(i.timestamp || Date.now()),
208
222
  ...i.userId && { userId: i.userId },
209
223
  ...i.sessionId && { sessionId: i.sessionId },
210
- ...((A = e == null ? void 0 : e.user) == null ? void 0 : A.email) && { user_email: e.user.email },
211
- ...((K = e == null ? void 0 : e.device) == null ? void 0 : K.timezone) && { timezone: e.device.timezone },
224
+ ...((K = e == null ? void 0 : e.user) == null ? void 0 : K.email) && { user_email: e.user.email },
225
+ ...((j = e == null ? void 0 : e.device) == null ? void 0 : j.timezone) && { timezone: e.device.timezone },
212
226
  ...((O = e == null ? void 0 : e.device) == null ? void 0 : O.browser) && { browser: e.device.browser }
213
227
  };
214
228
  try {
215
- await this.client.event(i.action, l, 0, n), this.log("Tracked event", { event: i, context: e });
229
+ await this.client.event(i.action, g, 0, l), this.log("Tracked event", { event: i, context: e });
216
230
  } catch (U) {
217
231
  console.error("[Pirsch-Server] Failed to track event:", U);
218
232
  }
219
233
  }
220
234
  pageView(i, e) {
221
- var p, n, v, f, y, t, w, m, b, c, k, S, _, E, I, z, P, B, F;
235
+ var n, l, a, o, f, y, c, w, m, b, S, k, I, _, E, P, z, B, A, F;
222
236
  if (!this.isEnabled() || !this.initialized || !this.client) return;
223
- const r = e, s = ((p = r == null ? void 0 : r.device) == null ? void 0 : p.ip) || "0.0.0.0", a = ((n = r == null ? void 0 : r.server) == null ? void 0 : n.userAgent) || ((v = r == null ? void 0 : r.device) == null ? void 0 : v.userAgent) || "unknown", l = {
224
- url: ((f = e == null ? void 0 : e.page) == null ? void 0 : f.url) || ((y = e == null ? void 0 : e.page) != null && y.protocol && ((t = e == null ? void 0 : e.page) != null && t.host) && ((w = e == null ? void 0 : e.page) != null && w.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (m = e == null ? void 0 : e.page) != null && m.path ? `https://${this.config.hostname}${e.page.path}` : "https://pageview"),
225
- ip: s,
226
- user_agent: a,
237
+ const r = e, h = ((n = r == null ? void 0 : r.device) == null ? void 0 : n.ip) || ((l = r == null ? void 0 : r.server) == null ? void 0 : l.ip), s = ((a = r == null ? void 0 : r.server) == null ? void 0 : a.userAgent) || ((o = r == null ? void 0 : r.device) == null ? void 0 : o.userAgent);
238
+ if (!h || !s) {
239
+ this.log("Skipping pageView - missing required IP or user-agent from context", {
240
+ hasIp: !!h,
241
+ hasUserAgent: !!s
242
+ });
243
+ return;
244
+ }
245
+ const g = {
246
+ url: ((f = e == null ? void 0 : e.page) == null ? void 0 : f.url) || ((y = e == null ? void 0 : e.page) != null && y.protocol && ((c = e == null ? void 0 : e.page) != null && c.host) && ((w = e == null ? void 0 : e.page) != null && w.path) ? `${e.page.protocol}://${e.page.host}${e.page.path}` : (m = e == null ? void 0 : e.page) != null && m.path ? `https://${this.config.hostname}${e.page.path}` : "https://pageview"),
247
+ ip: h,
248
+ user_agent: s,
227
249
  ...((b = e == null ? void 0 : e.page) == null ? void 0 : b.title) && { title: e.page.title },
228
- ...((c = e == null ? void 0 : e.page) == null ? void 0 : c.referrer) && { referrer: e.page.referrer },
229
- ...((S = (k = e == null ? void 0 : e.device) == null ? void 0 : k.screen) == null ? void 0 : S.width) && { screen_width: e.device.screen.width },
250
+ ...((S = e == null ? void 0 : e.page) == null ? void 0 : S.referrer) && { referrer: e.page.referrer },
251
+ ...((I = (k = e == null ? void 0 : e.device) == null ? void 0 : k.screen) == null ? void 0 : I.width) && { screen_width: e.device.screen.width },
230
252
  ...((E = (_ = e == null ? void 0 : e.device) == null ? void 0 : _.screen) == null ? void 0 : E.height) && { screen_height: e.device.screen.height },
231
- ...((z = (I = e == null ? void 0 : e.device) == null ? void 0 : I.viewport) == null ? void 0 : z.width) && { sec_ch_viewport_width: String(e.device.viewport.width) },
232
- ...((P = e == null ? void 0 : e.device) == null ? void 0 : P.language) && { accept_language: e.device.language },
233
- ...((B = e == null ? void 0 : e.device) == null ? void 0 : B.type) && { sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0" },
253
+ ...((z = (P = e == null ? void 0 : e.device) == null ? void 0 : P.viewport) == null ? void 0 : z.width) && { sec_ch_viewport_width: String(e.device.viewport.width) },
254
+ ...((B = e == null ? void 0 : e.device) == null ? void 0 : B.language) && { accept_language: e.device.language },
255
+ ...((A = e == null ? void 0 : e.device) == null ? void 0 : A.type) && { sec_ch_ua_mobile: e.device.type === "mobile" || e.device.type === "tablet" ? "?1" : "?0" },
234
256
  ...((F = e == null ? void 0 : e.device) == null ? void 0 : F.os) && { sec_ch_ua_platform: e.device.os },
235
257
  ...i && {
236
258
  tags: Object.fromEntries(
237
259
  Object.entries(i).filter(
238
- ([, o]) => typeof o == "string" || typeof o == "number" || typeof o == "boolean"
260
+ ([, v]) => typeof v == "string" || typeof v == "number" || typeof v == "boolean"
239
261
  )
240
262
  )
241
263
  }
242
264
  };
243
- this.client.hit(l).catch((o) => {
244
- console.error("[Pirsch-Server] Failed to track page view:", o);
265
+ this.client.hit(g).catch((v) => {
266
+ console.error("[Pirsch-Server] Failed to track page view:", v);
245
267
  }), this.log("Tracked page view", { properties: i, context: e });
246
268
  }
247
269
  async reset() {
@@ -259,68 +281,80 @@ class N extends V {
259
281
  this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
260
282
  }
261
283
  }
262
- async function D(d, h, i) {
263
- var e, r;
284
+ async function R(p, u, i) {
285
+ var e, r, h, s;
264
286
  try {
265
- const s = await d.json();
266
- if (!s.events || !Array.isArray(s.events))
287
+ const d = await p.json();
288
+ if (!d.events || !Array.isArray(d.events))
267
289
  throw new Error("Invalid payload: missing events array");
268
- const a = i != null && i.extractIp ? i.extractIp(d) : R(d), u = i != null && i.enrichContext ? i.enrichContext(d) : {};
269
- for (const l of s.events)
290
+ const g = i != null && i.extractIp ? i.extractIp(p) : T(p), n = p.headers.get("user-agent"), l = i != null && i.enrichContext ? i.enrichContext(p) : {};
291
+ for (const a of d.events)
270
292
  try {
271
- switch (l.type) {
293
+ switch (a.type) {
272
294
  case "track": {
273
- const p = {
274
- ...l.context,
275
- ...u,
295
+ const o = {
296
+ ...a.context,
297
+ ...l,
298
+ server: {
299
+ ...(e = a.context) == null ? void 0 : e.server,
300
+ ...typeof (l == null ? void 0 : l.server) == "object" && l.server !== null ? l.server : {},
301
+ ...n ? { userAgent: n } : {}
302
+ },
276
303
  device: {
277
- ...(e = l.context) == null ? void 0 : e.device,
278
- // Add IP (using type assertion for extended fields)
279
- // biome-ignore lint/suspicious/noExplicitAny: IP field not in base device type
280
- ...a ? { ip: a } : {}
304
+ ...(r = a.context) == null ? void 0 : r.device,
305
+ ...g ? { ip: g } : {}
281
306
  }
282
307
  };
283
- await h.track(l.event.action, l.event.properties, {
284
- userId: l.event.userId,
285
- sessionId: l.event.sessionId,
286
- // biome-ignore lint/suspicious/noExplicitAny: Generic context forwarding requires type assertion
287
- context: p
288
- });
308
+ await u.track(
309
+ a.event.action,
310
+ // biome-ignore lint/suspicious/noExplicitAny: Properties from JSON cannot be type-checked against TEventMap at compile time
311
+ a.event.properties,
312
+ {
313
+ userId: a.event.userId,
314
+ sessionId: a.event.sessionId,
315
+ context: o
316
+ }
317
+ );
289
318
  break;
290
319
  }
291
320
  case "identify": {
292
- h.identify(l.userId, l.traits);
321
+ u.identify(a.userId, a.traits);
293
322
  break;
294
323
  }
295
324
  case "pageView": {
296
- const p = {
297
- ...l.context,
298
- ...u,
325
+ const o = {
326
+ ...a.context,
327
+ ...l,
328
+ server: {
329
+ ...(h = a.context) == null ? void 0 : h.server,
330
+ ...typeof (l == null ? void 0 : l.server) == "object" && l.server !== null ? l.server : {},
331
+ ...n ? { userAgent: n } : {}
332
+ },
299
333
  device: {
300
- ...(r = l.context) == null ? void 0 : r.device,
301
- // biome-ignore lint/suspicious/noExplicitAny: IP field not in base device type
302
- // Add IP (using type assertion for extended fields)
303
- ...a ? { ip: a } : {}
334
+ ...(s = a.context) == null ? void 0 : s.device,
335
+ ...g ? { ip: g } : {}
304
336
  }
305
337
  };
306
- h.pageView(l.properties, p);
338
+ u.pageView(a.properties, {
339
+ context: o
340
+ });
307
341
  break;
308
342
  }
309
343
  case "reset":
310
344
  break;
311
345
  default:
312
- console.warn("[Proxy] Unknown event type:", l);
346
+ console.warn("[Proxy] Unknown event type:", a);
313
347
  }
314
- } catch (p) {
315
- i != null && i.onError ? i.onError(p) : console.error("[Proxy] Failed to process event:", p);
348
+ } catch (o) {
349
+ i != null && i.onError ? i.onError(o) : console.error("[Proxy] Failed to process event:", o);
316
350
  }
317
- } catch (s) {
318
- throw i != null && i.onError ? i.onError(s) : console.error("[Proxy] Failed to ingest events:", s), s;
351
+ } catch (d) {
352
+ throw i != null && i.onError ? i.onError(d) : console.error("[Proxy] Failed to ingest events:", d), d;
319
353
  }
320
354
  }
321
- function R(d) {
355
+ function T(p) {
322
356
  var i;
323
- const h = [
357
+ const u = [
324
358
  "x-forwarded-for",
325
359
  "x-real-ip",
326
360
  "cf-connecting-ip",
@@ -328,16 +362,16 @@ function R(d) {
328
362
  "x-client-ip",
329
363
  "x-cluster-client-ip"
330
364
  ];
331
- for (const e of h) {
332
- const r = d.headers.get(e);
365
+ for (const e of u) {
366
+ const r = p.headers.get(e);
333
367
  if (r)
334
368
  return (i = r.split(",")[0]) == null ? void 0 : i.trim();
335
369
  }
336
370
  }
337
- function G(d, h) {
371
+ function G(p, u) {
338
372
  return async (i) => {
339
373
  try {
340
- return await D(i, d, h), new Response("OK", { status: 200 });
374
+ return await R(i, p, u), new Response("OK", { status: 200 });
341
375
  } catch (e) {
342
376
  return console.error("[Proxy] Handler error:", e), new Response("Internal Server Error", { status: 500 });
343
377
  }
@@ -345,9 +379,9 @@ function G(d, h) {
345
379
  }
346
380
  export {
347
381
  V as BaseAnalyticsProvider,
348
- M as BentoServerProvider,
349
- N as PirschServerProvider,
382
+ N as BentoServerProvider,
383
+ W as PirschServerProvider,
350
384
  Q as PostHogServerProvider,
351
385
  G as createProxyHandler,
352
- D as ingestProxyEvents
386
+ R as ingestProxyEvents
353
387
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacksee/analytics",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "A highly typed, provider-agnostic analytics library for TypeScript applications",
5
5
  "type": "module",
6
6
  "exports": {