@stacksee/analytics 0.5.0 → 0.8.0

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.
@@ -0,0 +1,64 @@
1
+ import { BaseEvent, EventContext } from '../../core/events/types.js';
2
+ /**
3
+ * Proxy event types for batching and sending to server
4
+ */
5
+ export type ProxyTrackEvent = {
6
+ type: "track";
7
+ event: BaseEvent;
8
+ context?: EventContext;
9
+ };
10
+ export type ProxyIdentifyEvent = {
11
+ type: "identify";
12
+ userId: string;
13
+ traits?: Record<string, unknown>;
14
+ };
15
+ export type ProxyPageViewEvent = {
16
+ type: "pageView";
17
+ properties?: Record<string, unknown>;
18
+ context?: EventContext;
19
+ };
20
+ export type ProxyResetEvent = {
21
+ type: "reset";
22
+ };
23
+ export type ProxyEvent = ProxyTrackEvent | ProxyIdentifyEvent | ProxyPageViewEvent | ProxyResetEvent;
24
+ /**
25
+ * Payload sent to the proxy endpoint
26
+ */
27
+ export interface ProxyPayload {
28
+ events: ProxyEvent[];
29
+ }
30
+ /**
31
+ * Configuration for batching behavior
32
+ */
33
+ export interface ProxyBatchConfig {
34
+ /**
35
+ * Maximum number of events before auto-flush
36
+ * @default 10
37
+ */
38
+ size?: number;
39
+ /**
40
+ * Maximum time in ms before auto-flush
41
+ * @default 5000
42
+ */
43
+ interval?: number;
44
+ }
45
+ /**
46
+ * Configuration for retry behavior
47
+ */
48
+ export interface ProxyRetryConfig {
49
+ /**
50
+ * Maximum retry attempts
51
+ * @default 3
52
+ */
53
+ attempts?: number;
54
+ /**
55
+ * Backoff strategy
56
+ * @default 'exponential'
57
+ */
58
+ backoff?: "exponential" | "linear";
59
+ /**
60
+ * Initial delay in ms
61
+ * @default 1000
62
+ */
63
+ initialDelay?: number;
64
+ }
@@ -1,3 +1,9 @@
1
1
  export { BaseAnalyticsProvider } from './base.provider.js';
2
2
  export { PostHogServerProvider } from './posthog/server.js';
3
3
  export type { PostHogOptions } from 'posthog-node';
