@entrolytics/api-client 2.1.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1575 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ API_ENDPOINTS: () => import_shared.API_ENDPOINTS,
24
+ API_ROUTES: () => import_shared.API_ROUTES,
25
+ ApiClient: () => ApiClient,
26
+ BILLING_ERRORS: () => import_shared.BILLING_ERRORS,
27
+ CLI_CONFIG: () => import_shared.CLI_CONFIG,
28
+ CLI_TOKEN_STATUS: () => import_shared.CLI_TOKEN_STATUS,
29
+ DEFAULT_API_HOST: () => import_shared.DEFAULT_API_HOST,
30
+ DEPLOYMENT_ENV_VARS: () => import_shared.DEPLOYMENT_ENV_VARS,
31
+ DEPLOYMENT_SOURCES: () => import_shared.DEPLOYMENT_SOURCES,
32
+ ENV_VAR_NAMES: () => import_shared.ENV_VAR_NAMES,
33
+ ERROR_MESSAGES: () => import_shared.ERROR_MESSAGES,
34
+ EVENT_TYPES: () => import_shared.EVENT_TYPES,
35
+ FORM_EVENT_TYPES: () => import_shared.FORM_EVENT_TYPES,
36
+ FORM_FIELD_TYPES: () => import_shared.FORM_FIELD_TYPES,
37
+ FRAMEWORK_PACKAGES: () => import_shared.FRAMEWORK_PACKAGES,
38
+ FRAMEWORK_PATTERNS: () => import_shared.FRAMEWORK_PATTERNS,
39
+ HTTP_STATUS: () => import_shared.HTTP_STATUS,
40
+ NAVIGATION_TYPES: () => import_shared.NAVIGATION_TYPES,
41
+ ONBOARDING_STEPS: () => import_shared.ONBOARDING_STEPS,
42
+ PLANS: () => import_shared.PLANS,
43
+ PLAN_FEATURES: () => import_shared.PLAN_FEATURES,
44
+ RATE_LIMITS: () => import_shared.RATE_LIMITS,
45
+ SUCCESS_MESSAGES: () => import_shared.SUCCESS_MESSAGES,
46
+ USAGE_THRESHOLDS: () => import_shared.USAGE_THRESHOLDS,
47
+ USER_ROLES: () => import_shared.USER_ROLES,
48
+ VITAL_RATINGS: () => import_shared.VITAL_RATINGS,
49
+ VITAL_THRESHOLDS: () => import_shared.VITAL_THRESHOLDS,
50
+ VITAL_TYPES: () => import_shared.VITAL_TYPES,
51
+ assertRuntime: () => assertRuntime,
52
+ createAdminEndpoints: () => createAdminEndpoints,
53
+ createAuthEndpoints: () => createAuthEndpoints,
54
+ createBillingEndpoints: () => createBillingEndpoints,
55
+ createBoardsEndpoints: () => createBoardsEndpoints,
56
+ createConfigEndpoints: () => createConfigEndpoints,
57
+ createEdgeFetch: () => createEdgeFetch,
58
+ createEventsEndpoints: () => createEventsEndpoints,
59
+ createIntegrationsEndpoints: () => createIntegrationsEndpoints,
60
+ createLinksEndpoints: () => createLinksEndpoints,
61
+ createMeEndpoints: () => createMeEndpoints,
62
+ createOrgsEndpoints: () => createOrgsEndpoints,
63
+ createPixelsEndpoints: () => createPixelsEndpoints,
64
+ createReportsEndpoints: () => createReportsEndpoints,
65
+ createSegmentsEndpoints: () => createSegmentsEndpoints,
66
+ createSessionsEndpoints: () => createSessionsEndpoints,
67
+ createUsersEndpoints: () => createUsersEndpoints,
68
+ createWebhooksEndpoints: () => createWebhooksEndpoints,
69
+ createWebsitesEndpoints: () => createWebsitesEndpoints,
70
+ default: () => index_default,
71
+ detectDeploymentContext: () => import_shared.detectDeploymentContext,
72
+ detectRuntime: () => detectRuntime,
73
+ getApiRoute: () => import_shared.getApiRoute,
74
+ getClient: () => getClient,
75
+ getClientIp: () => getClientIp,
76
+ getEdgeEnv: () => getEdgeEnv,
77
+ getEnvVarNames: () => import_shared.getEnvVarNames,
78
+ getFrameworkPackage: () => import_shared.getFrameworkPackage,
79
+ getGeoFromRequest: () => getGeoFromRequest,
80
+ getPlan: () => import_shared.getPlan,
81
+ getPlanLimit: () => import_shared.getPlanLimit,
82
+ getRegionInfo: () => getRegionInfo,
83
+ getRuntimeCapabilities: () => getRuntimeCapabilities,
84
+ getVitalRating: () => import_shared.getVitalRating,
85
+ isEdgeRuntime: () => isEdgeRuntime,
86
+ isNodeRuntime: () => isNodeRuntime,
87
+ isPlanFeatureEnabled: () => import_shared.isPlanFeatureEnabled,
88
+ isUsageCritical: () => import_shared.isUsageCritical,
89
+ isUsageWarning: () => import_shared.isUsageWarning,
90
+ isValidFramework: () => import_shared.isValidFramework,
91
+ requireEdgeEnv: () => requireEdgeEnv
92
+ });
93
+ module.exports = __toCommonJS(index_exports);
94
+
95
+ // src/client.ts
96
+ var ApiClient = class {
97
+ endpoint;
98
+ bearerToken;
99
+ apiKey;
100
+ userId;
101
+ secret;
102
+ fetchFn;
103
+ retries;
104
+ retryDelay;
105
+ constructor(config = {}) {
106
+ const getEnv = (key) => {
107
+ if (typeof process !== "undefined" && process.env) {
108
+ return process.env[key];
109
+ }
110
+ return void 0;
111
+ };
112
+ this.endpoint = config.endpoint || getEnv("ENTROLYTICS_API_ENDPOINT") || "";
113
+ this.bearerToken = config.bearerToken || getEnv("ENTROLYTICS_BEARER_TOKEN");
114
+ this.apiKey = config.apiKey || getEnv("ENTROLYTICS_API_KEY");
115
+ this.userId = config.userId || getEnv("ENTROLYTICS_USER_ID");
116
+ this.secret = config.secret || getEnv("ENTROLYTICS_SECRET");
117
+ this.fetchFn = config.fetch || globalThis.fetch;
118
+ this.retries = config.retries ?? 3;
119
+ this.retryDelay = config.retryDelay ?? 1e3;
120
+ if (!this.endpoint) {
121
+ throw new Error(
122
+ "Entrolytics API endpoint is required. Set ENTROLYTICS_API_ENDPOINT or pass endpoint in config."
123
+ );
124
+ }
125
+ }
126
+ /**
127
+ * Update the bearer token (useful for token refresh).
128
+ */
129
+ setBearerToken(token) {
130
+ this.bearerToken = token;
131
+ }
132
+ /**
133
+ * Generate authentication headers.
134
+ * Priority: Bearer token > API key > Legacy share token
135
+ */
136
+ getAuthHeaders() {
137
+ const headers = {};
138
+ if (this.bearerToken) {
139
+ headers.Authorization = `Bearer ${this.bearerToken}`;
140
+ } else if (this.apiKey) {
141
+ headers["x-entrolytics-api-key"] = this.apiKey;
142
+ } else if (this.userId && this.secret) {
143
+ headers["x-entrolytics-share-token"] = this.createShareToken();
144
+ }
145
+ return headers;
146
+ }
147
+ /**
148
+ * Create a share token for self-hosted authentication (legacy).
149
+ * @deprecated Use bearerToken or apiKey instead
150
+ */
151
+ createShareToken() {
152
+ if (!this.userId || !this.secret) {
153
+ throw new Error("userId and secret are required for self-hosted authentication");
154
+ }
155
+ const payload = {
156
+ userId: this.userId,
157
+ timestamp: Date.now()
158
+ };
159
+ if (typeof Buffer !== "undefined") {
160
+ return Buffer.from(JSON.stringify(payload)).toString("base64");
161
+ } else {
162
+ return btoa(JSON.stringify(payload));
163
+ }
164
+ }
165
+ /**
166
+ * Sleep helper for retry delays.
167
+ */
168
+ sleep(ms) {
169
+ return new Promise((resolve) => setTimeout(resolve, ms));
170
+ }
171
+ /**
172
+ * Check if error is retryable.
173
+ */
174
+ isRetryable(status) {
175
+ return status === 0 || status === 429 || status >= 500;
176
+ }
177
+ /**
178
+ * Build URL with query parameters.
179
+ */
180
+ buildUrl(path, params) {
181
+ const url = new URL(path, this.endpoint);
182
+ if (params) {
183
+ Object.entries(params).forEach(([key, value]) => {
184
+ if (value !== void 0) {
185
+ url.searchParams.set(key, String(value));
186
+ }
187
+ });
188
+ }
189
+ return url.toString();
190
+ }
191
+ /**
192
+ * Make an authenticated API request with automatic retries.
193
+ */
194
+ async request(path, options = {}) {
195
+ const { method = "GET", body, params, headers = {} } = options;
196
+ const url = this.buildUrl(path, params);
197
+ let lastError = null;
198
+ for (let attempt = 0; attempt <= this.retries; attempt++) {
199
+ try {
200
+ const fetchOptions = {
201
+ method,
202
+ headers: {
203
+ "Content-Type": "application/json",
204
+ ...this.getAuthHeaders(),
205
+ ...headers
206
+ }
207
+ };
208
+ if (body) {
209
+ fetchOptions.body = JSON.stringify(body);
210
+ }
211
+ const response = await this.fetchFn(url, fetchOptions);
212
+ const data = await response.json().catch(() => ({}));
213
+ if (!response.ok) {
214
+ const errorMessage = typeof data.error === "string" ? data.error : typeof data.message === "string" ? data.message : `HTTP ${response.status}`;
215
+ lastError = {
216
+ ok: false,
217
+ status: response.status,
218
+ error: errorMessage
219
+ };
220
+ if (this.isRetryable(response.status) && attempt < this.retries) {
221
+ const delay = this.retryDelay * 2 ** attempt;
222
+ await this.sleep(delay);
223
+ continue;
224
+ }
225
+ return lastError;
226
+ }
227
+ return {
228
+ ok: true,
229
+ status: response.status,
230
+ data
231
+ };
232
+ } catch (error) {
233
+ lastError = {
234
+ ok: false,
235
+ status: 0,
236
+ error: error instanceof Error ? error.message : "Network error"
237
+ };
238
+ if (attempt < this.retries) {
239
+ const delay = this.retryDelay * 2 ** attempt;
240
+ await this.sleep(delay);
241
+ }
242
+ }
243
+ }
244
+ return lastError ?? {
245
+ ok: false,
246
+ status: 0,
247
+ error: "Request failed after retries"
248
+ };
249
+ }
250
+ /**
251
+ * GET request helper.
252
+ */
253
+ get(path, params) {
254
+ return this.request(path, { method: "GET", params });
255
+ }
256
+ /**
257
+ * POST request helper.
258
+ */
259
+ post(path, body) {
260
+ return this.request(path, { method: "POST", body });
261
+ }
262
+ /**
263
+ * PUT request helper.
264
+ */
265
+ put(path, body) {
266
+ return this.request(path, { method: "PUT", body });
267
+ }
268
+ /**
269
+ * DELETE request helper.
270
+ */
271
+ delete(path) {
272
+ return this.request(path, { method: "DELETE" });
273
+ }
274
+ /**
275
+ * PATCH request helper.
276
+ */
277
+ patch(path, body) {
278
+ return this.request(path, { method: "PATCH", body });
279
+ }
280
+ };
281
+
282
+ // src/endpoints/admin.ts
283
+ function createAdminEndpoints(client) {
284
+ return {
285
+ /**
286
+ * Get all organizations (admin only)
287
+ */
288
+ getOrgs: () => client.get("/admin/orgs"),
289
+ /**
290
+ * Get organization details (admin only)
291
+ */
292
+ getOrg: ({ orgId }) => client.get(`/admin/orgs/${orgId}`),
293
+ /**
294
+ * Get all users (admin only)
295
+ */
296
+ getUsers: () => client.get("/admin/users"),
297
+ /**
298
+ * Get user details (admin only)
299
+ */
300
+ getUser: ({ userId }) => client.get(`/admin/users/${userId}`),
301
+ /**
302
+ * Get all websites (admin only)
303
+ */
304
+ getWebsites: () => client.get("/admin/websites"),
305
+ /**
306
+ * Get website details (admin only)
307
+ */
308
+ getWebsite: ({ websiteId }) => client.get(`/admin/websites/${websiteId}`),
309
+ /**
310
+ * Run admin setup
311
+ */
312
+ setup: () => client.post("/admin/setup", {})
313
+ };
314
+ }
315
+
316
+ // src/endpoints/auth.ts
317
+ function createAuthEndpoints(client) {
318
+ return {
319
+ /**
320
+ * List all active CLI access tokens for the current user.
321
+ */
322
+ listCliTokens() {
323
+ return client.get("/auth/cli/tokens");
324
+ },
325
+ /**
326
+ * Revoke a specific CLI access token by its JTI.
327
+ *
328
+ * @param jti - The JWT ID of the token to revoke
329
+ */
330
+ revokeCliToken(jti) {
331
+ return client["request"]("/auth/cli/tokens", {
332
+ method: "DELETE",
333
+ body: { jti }
334
+ });
335
+ },
336
+ /**
337
+ * Revoke all CLI access tokens for the current user.
338
+ */
339
+ revokeAllCliTokens() {
340
+ return client["request"]("/auth/cli/tokens", {
341
+ method: "DELETE",
342
+ body: { revokeAll: true }
343
+ });
344
+ }
345
+ };
346
+ }
347
+
348
+ // src/endpoints/billing.ts
349
+ function createBillingEndpoints(client) {
350
+ return {
351
+ /**
352
+ * Get current account usage for the billing period.
353
+ */
354
+ getUsage() {
355
+ return client.get("/billing/usage");
356
+ },
357
+ /**
358
+ * Get account entitlements based on current plan.
359
+ */
360
+ getEntitlements() {
361
+ return client.get("/billing/entitlements");
362
+ },
363
+ /**
364
+ * Get current subscription details.
365
+ */
366
+ getSubscription() {
367
+ return client.get("/billing/subscription");
368
+ },
369
+ /**
370
+ * Create a Stripe checkout session for upgrading/changing plan.
371
+ */
372
+ createCheckoutSession(options) {
373
+ return client.post("/billing/checkout", options);
374
+ },
375
+ /**
376
+ * Create a Stripe billing portal session for managing subscription.
377
+ */
378
+ createPortalSession() {
379
+ return client.post("/billing/portal");
380
+ }
381
+ };
382
+ }
383
+
384
+ // src/endpoints/boards.ts
385
+ function createBoardsEndpoints(client) {
386
+ return {
387
+ /**
388
+ * Get all boards for a website.
389
+ */
390
+ getBoards(websiteId) {
391
+ return client.get(`/websites/${websiteId}/boards`);
392
+ },
393
+ /**
394
+ * Get a specific board by ID.
395
+ */
396
+ getBoard(boardId) {
397
+ return client.get(`/boards/${boardId}`);
398
+ },
399
+ /**
400
+ * Create a new board.
401
+ */
402
+ createBoard(data) {
403
+ return client.post("/boards", data);
404
+ },
405
+ /**
406
+ * Update a board.
407
+ */
408
+ updateBoard(boardId, data) {
409
+ return client.post(`/boards/${boardId}`, data);
410
+ },
411
+ /**
412
+ * Delete a board.
413
+ */
414
+ deleteBoard(boardId) {
415
+ return client.delete(`/boards/${boardId}`);
416
+ },
417
+ /**
418
+ * Get all widgets for a board.
419
+ */
420
+ getBoardWidgets(boardId) {
421
+ return client.get(`/boards/${boardId}/widgets`);
422
+ },
423
+ /**
424
+ * Get a specific widget by ID.
425
+ */
426
+ getBoardWidget(boardId, widgetId) {
427
+ return client.get(`/boards/${boardId}/widgets/${widgetId}`);
428
+ },
429
+ /**
430
+ * Create a new widget on a board.
431
+ */
432
+ createBoardWidget(boardId, data) {
433
+ return client.post(`/boards/${boardId}/widgets`, data);
434
+ },
435
+ /**
436
+ * Update a widget.
437
+ */
438
+ updateBoardWidget(boardId, widgetId, data) {
439
+ return client.post(`/boards/${boardId}/widgets/${widgetId}`, data);
440
+ },
441
+ /**
442
+ * Delete a widget.
443
+ */
444
+ deleteBoardWidget(boardId, widgetId) {
445
+ return client.delete(`/boards/${boardId}/widgets/${widgetId}`);
446
+ }
447
+ };
448
+ }
449
+
450
+ // src/endpoints/config.ts
451
+ function createConfigEndpoints(client) {
452
+ return {
453
+ /**
454
+ * Get system configuration
455
+ */
456
+ get: () => client.get("/config")
457
+ };
458
+ }
459
+
460
+ // src/endpoints/events.ts
461
+ function createEventsEndpoints(client) {
462
+ return {
463
+ /**
464
+ * Get event data statistics.
465
+ */
466
+ getEventDataStats(websiteId, params) {
467
+ return client.get(`/websites/${websiteId}/event-data/stats`, params);
468
+ },
469
+ /**
470
+ * Get event data events (distinct event names).
471
+ */
472
+ getEventDataEvents(websiteId, params) {
473
+ return client.get(`/websites/${websiteId}/event-data/events`, params);
474
+ },
475
+ /**
476
+ * Get event data fields for a specific event.
477
+ */
478
+ getEventDataFields(websiteId, params) {
479
+ return client.get(`/websites/${websiteId}/event-data/fields`, params);
480
+ },
481
+ /**
482
+ * Get event data values for a specific field.
483
+ */
484
+ getEventDataValues(websiteId, params) {
485
+ return client.get(`/websites/${websiteId}/event-data/values`, params);
486
+ },
487
+ /**
488
+ * Get event data properties breakdown.
489
+ */
490
+ getEventDataProperties(websiteId, params) {
491
+ return client.get(`/websites/${websiteId}/event-data/properties`, params);
492
+ },
493
+ /**
494
+ * Get specific event data by ID.
495
+ */
496
+ getEventData(websiteId, eventId) {
497
+ return client.get(`/websites/${websiteId}/event-data/${eventId}`);
498
+ },
499
+ /**
500
+ * Get session data properties.
501
+ */
502
+ getSessionDataProperties(websiteId, params) {
503
+ return client.get(`/websites/${websiteId}/session-data/properties`, params);
504
+ },
505
+ /**
506
+ * Get session data values for a property.
507
+ */
508
+ getSessionDataValues(websiteId, params) {
509
+ return client.get(`/websites/${websiteId}/session-data/values`, params);
510
+ }
511
+ };
512
+ }
513
+
514
+ // src/endpoints/integrations.ts
515
+ function createIntegrationsEndpoints(client) {
516
+ return {
517
+ /**
518
+ * Handle WordPress integration
519
+ */
520
+ wordpress: (params) => client.post("/integrations/wordpress", params.data)
521
+ };
522
+ }
523
+
524
+ // src/endpoints/links.ts
525
+ function createLinksEndpoints(client) {
526
+ return {
527
+ /**
528
+ * Get all links.
529
+ */
530
+ getLinks() {
531
+ return client.get("/links");
532
+ },
533
+ /**
534
+ * Get links for an organization.
535
+ */
536
+ getOrgLinks(orgId) {
537
+ return client.get(`/orgs/${orgId}/links`);
538
+ },
539
+ /**
540
+ * Create a new link.
541
+ */
542
+ createLink(orgId, data) {
543
+ return client.post(`/orgs/${orgId}/links`, data);
544
+ },
545
+ /**
546
+ * Get a link by ID.
547
+ */
548
+ getLink(linkId) {
549
+ return client.get(`/links/${linkId}`);
550
+ },
551
+ /**
552
+ * Update a link.
553
+ */
554
+ updateLink(linkId, data) {
555
+ return client.post(`/links/${linkId}`, data);
556
+ },
557
+ /**
558
+ * Delete a link.
559
+ */
560
+ deleteLink(linkId) {
561
+ return client.delete(`/links/${linkId}`);
562
+ }
563
+ };
564
+ }
565
+
566
+ // src/endpoints/me.ts
567
+ function createMeEndpoints(client) {
568
+ return {
569
+ /**
570
+ * Get current user profile.
571
+ */
572
+ getMe() {
573
+ return client.get("/me");
574
+ },
575
+ /**
576
+ * Update current user's password.
577
+ */
578
+ updateMyPassword(data) {
579
+ return client.post("/me/password", data);
580
+ },
581
+ /**
582
+ * Get current user's websites.
583
+ */
584
+ getMyWebsites() {
585
+ return client.get("/me/websites");
586
+ },
587
+ /**
588
+ * Get current user's organizations.
589
+ */
590
+ getMyOrgs() {
591
+ return client.get("/me/orgs");
592
+ }
593
+ };
594
+ }
595
+
596
+ // src/endpoints/orgs.ts
597
+ function createOrgsEndpoints(client) {
598
+ return {
599
+ /**
600
+ * Get all organizations for the current user.
601
+ */
602
+ getOrgs() {
603
+ return client.get("/orgs");
604
+ },
605
+ /**
606
+ * Create a new organization.
607
+ */
608
+ createOrg(data) {
609
+ return client.post("/orgs", data);
610
+ },
611
+ /**
612
+ * Join an organization using access code.
613
+ */
614
+ joinOrg(data) {
615
+ return client.post("/orgs/join", data);
616
+ },
617
+ /**
618
+ * Get an organization by ID.
619
+ */
620
+ getOrg(orgId) {
621
+ return client.get(`/orgs/${orgId}`);
622
+ },
623
+ /**
624
+ * Update an organization.
625
+ */
626
+ updateOrg(orgId, data) {
627
+ return client.post(`/orgs/${orgId}`, data);
628
+ },
629
+ /**
630
+ * Delete an organization.
631
+ */
632
+ deleteOrg(orgId) {
633
+ return client.delete(`/orgs/${orgId}`);
634
+ },
635
+ /**
636
+ * Get organization members.
637
+ */
638
+ getOrgUsers(orgId) {
639
+ return client.get(`/orgs/${orgId}/users`);
640
+ },
641
+ /**
642
+ * Add a user to an organization.
643
+ */
644
+ addOrgUser(orgId, data) {
645
+ return client.post(`/orgs/${orgId}/users`, data);
646
+ },
647
+ /**
648
+ * Update an organization member's role.
649
+ */
650
+ updateOrgUser(orgId, userId, data) {
651
+ return client.post(`/orgs/${orgId}/users/${userId}`, data);
652
+ },
653
+ /**
654
+ * Remove a user from an organization.
655
+ */
656
+ removeOrgUser(orgId, userId) {
657
+ return client.delete(`/orgs/${orgId}/users/${userId}`);
658
+ },
659
+ /**
660
+ * Get organization websites.
661
+ */
662
+ getOrgWebsites(orgId) {
663
+ return client.get(`/orgs/${orgId}/websites`);
664
+ },
665
+ /**
666
+ * Add a website to an organization.
667
+ */
668
+ addOrgWebsite(orgId, data) {
669
+ return client.post(`/orgs/${orgId}/websites`, data);
670
+ },
671
+ /**
672
+ * Remove a website from an organization.
673
+ */
674
+ removeOrgWebsite(orgId, websiteId) {
675
+ return client.delete(`/orgs/${orgId}/websites/${websiteId}`);
676
+ }
677
+ };
678
+ }
679
+
680
+ // src/endpoints/pixels.ts
681
+ function createPixelsEndpoints(client) {
682
+ return {
683
+ /**
684
+ * Get all pixels.
685
+ */
686
+ getPixels() {
687
+ return client.get("/pixels");
688
+ },
689
+ /**
690
+ * Get pixels for an organization.
691
+ */
692
+ getOrgPixels(orgId) {
693
+ return client.get(`/orgs/${orgId}/pixels`);
694
+ },
695
+ /**
696
+ * Create a new pixel.
697
+ */
698
+ createPixel(orgId, data) {
699
+ return client.post(`/orgs/${orgId}/pixels`, data);
700
+ },
701
+ /**
702
+ * Get a pixel by ID.
703
+ */
704
+ getPixel(pixelId) {
705
+ return client.get(`/pixels/${pixelId}`);
706
+ },
707
+ /**
708
+ * Update a pixel.
709
+ */
710
+ updatePixel(pixelId, data) {
711
+ return client.post(`/pixels/${pixelId}`, data);
712
+ },
713
+ /**
714
+ * Delete a pixel.
715
+ */
716
+ deletePixel(pixelId) {
717
+ return client.delete(`/pixels/${pixelId}`);
718
+ }
719
+ };
720
+ }
721
+
722
+ // src/endpoints/reports.ts
723
+ function createReportsEndpoints(client) {
724
+ return {
725
+ /**
726
+ * Get all reports for a website.
727
+ */
728
+ getReports(websiteId) {
729
+ return client.get(`/websites/${websiteId}/reports`);
730
+ },
731
+ /**
732
+ * Create a new report.
733
+ */
734
+ createReport(data) {
735
+ return client.post("/reports", data);
736
+ },
737
+ /**
738
+ * Get a report by ID.
739
+ */
740
+ getReport(reportId) {
741
+ return client.get(`/reports/${reportId}`);
742
+ },
743
+ /**
744
+ * Update a report.
745
+ */
746
+ updateReport(reportId, data) {
747
+ return client.post(`/reports/${reportId}`, data);
748
+ },
749
+ /**
750
+ * Delete a report.
751
+ */
752
+ deleteReport(reportId) {
753
+ return client.delete(`/reports/${reportId}`);
754
+ },
755
+ /**
756
+ * Run a funnel report.
757
+ */
758
+ runFunnelReport(params) {
759
+ const { websiteId, steps, window = 30, startAt, endAt, ...rest } = params;
760
+ return client.post("/reports/funnel", {
761
+ websiteId,
762
+ parameters: {
763
+ startDate: startAt,
764
+ endDate: endAt,
765
+ window,
766
+ steps
767
+ },
768
+ filters: rest
769
+ });
770
+ },
771
+ /**
772
+ * Run a retention report.
773
+ */
774
+ runRetentionReport(params) {
775
+ const { websiteId, startAt, endAt, timezone, ...rest } = params;
776
+ return client.post("/reports/retention", {
777
+ websiteId,
778
+ parameters: {
779
+ startDate: startAt,
780
+ endDate: endAt,
781
+ timezone
782
+ },
783
+ filters: rest
784
+ });
785
+ },
786
+ /**
787
+ * Run a journey/flow report.
788
+ */
789
+ runJourneyReport(params) {
790
+ const { websiteId, startAt, endAt, steps = 5, startStep, endStep, ...rest } = params;
791
+ return client.post("/reports/journey", {
792
+ websiteId,
793
+ parameters: {
794
+ startDate: startAt,
795
+ endDate: endAt,
796
+ steps,
797
+ startStep,
798
+ endStep
799
+ },
800
+ filters: rest
801
+ });
802
+ },
803
+ /**
804
+ * Run a goals report.
805
+ */
806
+ runGoalReport(params) {
807
+ const { websiteId, startAt, endAt, type, value, ...rest } = params;
808
+ return client.post("/reports/goal", {
809
+ websiteId,
810
+ parameters: {
811
+ startDate: startAt,
812
+ endDate: endAt,
813
+ type,
814
+ value
815
+ },
816
+ filters: rest
817
+ });
818
+ },
819
+ /**
820
+ * Run an attribution report.
821
+ */
822
+ runAttributionReport(params) {
823
+ const { websiteId, startAt, endAt, model, type, step, currency, ...rest } = params;
824
+ return client.post("/reports/attribution", {
825
+ websiteId,
826
+ parameters: {
827
+ startDate: startAt,
828
+ endDate: endAt,
829
+ model,
830
+ type,
831
+ step,
832
+ currency
833
+ },
834
+ filters: rest
835
+ });
836
+ },
837
+ /**
838
+ * Run a revenue report.
839
+ */
840
+ runRevenueReport(params) {
841
+ const { websiteId, startAt, endAt, currency = "USD", ...rest } = params;
842
+ return client.post("/reports/revenue", {
843
+ websiteId,
844
+ parameters: {
845
+ startDate: startAt,
846
+ endDate: endAt,
847
+ currency
848
+ },
849
+ filters: rest
850
+ });
851
+ },
852
+ /**
853
+ * Run a UTM report.
854
+ */
855
+ runUTMReport(params) {
856
+ const { websiteId, startAt, endAt, ...rest } = params;
857
+ return client.post("/reports/utm", {
858
+ websiteId,
859
+ parameters: {
860
+ startDate: startAt,
861
+ endDate: endAt
862
+ },
863
+ filters: rest
864
+ });
865
+ },
866
+ /**
867
+ * Run a breakdown report.
868
+ * @param property - Field to break down by (path, referrer, browser, device, os, country, etc.)
869
+ */
870
+ runBreakdownReport(params) {
871
+ const { websiteId, startAt, endAt, property, ...rest } = params;
872
+ return client.post("/reports/breakdown", {
873
+ websiteId,
874
+ parameters: {
875
+ startDate: startAt,
876
+ endDate: endAt,
877
+ property
878
+ },
879
+ filters: rest
880
+ });
881
+ }
882
+ };
883
+ }
884
+
885
+ // src/endpoints/segments.ts
886
+ function createSegmentsEndpoints(client) {
887
+ return {
888
+ /**
889
+ * Get all segments for a website.
890
+ */
891
+ getSegments(websiteId) {
892
+ return client.get(`/websites/${websiteId}/segments`);
893
+ },
894
+ /**
895
+ * Create a new segment.
896
+ */
897
+ createSegment(websiteId, data) {
898
+ return client.post(`/websites/${websiteId}/segments`, data);
899
+ },
900
+ /**
901
+ * Get a segment by ID.
902
+ */
903
+ getSegment(websiteId, segmentId) {
904
+ return client.get(`/websites/${websiteId}/segments/${segmentId}`);
905
+ },
906
+ /**
907
+ * Update a segment.
908
+ */
909
+ updateSegment(websiteId, segmentId, data) {
910
+ return client.post(`/websites/${websiteId}/segments/${segmentId}`, data);
911
+ },
912
+ /**
913
+ * Delete a segment.
914
+ */
915
+ deleteSegment(websiteId, segmentId) {
916
+ return client.delete(`/websites/${websiteId}/segments/${segmentId}`);
917
+ }
918
+ };
919
+ }
920
+
921
+ // src/endpoints/sessions.ts
922
+ function createSessionsEndpoints(client) {
923
+ return {
924
+ /**
925
+ * Get website sessions.
926
+ */
927
+ getWebsiteSessions(websiteId, params) {
928
+ return client.get(`/websites/${websiteId}/sessions`, params);
929
+ },
930
+ /**
931
+ * Get session statistics.
932
+ */
933
+ getWebsiteSessionStats(websiteId, params) {
934
+ return client.get(`/websites/${websiteId}/sessions/stats`, params);
935
+ },
936
+ /**
937
+ * Get weekly session traffic.
938
+ */
939
+ getWeeklyTraffic(websiteId, params) {
940
+ return client.get(`/websites/${websiteId}/sessions/weekly`, params);
941
+ },
942
+ /**
943
+ * Get a specific session.
944
+ */
945
+ getSession(websiteId, sessionId) {
946
+ return client.get(`/websites/${websiteId}/sessions/${sessionId}`);
947
+ },
948
+ /**
949
+ * Get session activity (pageviews and events).
950
+ */
951
+ getSessionActivity(websiteId, sessionId, params) {
952
+ return client.get(
953
+ `/websites/${websiteId}/sessions/${sessionId}/activity`,
954
+ params
955
+ );
956
+ },
957
+ /**
958
+ * Get session properties (custom data).
959
+ */
960
+ getSessionProperties(websiteId, sessionId) {
961
+ return client.get(`/websites/${websiteId}/sessions/${sessionId}/properties`);
962
+ }
963
+ };
964
+ }
965
+
966
+ // src/endpoints/users.ts
967
+ function createUsersEndpoints(client) {
968
+ return {
969
+ /**
970
+ * Get all users (admin only).
971
+ */
972
+ getUsers() {
973
+ return client.get("/users");
974
+ },
975
+ /**
976
+ * Create a new user (admin only).
977
+ */
978
+ createUser(data) {
979
+ return client.post("/users", data);
980
+ },
981
+ /**
982
+ * Get a user by ID.
983
+ */
984
+ getUser(userId) {
985
+ return client.get(`/users/${userId}`);
986
+ },
987
+ /**
988
+ * Update a user.
989
+ */
990
+ updateUser(userId, data) {
991
+ return client.post(`/users/${userId}`, data);
992
+ },
993
+ /**
994
+ * Delete a user (admin only).
995
+ */
996
+ deleteUser(userId) {
997
+ return client.delete(`/users/${userId}`);
998
+ },
999
+ /**
1000
+ * Get websites belonging to a user.
1001
+ */
1002
+ getUserWebsites(userId) {
1003
+ return client.get(`/users/${userId}/websites`);
1004
+ },
1005
+ /**
1006
+ * Get user usage statistics.
1007
+ */
1008
+ getUserUsage(userId, params) {
1009
+ return client.get(`/users/${userId}/usage`, params);
1010
+ }
1011
+ };
1012
+ }
1013
+
1014
+ // src/endpoints/webhooks.ts
1015
+ function createWebhooksEndpoints(client) {
1016
+ return {
1017
+ /**
1018
+ * Handle Clerk webhook
1019
+ */
1020
+ clerk: (params) => client.post("/webhooks/clerk", params.data)
1021
+ };
1022
+ }
1023
+
1024
+ // src/endpoints/websites.ts
1025
+ function createWebsitesEndpoints(client) {
1026
+ return {
1027
+ /**
1028
+ * Get all websites.
1029
+ */
1030
+ getWebsites() {
1031
+ return client.get("/websites");
1032
+ },
1033
+ /**
1034
+ * Create a new website.
1035
+ */
1036
+ createWebsite(data) {
1037
+ return client.post("/websites", data);
1038
+ },
1039
+ /**
1040
+ * Get a website by ID.
1041
+ */
1042
+ getWebsite(websiteId) {
1043
+ return client.get(`/websites/${websiteId}`);
1044
+ },
1045
+ /**
1046
+ * Update a website.
1047
+ */
1048
+ updateWebsite(websiteId, data) {
1049
+ return client.post(`/websites/${websiteId}`, data);
1050
+ },
1051
+ /**
1052
+ * Delete a website.
1053
+ */
1054
+ deleteWebsite(websiteId) {
1055
+ return client.delete(`/websites/${websiteId}`);
1056
+ },
1057
+ /**
1058
+ * Reset a website's data.
1059
+ */
1060
+ resetWebsite(websiteId) {
1061
+ return client.post(`/websites/${websiteId}/reset`);
1062
+ },
1063
+ /**
1064
+ * Transfer website ownership.
1065
+ */
1066
+ transferWebsite(websiteId, data) {
1067
+ return client.post(`/websites/${websiteId}/transfer`, data);
1068
+ },
1069
+ /**
1070
+ * Get website statistics.
1071
+ */
1072
+ getWebsiteStats(websiteId, params) {
1073
+ return client.get(`/websites/${websiteId}/stats`, params);
1074
+ },
1075
+ /**
1076
+ * Get website pageviews data.
1077
+ */
1078
+ getWebsitePageviews(websiteId, params) {
1079
+ return client.get(`/websites/${websiteId}/pageviews`, params);
1080
+ },
1081
+ /**
1082
+ * Get website metrics (URLs, referrers, browsers, etc.).
1083
+ */
1084
+ getWebsiteMetrics(websiteId, params) {
1085
+ return client.get(`/websites/${websiteId}/metrics`, params);
1086
+ },
1087
+ /**
1088
+ * Get expanded metrics (with additional details).
1089
+ */
1090
+ getWebsiteExpandedMetrics(websiteId, params) {
1091
+ return client.get(`/websites/${websiteId}/metrics/expanded`, params);
1092
+ },
1093
+ /**
1094
+ * Get website events.
1095
+ */
1096
+ getWebsiteEvents(websiteId, params) {
1097
+ return client.get(`/websites/${websiteId}/events`, params);
1098
+ },
1099
+ /**
1100
+ * Get events time series.
1101
+ */
1102
+ getWebsiteEventsSeries(websiteId, params) {
1103
+ return client.get(`/websites/${websiteId}/events/series`, params);
1104
+ },
1105
+ /**
1106
+ * Get active visitors count.
1107
+ */
1108
+ getWebsiteActive(websiteId) {
1109
+ return client.get(`/websites/${websiteId}/active`);
1110
+ },
1111
+ /**
1112
+ * Get website date range (first and last event dates).
1113
+ */
1114
+ getWebsiteDateRange(websiteId) {
1115
+ return client.get(`/websites/${websiteId}/daterange`);
1116
+ },
1117
+ /**
1118
+ * Get website values for a specific field.
1119
+ */
1120
+ getWebsiteValues(websiteId, params) {
1121
+ return client.get(`/websites/${websiteId}/values`, params);
1122
+ },
1123
+ /**
1124
+ * Get realtime data.
1125
+ */
1126
+ getRealtimeData(websiteId) {
1127
+ return client.get(`/realtime/${websiteId}`);
1128
+ },
1129
+ /**
1130
+ * Export website data.
1131
+ */
1132
+ exportWebsiteData(websiteId, params) {
1133
+ return client.get(`/websites/${websiteId}/export`, params);
1134
+ },
1135
+ /**
1136
+ * Get website ingest mode configuration.
1137
+ */
1138
+ getWebsiteMode(websiteId) {
1139
+ return client.get(`/websites/${websiteId}/mode`);
1140
+ },
1141
+ /**
1142
+ * Set website ingest mode (auto, node, or edge).
1143
+ */
1144
+ setWebsiteMode(websiteId, mode) {
1145
+ return client.post(`/websites/${websiteId}/mode`, { ingestMode: mode });
1146
+ },
1147
+ /**
1148
+ * Get routing health status.
1149
+ */
1150
+ getRoutingHealth() {
1151
+ return client.get("/health/routing");
1152
+ },
1153
+ /**
1154
+ * Get routing statistics.
1155
+ */
1156
+ getRoutingStats(params) {
1157
+ return client.get("/routing/stats", params);
1158
+ },
1159
+ // ========================================================================
1160
+ // Phase 2: Web Vitals Endpoints (NG only)
1161
+ // ========================================================================
1162
+ /**
1163
+ * Get Web Vitals statistics for a website.
1164
+ * Note: Only available in entrolytics.
1165
+ */
1166
+ getWebsiteVitals(websiteId, params) {
1167
+ return client.get(`/websites/${websiteId}/vitals`, params);
1168
+ },
1169
+ /**
1170
+ * Get individual Web Vital events.
1171
+ * Note: Only available in entrolytics.
1172
+ */
1173
+ getWebsiteVitalEvents(websiteId, params) {
1174
+ return client.get(`/websites/${websiteId}/vitals/events`, params);
1175
+ },
1176
+ /**
1177
+ * Track a Web Vital metric (send to collection endpoint).
1178
+ * Note: Only available in entrolytics.
1179
+ */
1180
+ trackVital(websiteId, data) {
1181
+ return client.post("/collect/vitals", {
1182
+ website: websiteId,
1183
+ ...data
1184
+ });
1185
+ },
1186
+ /**
1187
+ * Track multiple Web Vitals metrics in batch.
1188
+ * Note: Only available in entrolytics.
1189
+ */
1190
+ trackVitalsBatch(websiteId, vitals) {
1191
+ return client.post("/collect/vitals", {
1192
+ website: websiteId,
1193
+ vitals
1194
+ });
1195
+ },
1196
+ // ========================================================================
1197
+ // Phase 2: Form Analytics Endpoints (NG only)
1198
+ // ========================================================================
1199
+ /**
1200
+ * Get form analytics for a website.
1201
+ * Note: Only available in entrolytics.
1202
+ */
1203
+ getWebsiteForms(websiteId, params) {
1204
+ return client.get(`/websites/${websiteId}/forms`, params);
1205
+ },
1206
+ /**
1207
+ * Get field-level analytics for a specific form.
1208
+ * Note: Only available in entrolytics.
1209
+ */
1210
+ getFormFields(websiteId, formId, params) {
1211
+ return client.get(`/websites/${websiteId}/forms/${formId}/fields`, params);
1212
+ },
1213
+ /**
1214
+ * Get individual form events.
1215
+ * Note: Only available in entrolytics.
1216
+ */
1217
+ getFormEvents(websiteId, params) {
1218
+ return client.get(`/websites/${websiteId}/forms/events`, params);
1219
+ },
1220
+ /**
1221
+ * Track a form event (send to collection endpoint).
1222
+ * Note: Only available in entrolytics.
1223
+ */
1224
+ trackFormEvent(websiteId, data) {
1225
+ return client.post("/collect/forms", {
1226
+ website: websiteId,
1227
+ ...data
1228
+ });
1229
+ },
1230
+ /**
1231
+ * Track multiple form events in batch.
1232
+ * Note: Only available in entrolytics.
1233
+ */
1234
+ trackFormEventsBatch(websiteId, events) {
1235
+ return client.post("/collect/forms", {
1236
+ website: websiteId,
1237
+ events
1238
+ });
1239
+ },
1240
+ // ========================================================================
1241
+ // Phase 2: Deployment Tracking Endpoints (NG only)
1242
+ // ========================================================================
1243
+ /**
1244
+ * Get deployments for a website.
1245
+ * Note: Only available in entrolytics.
1246
+ */
1247
+ getWebsiteDeployments(websiteId, params) {
1248
+ return client.get(`/websites/${websiteId}/deployments`, params);
1249
+ },
1250
+ /**
1251
+ * Get a specific deployment.
1252
+ * Note: Only available in entrolytics.
1253
+ */
1254
+ getDeployment(websiteId, deployId) {
1255
+ return client.get(`/websites/${websiteId}/deployments/${deployId}`);
1256
+ },
1257
+ /**
1258
+ * Compare two deployments.
1259
+ * Note: Only available in entrolytics.
1260
+ */
1261
+ compareDeployments(websiteId, currentDeployId, previousDeployId) {
1262
+ return client.get(`/websites/${websiteId}/deployments/${currentDeployId}/compare`, {
1263
+ previous: previousDeployId
1264
+ });
1265
+ },
1266
+ /**
1267
+ * Set/register a deployment context.
1268
+ * Note: Only available in entrolytics.
1269
+ */
1270
+ setDeployment(websiteId, data) {
1271
+ return client.post(`/websites/${websiteId}/deployments`, data);
1272
+ }
1273
+ };
1274
+ }
1275
+
1276
+ // src/index.ts
1277
+ var import_shared = require("@entrolytics/shared");
1278
+
1279
+ // src/runtime.ts
1280
+ function detectRuntime() {
1281
+ if (
1282
+ // @ts-ignore - Edge Runtime global
1283
+ typeof EdgeRuntime !== "undefined" || // @ts-ignore - Vercel Edge Runtime
1284
+ globalThis.EdgeRuntime !== void 0 || // @ts-ignore - Netlify Edge Functions use Deno
1285
+ typeof Deno !== "undefined" || // @ts-ignore - Cloudflare Workers
1286
+ typeof WebAssembly !== "undefined" && typeof Response !== "undefined" && !process?.versions?.node
1287
+ ) {
1288
+ return "edge";
1289
+ }
1290
+ if (typeof process !== "undefined" && process.versions != null && process.versions.node != null) {
1291
+ return "node";
1292
+ }
1293
+ return "unknown";
1294
+ }
1295
+ function isNodeRuntime() {
1296
+ return detectRuntime() === "node";
1297
+ }
1298
+ function isEdgeRuntime() {
1299
+ return detectRuntime() === "edge";
1300
+ }
1301
+ function getRuntimeCapabilities() {
1302
+ const runtime = detectRuntime();
1303
+ return {
1304
+ runtime,
1305
+ isNode: runtime === "node",
1306
+ isEdge: runtime === "edge",
1307
+ supportsFileSystem: runtime === "node",
1308
+ supportsWebCrypto: typeof crypto !== "undefined" && typeof crypto.subtle !== "undefined",
1309
+ supportsFetch: typeof fetch !== "undefined",
1310
+ supportsStreams: typeof ReadableStream !== "undefined"
1311
+ };
1312
+ }
1313
+ function assertRuntime(expected) {
1314
+ const actual = detectRuntime();
1315
+ if (actual !== expected) {
1316
+ throw new Error(
1317
+ `Expected ${expected} runtime, but detected ${actual}. This code requires ${expected} runtime to function correctly.`
1318
+ );
1319
+ }
1320
+ }
1321
+
1322
+ // src/edge-helpers.ts
1323
+ function getEdgeEnv(key, defaultValue) {
1324
+ if (typeof process !== "undefined" && process.env) {
1325
+ const value = process.env[key];
1326
+ if (value !== void 0) return value;
1327
+ }
1328
+ if (typeof Deno !== "undefined" && typeof Deno.env !== "undefined") {
1329
+ try {
1330
+ return Deno.env.get(key) || defaultValue;
1331
+ } catch {
1332
+ }
1333
+ }
1334
+ return defaultValue;
1335
+ }
1336
+ function requireEdgeEnv(key) {
1337
+ const value = getEdgeEnv(key);
1338
+ if (!value) {
1339
+ throw new Error(`Required environment variable ${key} is not set`);
1340
+ }
1341
+ return value;
1342
+ }
1343
+ function createEdgeFetch(defaultOptions = {}) {
1344
+ const {
1345
+ retries = 3,
1346
+ retryDelay = 1e3,
1347
+ timeout = 3e4,
1348
+ ...fetchDefaults
1349
+ } = defaultOptions;
1350
+ return async function edgeFetch(input, options) {
1351
+ const finalRetries = options?.retries ?? retries;
1352
+ const finalDelay = options?.retryDelay ?? retryDelay;
1353
+ const finalTimeout = options?.timeout ?? timeout;
1354
+ const finalOptions = { ...fetchDefaults, ...options };
1355
+ let lastError;
1356
+ for (let attempt = 0; attempt <= finalRetries; attempt++) {
1357
+ try {
1358
+ const controller = new AbortController();
1359
+ const timeoutId = setTimeout(() => controller.abort(), finalTimeout);
1360
+ const response = await fetch(input, {
1361
+ ...finalOptions,
1362
+ signal: controller.signal
1363
+ });
1364
+ clearTimeout(timeoutId);
1365
+ if (response.ok || response.status >= 400 && response.status < 500) {
1366
+ return response;
1367
+ }
1368
+ lastError = new Error(`HTTP ${response.status}: ${response.statusText}`);
1369
+ } catch (error) {
1370
+ lastError = error instanceof Error ? error : new Error(String(error));
1371
+ if (lastError.name === "AbortError") {
1372
+ throw new Error(`Request timeout after ${finalTimeout}ms`);
1373
+ }
1374
+ }
1375
+ if (attempt < finalRetries) {
1376
+ const delay = finalDelay * Math.pow(2, attempt);
1377
+ await new Promise((resolve) => setTimeout(resolve, delay));
1378
+ }
1379
+ }
1380
+ throw lastError || new Error("Request failed");
1381
+ };
1382
+ }
1383
+ function getRegionInfo() {
1384
+ if (getEdgeEnv("VERCEL")) {
1385
+ return {
1386
+ provider: "vercel",
1387
+ region: getEdgeEnv("VERCEL_REGION"),
1388
+ isEdge: getEdgeEnv("VERCEL_EDGE_RUNTIME") === "1"
1389
+ };
1390
+ }
1391
+ if (typeof Deno !== "undefined" && getEdgeEnv("NETLIFY")) {
1392
+ return {
1393
+ provider: "netlify",
1394
+ region: getEdgeEnv("NETLIFY_REGION"),
1395
+ isEdge: true
1396
+ };
1397
+ }
1398
+ if (typeof caches !== "undefined" && typeof WebAssembly !== "undefined") {
1399
+ return {
1400
+ provider: "cloudflare",
1401
+ region: void 0,
1402
+ // Cloudflare doesn't expose region
1403
+ isEdge: true
1404
+ };
1405
+ }
1406
+ return {
1407
+ provider: "unknown",
1408
+ isEdge: false
1409
+ };
1410
+ }
1411
+ function getGeoFromRequest(request) {
1412
+ const headers = request.headers;
1413
+ const vercelCountry = headers.get("x-vercel-ip-country");
1414
+ if (vercelCountry) {
1415
+ return {
1416
+ country: vercelCountry,
1417
+ region: headers.get("x-vercel-ip-country-region"),
1418
+ city: headers.get("x-vercel-ip-city"),
1419
+ latitude: headers.get("x-vercel-ip-latitude"),
1420
+ longitude: headers.get("x-vercel-ip-longitude")
1421
+ };
1422
+ }
1423
+ const cfCountry = headers.get("cf-ipcountry");
1424
+ if (cfCountry) {
1425
+ return {
1426
+ country: cfCountry,
1427
+ region: headers.get("cf-region"),
1428
+ city: headers.get("cf-city"),
1429
+ latitude: headers.get("cf-latitude"),
1430
+ longitude: headers.get("cf-longitude")
1431
+ };
1432
+ }
1433
+ return {
1434
+ country: void 0,
1435
+ region: void 0,
1436
+ city: void 0,
1437
+ latitude: void 0,
1438
+ longitude: void 0
1439
+ };
1440
+ }
1441
+ function getClientIp(request) {
1442
+ const headers = request.headers;
1443
+ return headers.get("x-forwarded-for")?.split(",")[0]?.trim() || headers.get("x-real-ip") || headers.get("cf-connecting-ip") || headers.get("x-vercel-forwarded-for") || void 0;
1444
+ }
1445
+
1446
+ // src/index.ts
1447
+ function getClient(config) {
1448
+ const apiClient = new ApiClient(config);
1449
+ const admin = createAdminEndpoints(apiClient);
1450
+ const auth = createAuthEndpoints(apiClient);
1451
+ const billing = createBillingEndpoints(apiClient);
1452
+ const config_endpoints = createConfigEndpoints(apiClient);
1453
+ const me = createMeEndpoints(apiClient);
1454
+ const users = createUsersEndpoints(apiClient);
1455
+ const orgs = createOrgsEndpoints(apiClient);
1456
+ const websites = createWebsitesEndpoints(apiClient);
1457
+ const sessions = createSessionsEndpoints(apiClient);
1458
+ const events = createEventsEndpoints(apiClient);
1459
+ const reports = createReportsEndpoints(apiClient);
1460
+ const segments = createSegmentsEndpoints(apiClient);
1461
+ const links = createLinksEndpoints(apiClient);
1462
+ const pixels = createPixelsEndpoints(apiClient);
1463
+ const boards = createBoardsEndpoints(apiClient);
1464
+ const webhooks = createWebhooksEndpoints(apiClient);
1465
+ const integrations = createIntegrationsEndpoints(apiClient);
1466
+ return {
1467
+ // Auth
1468
+ auth,
1469
+ // Me
1470
+ ...me,
1471
+ // Users
1472
+ ...users,
1473
+ // Organizations
1474
+ ...orgs,
1475
+ // Websites
1476
+ ...websites,
1477
+ // Sessions
1478
+ ...sessions,
1479
+ // Events
1480
+ ...events,
1481
+ // Reports
1482
+ ...reports,
1483
+ // Segments
1484
+ ...segments,
1485
+ // Links
1486
+ ...links,
1487
+ // Pixels
1488
+ ...pixels,
1489
+ // Boards
1490
+ ...boards,
1491
+ // Config
1492
+ getConfig: config_endpoints.get,
1493
+ // Admin
1494
+ admin,
1495
+ // Webhooks
1496
+ webhooks,
1497
+ // Integrations
1498
+ integrations,
1499
+ // Billing
1500
+ billing
1501
+ };
1502
+ }
1503
+ var index_default = getClient;
1504
+ // Annotate the CommonJS export names for ESM import in node:
1505
+ 0 && (module.exports = {
1506
+ API_ENDPOINTS,
1507
+ API_ROUTES,
1508
+ ApiClient,
1509
+ BILLING_ERRORS,
1510
+ CLI_CONFIG,
1511
+ CLI_TOKEN_STATUS,
1512
+ DEFAULT_API_HOST,
1513
+ DEPLOYMENT_ENV_VARS,
1514
+ DEPLOYMENT_SOURCES,
1515
+ ENV_VAR_NAMES,
1516
+ ERROR_MESSAGES,
1517
+ EVENT_TYPES,
1518
+ FORM_EVENT_TYPES,
1519
+ FORM_FIELD_TYPES,
1520
+ FRAMEWORK_PACKAGES,
1521
+ FRAMEWORK_PATTERNS,
1522
+ HTTP_STATUS,
1523
+ NAVIGATION_TYPES,
1524
+ ONBOARDING_STEPS,
1525
+ PLANS,
1526
+ PLAN_FEATURES,
1527
+ RATE_LIMITS,
1528
+ SUCCESS_MESSAGES,
1529
+ USAGE_THRESHOLDS,
1530
+ USER_ROLES,
1531
+ VITAL_RATINGS,
1532
+ VITAL_THRESHOLDS,
1533
+ VITAL_TYPES,
1534
+ assertRuntime,
1535
+ createAdminEndpoints,
1536
+ createAuthEndpoints,
1537
+ createBillingEndpoints,
1538
+ createBoardsEndpoints,
1539
+ createConfigEndpoints,
1540
+ createEdgeFetch,
1541
+ createEventsEndpoints,
1542
+ createIntegrationsEndpoints,
1543
+ createLinksEndpoints,
1544
+ createMeEndpoints,
1545
+ createOrgsEndpoints,
1546
+ createPixelsEndpoints,
1547
+ createReportsEndpoints,
1548
+ createSegmentsEndpoints,
1549
+ createSessionsEndpoints,
1550
+ createUsersEndpoints,
1551
+ createWebhooksEndpoints,
1552
+ createWebsitesEndpoints,
1553
+ detectDeploymentContext,
1554
+ detectRuntime,
1555
+ getApiRoute,
1556
+ getClient,
1557
+ getClientIp,
1558
+ getEdgeEnv,
1559
+ getEnvVarNames,
1560
+ getFrameworkPackage,
1561
+ getGeoFromRequest,
1562
+ getPlan,
1563
+ getPlanLimit,
1564
+ getRegionInfo,
1565
+ getRuntimeCapabilities,
1566
+ getVitalRating,
1567
+ isEdgeRuntime,
1568
+ isNodeRuntime,
1569
+ isPlanFeatureEnabled,
1570
+ isUsageCritical,
1571
+ isUsageWarning,
1572
+ isValidFramework,
1573
+ requireEdgeEnv
1574
+ });
1575
+ //# sourceMappingURL=index.cjs.map