4
+ export { BentoServerProvider } from './bento/server.js';
5
+ export type { BentoServerConfig, BentoAnalyticsOptions } from './bento/server.js';
6
+ export { PirschServerProvider } from './pirsch/server.js';
7
+ export type { PirschServerConfig } from './pirsch/server.js';
8
+ export { ingestProxyEvents, createProxyHandler } from './proxy/server.js';
9
+ export type { IngestProxyEventsConfig } from './proxy/server.js';
@@ -1,6 +1,307 @@
1
- import { B as e } from "../base.provider-AfFL5W_P.js";
2
- import { P as a } from "../server-DjEk1fUD.js";
1
+ var f = Object.defineProperty;
2
+ var y = (l, n, i) => n in l ? f(l, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : l[n] = i;
3
+ var d = (l, n, i) => y(l, typeof n != "symbol" ? n + "" : n, i);
4
+ import { B as p } from "../base.provider-AfFL5W_P.js";
5
+ import { P as z } from "../server-DjEk1fUD.js";
6
+ class v extends p {
7
+ constructor(i) {
8
+ super({ debug: i.debug, enabled: i.enabled });
9
+ d(this, "name", "Bento-Server");
10
+ d(this, "client");
11
+ d(this, "initialized", !1);
12
+ d(this, "config");
13
+ d(this, "currentUserEmail");
14
+ this.config = i;
15
+ }
16
+ async initialize() {
17
+ var i, e;
18
+ if (this.isEnabled() && !this.initialized) {
19
+ if (!this.config.siteUuid || typeof this.config.siteUuid != "string")
20
+ throw new Error("Bento requires a siteUuid");
21
+ if (!((i = this.config.authentication) != null && i.publishableKey) || typeof this.config.authentication.publishableKey != "string")
22
+ throw new Error("Bento requires authentication.publishableKey");
23
+ if (!((e = this.config.authentication) != null && e.secretKey) || typeof this.config.authentication.secretKey != "string")
24
+ throw new Error("Bento requires authentication.secretKey");
25
+ try {
26
+ const { Analytics: s } = await import("../bento-node-sdk.esm-C4HG7SVz.js"), { debug: a, enabled: t, ...o } = this.config;
27
+ this.client = new s(o), this.initialized = !0, this.log("Initialized successfully", {
28
+ siteUuid: this.config.siteUuid
29
+ });
30
+ } catch (s) {
31
+ throw console.error(
32
+ "[Bento-Server] Failed to initialize. Make sure @bentonow/bento-node-sdk is installed:",
33
+ s
34
+ ), s;
35
+ }
36
+ }
37
+ }
38
+ identify(i, e) {
39
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
40
+ const s = (e == null ? void 0 : e.email) || i;
41
+ this.currentUserEmail = s;
42
+ const a = e ? { ...e } : {};
43
+ delete a.email, this.client.V1.addSubscriber({
44
+ email: s,
45
+ fields: a
46
+ }).catch((t) => {
47
+ console.error("[Bento-Server] Failed to identify user:", t);
48
+ }), this.log("Identified user", { userId: i, email: s, traits: e });
49
+ }
50
+ async track(i, e) {
51
+ var o, r, h;
52
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
53
+ const s = ((o = e == null ? void 0 : e.user) == null ? void 0 : o.email) || this.currentUserEmail || ((r = e == null ? void 0 : e.user) == null ? void 0 : r.userId) || i.userId || "anonymous@unknown.com", a = {
54
+ ...i.properties,
55
+ category: i.category,
56
+ timestamp: i.timestamp || Date.now(),
57
+ ...i.sessionId && { sessionId: i.sessionId },
58
+ ...(e == null ? void 0 : e.page) && {
59
+ page: {
60
+ path: e.page.path,
61
+ title: e.page.title,
62
+ referrer: e.page.referrer
63
+ }
64
+ },
65
+ ...(e == null ? void 0 : e.device) && { device: e.device },
66
+ ...(e == null ? void 0 : e.utm) && { utm: e.utm }
67
+ }, t = ((h = e == null ? void 0 : e.user) == null ? void 0 : h.traits) || {};
68
+ try {
69
+ await this.client.V1.track({
70
+ email: s,
71
+ type: `$${i.action}`,
72
+ details: a,
73
+ fields: t
74
+ }), this.log("Tracked event", { event: i, context: e });
75
+ } catch (u) {
76
+ console.error("[Bento-Server] Failed to track event:", u);
77
+ }
78
+ }
79
+ pageView(i, e) {
80
+ var o, r;
81
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
82
+ const s = ((o = e == null ? void 0 : e.user) == null ? void 0 : o.email) || this.currentUserEmail || "anonymous@unknown.com", a = {
83
+ ...i,
84
+ ...(e == null ? void 0 : e.page) && {
85
+ path: e.page.path,
86
+ title: e.page.title,
87
+ referrer: e.page.referrer
88
+ }
89
+ }, t = ((r = e == null ? void 0 : e.user) == null ? void 0 : r.traits) || {};
90
+ this.client.V1.track({
91
+ email: s,
92
+ type: "$pageview",
93
+ details: a,
94
+ fields: t
95
+ }).catch((h) => {
96
+ console.error("[Bento-Server] Failed to track page view:", h);
97
+ }), this.log("Tracked page view", { properties: i, context: e });
98
+ }
99
+ async reset() {
100
+ !this.isEnabled() || !this.initialized || !this.client || (this.currentUserEmail = void 0, this.log("Reset user session"));
101
+ }
102
+ async shutdown() {
103
+ this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
104
+ }
105
+ }
106
+ class E extends p {
107
+ constructor(i) {
108
+ super({ debug: i.debug, enabled: i.enabled });
109
+ d(this, "name", "Pirsch-Server");
110
+ d(this, "client");
111
+ d(this, "initialized", !1);
112
+ d(this, "config");
113
+ this.config = i;
114
+ }
115
+ async initialize() {
116
+ if (this.isEnabled() && !this.initialized) {
117
+ if (!this.config.hostname || typeof this.config.hostname != "string")
118
+ throw new Error("Pirsch requires a hostname");
119
+ if (!this.config.clientSecret || typeof this.config.clientSecret != "string")
120
+ throw new Error("Pirsch requires a clientSecret (or access key)");
121
+ try {
122
+ const { Pirsch: i } = await import("../index-bgxxv-IJ.js").then((t) => t.i), { debug: e, enabled: s, ...a } = this.config;
123
+ this.client = new i(a), this.initialized = !0, this.log("Initialized successfully", {
124
+ hostname: this.config.hostname
125
+ });
126
+ } catch (i) {
127
+ throw console.error(
128
+ "[Pirsch-Server] Failed to initialize. Make sure pirsch-sdk is installed:",
129
+ i
130
+ ), i;
131
+ }
132
+ }
133
+ }
134
+ identify(i, e) {
135
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
136
+ const s = {
137
+ url: "https://identify",
138
+ ip: "0.0.0.0",
139
+ user_agent: "analytics-library"
140
+ }, a = {
141
+ userId: i,
142
+ ...e && Object.fromEntries(
143
+ Object.entries(e).filter(
144
+ ([, t]) => typeof t == "string" || typeof t == "number" || typeof t == "boolean"
145
+ )
146
+ )
147
+ };
148
+ this.client.event("user_identified", s, 0, a).catch((t) => {
149
+ console.error("[Pirsch-Server] Failed to track identify event:", t);
150
+ }), this.log("Identified user via event", { userId: i, traits: e });
151
+ }
152
+ async track(i, e) {
153
+ var o, r, h, u;
154
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
155
+ const s = {
156
+ url: ((o = e == null ? void 0 : e.page) == null ? void 0 : o.path) || "https://event",
157
+ ip: "0.0.0.0",
158
+ // Server-side should provide real IP if available
159
+ user_agent: "analytics-library",
160
+ // Server-side should provide real UA if available
161
+ ...((r = e == null ? void 0 : e.page) == null ? void 0 : r.title) && { title: e.page.title },
162
+ ...((h = e == null ? void 0 : e.page) == null ? void 0 : h.referrer) && { referrer: e.page.referrer }
163
+ }, t = {
164
+ ...Object.fromEntries(
165
+ Object.entries(i.properties).filter(
166
+ ([, c]) => typeof c == "string" || typeof c == "number" || typeof c == "boolean"
167
+ )
168
+ ),
169
+ category: i.category,
170
+ timestamp: String(i.timestamp || Date.now()),
171
+ ...i.userId && { userId: i.userId },
172
+ ...i.sessionId && { sessionId: i.sessionId },
173
+ ...((u = e == null ? void 0 : e.user) == null ? void 0 : u.email) && { user_email: e.user.email }
174
+ };
175
+ try {
176
+ await this.client.event(i.action, s, 0, t), this.log("Tracked event", { event: i, context: e });
177
+ } catch (c) {
178
+ console.error("[Pirsch-Server] Failed to track event:", c);
179
+ }
180
+ }
181
+ pageView(i, e) {
182
+ var a, t, o;
183
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
184
+ const s = {
185
+ url: ((a = e == null ? void 0 : e.page) == null ? void 0 : a.path) || "https://pageview",
186
+ ip: "0.0.0.0",
187
+ // Server-side should provide real IP if available
188
+ user_agent: "analytics-library",
189
+ // Server-side should provide real UA if available
190
+ ...((t = e == null ? void 0 : e.page) == null ? void 0 : t.title) && { title: e.page.title },
191
+ ...((o = e == null ? void 0 : e.page) == null ? void 0 : o.referrer) && { referrer: e.page.referrer },
192
+ ...i && {
193
+ tags: Object.fromEntries(
194
+ Object.entries(i).filter(
195
+ ([, r]) => typeof r == "string" || typeof r == "number" || typeof r == "boolean"
196
+ )
197
+ )
198
+ }
199
+ };
200
+ this.client.hit(s).catch((r) => {
201
+ console.error("[Pirsch-Server] Failed to track page view:", r);
202
+ }), this.log("Tracked page view", { properties: i, context: e });
203
+ }
204
+ async reset() {
205
+ if (!this.isEnabled() || !this.initialized || !this.client) return;
206
+ const i = {
207
+ url: "https://session-reset",
208
+ ip: "0.0.0.0",
209
+ user_agent: "analytics-library"
210
+ };
211
+ await this.client.event("session_reset", i, 0, {}).catch((e) => {
212
+ console.error("[Pirsch-Server] Failed to track session reset:", e);
213
+ }), this.log("Reset user session");
214
+ }
215
+ async shutdown() {
216
+ this.client = void 0, this.initialized = !1, this.log("Shutdown complete");
217
+ }
218
+ }
219
+ async function g(l, n, i) {
220
+ var e, s;
221
+ try {
222
+ const a = await l.json();
223
+ if (!a.events || !Array.isArray(a.events))
224
+ throw new Error("Invalid payload: missing events array");
225
+ const t = i != null && i.extractIp ? i.extractIp(l) : m(l), o = i != null && i.enrichContext ? i.enrichContext(l) : {};
226
+ for (const r of a.events)
227
+ try {
228
+ switch (r.type) {
229
+ case "track": {
230
+ const h = {
231
+ ...r.context,
232
+ ...o,
233
+ device: {
234
+ ...(e = r.context) == null ? void 0 : e.device,
235
+ // Add IP (using type assertion for extended fields)
236
+ ...t ? { ip: t } : {}
237
+ }
238
+ };
239
+ await n.track(r.event.action, r.event.properties, {
240
+ userId: r.event.userId,
241
+ sessionId: r.event.sessionId,
242
+ context: h
243
+ });
244
+ break;
245
+ }
246
+ case "identify": {
247
+ n.identify(r.userId, r.traits);
248
+ break;
249
+ }
250
+ case "pageView": {
251
+ const h = {
252
+ ...r.context,
253
+ ...o,
254
+ device: {
255
+ ...(s = r.context) == null ? void 0 : s.device,
256
+ // Add IP (using type assertion for extended fields)
257
+ ...t ? { ip: t } : {}
258
+ }
259
+ };
260
+ n.pageView(r.properties, h);
261
+ break;
262
+ }
263
+ case "reset":
264
+ break;
265
+ default:
266
+ console.warn("[Proxy] Unknown event type:", r);
267
+ }
268
+ } catch (h) {
269
+ i != null && i.onError ? i.onError(h) : console.error("[Proxy] Failed to process event:", h);
270
+ }
271
+ } catch (a) {
272
+ throw i != null && i.onError ? i.onError(a) : console.error("[Proxy] Failed to ingest events:", a), a;
273
+ }
274
+ }
275
+ function m(l) {
276
+ var i;
277
+ const n = [
278
+ "x-forwarded-for",
279
+ "x-real-ip",
280
+ "cf-connecting-ip",
281
+ // Cloudflare
282
+ "x-client-ip",
283
+ "x-cluster-client-ip"
284
+ ];
285
+ for (const e of n) {
286
+ const s = l.headers.get(e);
287
+ if (s)
288
+ return (i = s.split(",")[0]) == null ? void 0 : i.trim();
289
+ }
290
+ }
291
+ function k(l, n) {
292
+ return async (i) => {
293
+ try {
294
+ return await g(i, l, n), new Response("OK", { status: 200 });
295
+ } catch (e) {
296
+ return console.error("[Proxy] Handler error:", e), new Response("Internal Server Error", { status: 500 });
297
+ }
298
+ };
299
+ }
3
300
  export {
4
- e as BaseAnalyticsProvider,
5
- a as PostHogServerProvider
301
+ p as BaseAnalyticsProvider,
302
+ v as BentoServerProvider,
303
+ E as PirschServerProvider,
304
+ z as PostHogServerProvider,
305
+ k as createProxyHandler,
306
+ g as ingestProxyEvents
6
307
  };
@@ -0,0 +1,220 @@
1
+ import { r as O, a as P, b as E } from "./axios-gULqh8dv.js";
2
+ function j(f, p) {
3
+ for (var d = 0; d < p.length; d++) {
4
+ const o = p[d];
5
+ if (typeof o != "string" && !Array.isArray(o)) {
6
+ for (const a in o)
7
+ if (a !== "default" && !(a in f)) {
8
+ const u = Object.getOwnPropertyDescriptor(o, a);
9
+ u && Object.defineProperty(f, a, u.get ? u : {
10
+ enumerable: !0,
11
+ get: () => o[a]
12
+ });
13
+ }
14
+ }
15
+ }
16
+ return Object.freeze(Object.defineProperty(f, Symbol.toStringTag, { value: "Module" }));
17
+ }
18
+ var r = {}, w;
19
+ function C() {
20
+ if (w) return r;
21
+ w = 1;
22
+ var f = r && r.__createBinding || (Object.create ? function(c, e, t, n) {
23
+ n === void 0 && (n = t);
24
+ var i = Object.getOwnPropertyDescriptor(e, t);
25
+ (!i || ("get" in i ? !e.__esModule : i.writable || i.configurable)) && (i = { enumerable: !0, get: function() {
26
+ return e[t];
27
+ } }), Object.defineProperty(c, n, i);
28
+ } : function(c, e, t, n) {
29
+ n === void 0 && (n = t), c[n] = e[t];
30
+ }), p = r && r.__setModuleDefault || (Object.create ? function(c, e) {
31
+ Object.defineProperty(c, "default", { enumerable: !0, value: e });
32
+ } : function(c, e) {
33
+ c.default = e;
34
+ }), d = r && r.__importStar || /* @__PURE__ */ function() {
35
+ var c = function(e) {
36
+ return c = Object.getOwnPropertyNames || function(t) {
37
+ var n = [];
38
+ for (var i in t) Object.prototype.hasOwnProperty.call(t, i) && (n[n.length] = i);
39
+ return n;
40
+ }, c(e);
41
+ };
42
+ return function(e) {
43
+ if (e && e.__esModule) return e;
44
+ var t = {};
45
+ if (e != null) for (var n = c(e), i = 0; i < n.length; i++) n[i] !== "default" && f(t, e, n[i]);
46
+ return p(t, e), t;
47
+ };
48
+ }(), o = r && r.__awaiter || function(c, e, t, n) {
49
+ function i(s) {
50
+ return s instanceof t ? s : new t(function(l) {
51
+ l(s);
52
+ });
53
+ }
54
+ return new (t || (t = Promise))(function(s, l) {
55
+ function g(h) {
56
+ try {
57
+ b(n.next(h));
58
+ } catch (v) {
59
+ l(v);
60
+ }
61
+ }
62
+ function y(h) {
63
+ try {
64
+ b(n.throw(h));
65
+ } catch (v) {
66
+ l(v);
67
+ }
68
+ }
69
+ function b(h) {
70
+ h.done ? s(h.value) : i(h.value).then(g, y);
71
+ }
72
+ b((n = n.apply(c, e || [])).next());
73
+ });
74
+ };
75
+ Object.defineProperty(r, "__esModule", { value: !0 }), r.Client = r.Pirsch = r.PirschWebClient = void 0;
76
+ const a = O(), u = P(), m = d(/* @__PURE__ */ E());
77
+ class _ extends a.PirschCommon {
78
+ /**
79
+ * The constructor creates a new client.
80
+ *
81
+ * @param {object} configuration You need to pass in the **Identification Code** you have configured on the Pirsch dashboard.
82
+ * It's also recommended to set the proper protocol for your website, else it will be set to `https` by default.
83
+ * All other configuration parameters can be left to their defaults.
84
+ * @param {string} configuration.baseUrl The base URL for the pirsch API
85
+ * @param {number} configuration.timeout The default HTTP timeout in milliseconds
86
+ * @param {string} configuration.identificationCode The identification code
87
+ * @param {string} configuration.hostname The hostname to rewrite the URL. Usually only required for testing
88
+ *
89
+ */
90
+ constructor(e) {
91
+ if (super(), "clientId" in e || "clientSecret" in e)
92
+ throw new Error("Do not pass OAuth secrets such as 'clientId' or 'clientSecret' to the web client!");
93
+ if ("accessToken" in e)
94
+ throw new Error("Do not pass secrets such as 'accessToken' to the web client!");
95
+ const { baseUrl: t = u.PIRSCH_DEFAULT_BASE_URL, timeout: n = u.PIRSCH_DEFAULT_TIMEOUT, identificationCode: i, hostname: s } = e;
96
+ this.assertIdentificationCodeCredentials({ identificationCode: i }), this.baseUrl = t, this.timeout = n, this.identificationCode = i, this.hostname = s, this.httpClient = m.default.create({ baseURL: this.baseUrl, timeout: this.timeout });
97
+ }
98
+ /**
99
+ * hit sends a hit to Pirsch.
100
+ *
101
+ * @param hit optional override data for the request.
102
+ */
103
+ hit(e) {
104
+ return o(this, void 0, void 0, function* () {
105
+ const t = Object.assign(Object.assign({}, this.hitFromBrowser()), e), n = this.browserHitToGetParameters(t);
106
+ yield this.get(u.PirschEndpoint.HIT, { parameters: n });
107
+ });
108
+ }
109
+ /**
110
+ * event sends an event to Pirsch.
111
+ *
112
+ * @param name the name for the event
113
+ * @param duration optional duration for the event
114
+ * @param meta optional object containing metadata (only scalar values, like strings, numbers, and booleans)
115
+ * @param hit optional override data for the request
116
+ */
117
+ event(e) {
118
+ return o(this, arguments, void 0, function* (t, n = 0, i, s) {
119
+ const l = Object.assign(Object.assign({}, this.hitFromBrowser()), s);
120
+ return this.beacon(u.PirschEndpoint.EVENT, Object.assign({ identification_code: this.identificationCode, event_name: t, event_duration: n, event_meta: this.prepareScalarObject(i) }, l)), Promise.resolve();
121
+ });
122
+ }
123
+ /**
124
+ * customHit sends a hit to Pirsch.
125
+ *
126
+ * @param hit data for the request.
127
+ */
128
+ customHit(e) {
129
+ return o(this, void 0, void 0, function* () {
130
+ const t = this.browserHitToGetParameters(e);
131
+ yield this.get(u.PirschEndpoint.HIT, { parameters: t });
132
+ });
133
+ }
134
+ /**
135
+ * customEvent sends an event to Pirsch.
136
+ *
137
+ * @param name the name for the event
138
+ * @param duration optional duration for the event
139
+ * @param hit data for the request
140
+ * @param meta optional object containing metadata (only scalar values, like strings, numbers, and booleans)
141
+ */
142
+ customEvent(e) {
143
+ return o(this, arguments, void 0, function* (t, n = 0, i, s) {
144
+ return this.beacon(u.PirschEndpoint.EVENT, Object.assign({ identification_code: this.identificationCode, event_name: t, event_duration: n, event_meta: this.prepareScalarObject(s) }, i)), Promise.resolve();
145
+ });
146
+ }
147
+ /**
148
+ * hitFromBrowser returns the required data to send a hit to Pirsch.
149
+ *
150
+ * @returns Hit object containing all necessary fields.
151
+ */
152
+ hitFromBrowser() {
153
+ return {
154
+ url: this.generateUrl(),
155
+ title: document.title,
156
+ referrer: document.referrer,
157
+ screen_width: screen.width,
158
+ screen_height: screen.height
159
+ };
160
+ }
161
+ browserHitToGetParameters(e) {
162
+ const t = {
163
+ nc: Date.now(),
164
+ code: this.identificationCode,
165
+ url: e.url
166
+ };
167
+ if (e.title && (t.t = e.title), e.referrer && (t.ref = e.referrer), e.screen_width && (t.w = e.screen_width), e.screen_height && (t.h = e.screen_height), e.tags)
168
+ for (const [n, i] of Object.entries(e.tags))
169
+ t[`tag_${n.replaceAll("-", " ")}`] = i || 1;
170
+ return t;
171
+ }
172
+ generateUrl() {
173
+ return (this.hostname ? location.href.replace(location.hostname, this.hostname) : location.href).slice(0, u.PIRSCH_URL_LENGTH_LIMIT);
174
+ }
175
+ get(e, t) {
176
+ return o(this, void 0, void 0, function* () {
177
+ try {
178
+ return (yield this.httpClient.get(e, this.createOptions(Object.assign({}, t)))).data;
179
+ } catch (n) {
180
+ throw yield this.toApiError(n);
181
+ }
182
+ });
183
+ }
184
+ post(e, t, n) {
185
+ return o(this, void 0, void 0, function* () {
186
+ try {
187
+ return (yield this.httpClient.post(e, t, this.createOptions(n ?? {}))).data;
188
+ } catch (i) {
189
+ throw yield this.toApiError(i);
190
+ }
191
+ });
192
+ }
193
+ beacon(e, t) {
194
+ return o(this, void 0, void 0, function* () {
195
+ if (!navigator.sendBeacon([this.baseUrl, e].join("/"), JSON.stringify(t)))
196
+ throw yield this.toApiError("sendBeacon failed");
197
+ });
198
+ }
199
+ toApiError(e) {
200
+ return o(this, void 0, void 0, function* () {
201
+ var t, n, i, s, l;
202
+ return e instanceof a.PirschApiError ? e : e instanceof m.AxiosError ? new a.PirschApiError((n = (t = e.response) === null || t === void 0 ? void 0 : t.status) !== null && n !== void 0 ? n : 400, (i = e.response) === null || i === void 0 ? void 0 : i.data) : typeof e == "object" && e !== null && "response" in e && typeof e.response == "object" && e.response !== null && "status" in e.response && "data" in e.response ? new a.PirschApiError((s = e.response.status) !== null && s !== void 0 ? s : 400, (l = e.response) === null || l === void 0 ? void 0 : l.data) : e instanceof Error ? new a.PirschUnknownApiError(e.message) : typeof e == "object" && e !== null && "message" in e && typeof e.message == "string" ? new a.PirschUnknownApiError(e.message) : new a.PirschUnknownApiError(JSON.stringify(e));
203
+ });
204
+ }
205
+ createOptions({ headers: e, parameters: t }) {
206
+ return {
207
+ headers: e,
208
+ params: t
209
+ };
210
+ }
211
+ }
212
+ return r.PirschWebClient = _, r.Pirsch = _, r.Client = _, r;
213
+ }
214
+ var A = C();
215
+ const U = /* @__PURE__ */ j({
216
+ __proto__: null
217
+ }, [A]);
218
+ export {
219
+ U as w
220
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacksee/analytics",
3
- "version": "0.5.0",
3
+ "version": "0.8.0",
4
4
  "description": "A highly typed, provider-agnostic analytics library for TypeScript applications",
5
5
  "type": "module",
6
6
  "exports": {
@@ -61,6 +61,8 @@
61
61
  "vitest": "^2.0.3"
62
62
  },
63
63
  "optionalDependencies": {
64
+ "@bentonow/bento-node-sdk": "^0.2.1",
65
+ "pirsch-sdk": "^2.9.1",
64
66
  "posthog-js": "^1.268.2",
65
67
  "posthog-node": "^5.9.0"
66
68
  },