@entrolytics/shared 2.2.1 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,588 +1,685 @@
1
- // src/event-protocol.ts
2
- var EventType = {
3
- PageView: "pageview",
4
- Custom: "custom_event",
5
- Click: "click"
1
+ //#region src/event-protocol.ts
2
+ /**
3
+ * Event Protocol Types
4
+ *
5
+ * These types define the canonical event structures used across the Entrolytics ecosystem.
6
+ * Used by: API Server, SDKs, CLI, worker processes.
7
+ *
8
+ * This file was extracted from the internal @entrolytics/protocol package to enable
9
+ * sharing with external packages.
10
+ */
11
+ /**
12
+ * Core event types supported by the analytics platform
13
+ */
14
+ const EventType = {
15
+ PageView: "pageview",
16
+ Custom: "custom_event",
17
+ Click: "click"
6
18
  };
7
19
 
8
- // src/index.ts
9
- var PLANS = {
10
- starter: {
11
- id: "starter",
12
- name: "Starter",
13
- price: 0,
14
- limits: {
15
- pageviewsPerMonth: 25e3,
16
- websites: 2,
17
- retentionDays: 30,
18
- seats: 1
19
- },
20
- features: {
21
- funnels: false,
22
- attribution: false,
23
- revenue: false,
24
- customDashboards: false,
25
- apiAccess: false,
26
- weeklyReports: true,
27
- support: "community"
28
- }
29
- },
30
- pro: {
31
- id: "pro",
32
- name: "Pro",
33
- price: 29,
34
- limits: {
35
- pageviewsPerMonth: 25e4,
36
- websites: 10,
37
- retentionDays: 365,
38
- seats: 5
39
- },
40
- features: {
41
- funnels: true,
42
- attribution: true,
43
- revenue: true,
44
- customDashboards: false,
45
- apiAccess: true,
46
- weeklyReports: true,
47
- support: "email"
48
- }
49
- },
50
- business: {
51
- id: "business",
52
- name: "Business",
53
- price: 99,
54
- limits: {
55
- pageviewsPerMonth: 1e6,
56
- websites: -1,
57
- // unlimited
58
- retentionDays: 730,
59
- // 2 years
60
- seats: -1
61
- // unlimited
62
- },
63
- features: {
64
- funnels: true,
65
- attribution: true,
66
- revenue: true,
67
- customDashboards: true,
68
- apiAccess: true,
69
- weeklyReports: true,
70
- support: "priority"
71
- }
72
- },
73
- enterprise: {
74
- id: "enterprise",
75
- name: "Enterprise",
76
- price: -1,
77
- // custom
78
- limits: {
79
- pageviewsPerMonth: -1,
80
- // custom
81
- websites: -1,
82
- retentionDays: -1,
83
- // custom
84
- seats: -1
85
- },
86
- features: {
87
- funnels: true,
88
- attribution: true,
89
- revenue: true,
90
- customDashboards: true,
91
- apiAccess: true,
92
- weeklyReports: true,
93
- support: "dedicated",
94
- sso: true,
95
- auditLogs: true,
96
- customRetention: true
97
- }
98
- }
20
+ //#endregion
21
+ //#region src/index.ts
22
+ /**
23
+ * Shared constants across Entrolytics ecosystem
24
+ * Used by: CLI, SDKs, Dashboard, Integrations
25
+ */
26
+ /**
27
+ * Plan definitions and limits
28
+ */
29
+ const PLANS = {
30
+ starter: {
31
+ id: "starter",
32
+ name: "Starter",
33
+ price: 0,
34
+ limits: {
35
+ pageviewsPerMonth: 25e3,
36
+ websites: 2,
37
+ retentionDays: 30,
38
+ seats: 1
39
+ },
40
+ features: {
41
+ funnels: false,
42
+ attribution: false,
43
+ revenue: false,
44
+ customDashboards: false,
45
+ apiAccess: false,
46
+ weeklyReports: true,
47
+ support: "community"
48
+ }
49
+ },
50
+ pro: {
51
+ id: "pro",
52
+ name: "Pro",
53
+ price: 29,
54
+ limits: {
55
+ pageviewsPerMonth: 25e4,
56
+ websites: 10,
57
+ retentionDays: 365,
58
+ seats: 5
59
+ },
60
+ features: {
61
+ funnels: true,
62
+ attribution: true,
63
+ revenue: true,
64
+ customDashboards: false,
65
+ apiAccess: true,
66
+ weeklyReports: true,
67
+ support: "email"
68
+ }
69
+ },
70
+ business: {
71
+ id: "business",
72
+ name: "Business",
73
+ price: 99,
74
+ limits: {
75
+ pageviewsPerMonth: 1e6,
76
+ websites: -1,
77
+ retentionDays: 730,
78
+ seats: -1
79
+ },
80
+ features: {
81
+ funnels: true,
82
+ attribution: true,
83
+ revenue: true,
84
+ customDashboards: true,
85
+ apiAccess: true,
86
+ weeklyReports: true,
87
+ support: "priority"
88
+ }
89
+ },
90
+ enterprise: {
91
+ id: "enterprise",
92
+ name: "Enterprise",
93
+ price: -1,
94
+ limits: {
95
+ pageviewsPerMonth: -1,
96
+ websites: -1,
97
+ retentionDays: -1,
98
+ seats: -1
99
+ },
100
+ features: {
101
+ funnels: true,
102
+ attribution: true,
103
+ revenue: true,
104
+ customDashboards: true,
105
+ apiAccess: true,
106
+ weeklyReports: true,
107
+ support: "dedicated",
108
+ sso: true,
109
+ auditLogs: true,
110
+ customRetention: true
111
+ }
112
+ }
99
113
  };
100
- var PLAN_FEATURES = {
101
- funnels: "Funnel Analytics",
102
- attribution: "Attribution Reports",
103
- revenue: "Revenue Tracking",
104
- customDashboards: "Custom Dashboards",
105
- apiAccess: "API Access",
106
- weeklyReports: "Weekly Email Reports",
107
- sso: "SSO/SAML",
108
- auditLogs: "Audit Logs",
109
- customRetention: "Custom Data Retention"
114
+ /**
115
+ * Plan feature names for display
116
+ */
117
+ const PLAN_FEATURES = {
118
+ funnels: "Funnel Analytics",
119
+ attribution: "Attribution Reports",
120
+ revenue: "Revenue Tracking",
121
+ customDashboards: "Custom Dashboards",
122
+ apiAccess: "API Access",
123
+ weeklyReports: "Weekly Email Reports",
124
+ sso: "SSO/SAML",
125
+ auditLogs: "Audit Logs",
126
+ customRetention: "Custom Data Retention"
110
127
  };
111
- var USAGE_THRESHOLDS = {
112
- warning: 90,
113
- critical: 95
128
+ /**
129
+ * Usage warning thresholds (percentages)
130
+ */
131
+ const USAGE_THRESHOLDS = {
132
+ warning: 90,
133
+ critical: 95
114
134
  };
115
- var BILLING_ERRORS = {
116
- quotaExceeded: "QUOTA_EXCEEDED",
117
- planRequired: "PLAN_REQUIRED",
118
- featureNotAvailable: "FEATURE_NOT_AVAILABLE",
119
- subscriptionInactive: "SUBSCRIPTION_INACTIVE",
120
- paymentFailed: "PAYMENT_FAILED"
135
+ /**
136
+ * Billing-related error codes
137
+ */
138
+ const BILLING_ERRORS = {
139
+ quotaExceeded: "QUOTA_EXCEEDED",
140
+ planRequired: "PLAN_REQUIRED",
141
+ featureNotAvailable: "FEATURE_NOT_AVAILABLE",
142
+ subscriptionInactive: "SUBSCRIPTION_INACTIVE",
143
+ paymentFailed: "PAYMENT_FAILED"
121
144
  };
122
- var API_ENDPOINTS = {
123
- production: "https://entrolytics.click",
124
- development: "http://localhost:3000"
145
+ /**
146
+ * API endpoint configuration
147
+ */
148
+ const API_ENDPOINTS = {
149
+ production: "https://api.entrolytics.com",
150
+ development: "http://localhost:3001"
125
151
  };
126
- var DEFAULT_API_HOST = process.env.NODE_ENV === "production" ? API_ENDPOINTS.production : API_ENDPOINTS.development;
127
- var ENV_VAR_NAMES = {
128
- nextjs: {
129
- websiteId: "NEXT_PUBLIC_ENTROLYTICS_WEBSITE_ID",
130
- host: "NEXT_PUBLIC_ENTROLYTICS_HOST",
131
- envFile: ".env.local"
132
- },
133
- react: {
134
- websiteId: "VITE_ENTROLYTICS_WEBSITE_ID",
135
- host: "VITE_ENTROLYTICS_HOST",
136
- envFile: ".env",
137
- fallback: {
138
- // CRA fallback
139
- websiteId: "REACT_APP_ENTROLYTICS_WEBSITE_ID",
140
- host: "REACT_APP_ENTROLYTICS_HOST"
141
- }
142
- },
143
- vue: {
144
- websiteId: "VITE_ENTROLYTICS_WEBSITE_ID",
145
- host: "VITE_ENTROLYTICS_HOST",
146
- envFile: ".env"
147
- },
148
- svelte: {
149
- websiteId: "PUBLIC_ENTROLYTICS_WEBSITE_ID",
150
- host: "PUBLIC_ENTROLYTICS_HOST",
151
- envFile: ".env"
152
- },
153
- astro: {
154
- websiteId: "PUBLIC_ENTROLYTICS_WEBSITE_ID",
155
- host: "PUBLIC_ENTROLYTICS_HOST",
156
- envFile: ".env"
157
- },
158
- html: {
159
- websiteId: "ENTROLYTICS_WEBSITE_ID",
160
- host: "ENTROLYTICS_HOST",
161
- envFile: ".env"
162
- },
163
- node: {
164
- websiteId: "ENTROLYTICS_WEBSITE_ID",
165
- host: "ENTROLYTICS_HOST",
166
- envFile: ".env"
167
- },
168
- php: {
169
- websiteId: "ENTROLYTICS_WEBSITE_ID",
170
- host: "ENTROLYTICS_HOST",
171
- envFile: ".env"
172
- },
173
- python: {
174
- websiteId: "ENTROLYTICS_WEBSITE_ID",
175
- host: "ENTROLYTICS_HOST",
176
- envFile: ".env"
177
- },
178
- go: {
179
- websiteId: "ENTROLYTICS_WEBSITE_ID",
180
- host: "ENTROLYTICS_HOST",
181
- envFile: ".env"
182
- }
152
+ /**
153
+ * Default API host
154
+ */
155
+ const DEFAULT_API_HOST = process.env.NODE_ENV === "production" ? API_ENDPOINTS.production : API_ENDPOINTS.development;
156
+ /**
157
+ * Environment variable naming conventions by framework
158
+ */
159
+ const ENV_VAR_NAMES = {
160
+ nextjs: {
161
+ websiteId: "NEXT_PUBLIC_ENTROLYTICS_WEBSITE_ID",
162
+ host: "NEXT_PUBLIC_ENTROLYTICS_HOST",
163
+ envFile: ".env.local"
164
+ },
165
+ react: {
166
+ websiteId: "VITE_ENTROLYTICS_WEBSITE_ID",
167
+ host: "VITE_ENTROLYTICS_HOST",
168
+ envFile: ".env",
169
+ fallback: {
170
+ websiteId: "REACT_APP_ENTROLYTICS_WEBSITE_ID",
171
+ host: "REACT_APP_ENTROLYTICS_HOST"
172
+ }
173
+ },
174
+ vue: {
175
+ websiteId: "VITE_ENTROLYTICS_WEBSITE_ID",
176
+ host: "VITE_ENTROLYTICS_HOST",
177
+ envFile: ".env"
178
+ },
179
+ svelte: {
180
+ websiteId: "PUBLIC_ENTROLYTICS_WEBSITE_ID",
181
+ host: "PUBLIC_ENTROLYTICS_HOST",
182
+ envFile: ".env"
183
+ },
184
+ astro: {
185
+ websiteId: "PUBLIC_ENTROLYTICS_WEBSITE_ID",
186
+ host: "PUBLIC_ENTROLYTICS_HOST",
187
+ envFile: ".env"
188
+ },
189
+ html: {
190
+ websiteId: "ENTROLYTICS_WEBSITE_ID",
191
+ host: "ENTROLYTICS_HOST",
192
+ envFile: ".env"
193
+ },
194
+ node: {
195
+ websiteId: "ENTROLYTICS_WEBSITE_ID",
196
+ host: "ENTROLYTICS_HOST",
197
+ envFile: ".env"
198
+ },
199
+ php: {
200
+ websiteId: "ENTROLYTICS_WEBSITE_ID",
201
+ host: "ENTROLYTICS_HOST",
202
+ envFile: ".env"
203
+ },
204
+ python: {
205
+ websiteId: "ENTROLYTICS_WEBSITE_ID",
206
+ host: "ENTROLYTICS_HOST",
207
+ envFile: ".env"
208
+ },
209
+ go: {
210
+ websiteId: "ENTROLYTICS_WEBSITE_ID",
211
+ host: "ENTROLYTICS_HOST",
212
+ envFile: ".env"
213
+ }
183
214
  };
184
- var CLI_CONFIG = {
185
- tokenExpiryMinutes: 15,
186
- maxTokensPerUser: 10,
187
- pollIntervalMs: 2e3,
188
- setupTimeoutMs: 3e5,
189
- // 5 minutes
190
- minCliVersion: "1.0.0"
215
+ /**
216
+ * CLI configuration constants
217
+ */
218
+ const CLI_CONFIG = {
219
+ tokenExpiryMinutes: 15,
220
+ maxTokensPerUser: 10,
221
+ pollIntervalMs: 2e3,
222
+ setupTimeoutMs: 3e5,
223
+ minCliVersion: "1.0.0"
191
224
  };
192
- var EVENT_TYPES = {
193
- pageView: "pageview",
194
- custom: "custom_event",
195
- click: "click"
225
+ /**
226
+ * Core event types - matches backend protocol values exactly
227
+ * Used by: API Server, SDKs, CLI, worker processes
228
+ * See: entrolytics/packages/protocol/src/events.ts
229
+ */
230
+ const EVENT_TYPES = {
231
+ pageView: "pageview",
232
+ custom: "custom_event",
233
+ click: "click"
196
234
  };
197
- var SDK_EVENT_TYPES = {
198
- pageView: "pageview",
199
- click: "click",
200
- formSubmit: "form_submit",
201
- custom: "custom_event",
202
- error: "error",
203
- performance: "performance"
235
+ /**
236
+ * Extended event types for SDK-level semantics
237
+ * These are higher-level event categories used by SDKs
238
+ * They map to the core EVENT_TYPES when sent to the backend
239
+ */
240
+ const SDK_EVENT_TYPES = {
241
+ pageView: "pageview",
242
+ click: "click",
243
+ formSubmit: "form_submit",
244
+ custom: "custom_event",
245
+ error: "error",
246
+ performance: "performance"
204
247
  };
205
- var VITAL_TYPES = {
206
- LCP: "LCP",
207
- // Largest Contentful Paint
208
- INP: "INP",
209
- // Interaction to Next Paint (replaced FID)
210
- CLS: "CLS",
211
- // Cumulative Layout Shift
212
- TTFB: "TTFB",
213
- // Time to First Byte
214
- FCP: "FCP"
215
- // First Contentful Paint
248
+ /**
249
+ * Web Vitals metric types (Phase 2)
250
+ * Core Web Vitals: LCP, INP, CLS
251
+ * Additional: TTFB, FCP
252
+ */
253
+ const VITAL_TYPES = {
254
+ LCP: "LCP",
255
+ INP: "INP",
256
+ CLS: "CLS",
257
+ TTFB: "TTFB",
258
+ FCP: "FCP"
216
259
  };
217
- var VITAL_RATINGS = {
218
- good: "good",
219
- needsImprovement: "needs-improvement",
220
- poor: "poor"
260
+ /**
261
+ * Web Vitals rating thresholds
262
+ */
263
+ const VITAL_RATINGS = {
264
+ good: "good",
265
+ needsImprovement: "needs-improvement",
266
+ poor: "poor"
221
267
  };
222
- var VITAL_THRESHOLDS = {
223
- LCP: { good: 2500, poor: 4e3 },
224
- INP: { good: 200, poor: 500 },
225
- CLS: { good: 0.1, poor: 0.25 },
226
- TTFB: { good: 800, poor: 1800 },
227
- FCP: { good: 1800, poor: 3e3 }
268
+ /**
269
+ * Web Vitals thresholds by metric (in milliseconds, except CLS which is unitless)
270
+ */
271
+ const VITAL_THRESHOLDS = {
272
+ LCP: {
273
+ good: 2500,
274
+ poor: 4e3
275
+ },
276
+ INP: {
277
+ good: 200,
278
+ poor: 500
279
+ },
280
+ CLS: {
281
+ good: .1,
282
+ poor: .25
283
+ },
284
+ TTFB: {
285
+ good: 800,
286
+ poor: 1800
287
+ },
288
+ FCP: {
289
+ good: 1800,
290
+ poor: 3e3
291
+ }
228
292
  };
229
- var NAVIGATION_TYPES = {
230
- navigate: "navigate",
231
- reload: "reload",
232
- backForward: "back-forward",
233
- backForwardCache: "back-forward-cache",
234
- prerender: "prerender",
235
- restore: "restore"
293
+ /**
294
+ * Navigation types for Web Vitals context
295
+ */
296
+ const NAVIGATION_TYPES = {
297
+ navigate: "navigate",
298
+ reload: "reload",
299
+ backForward: "back-forward",
300
+ backForwardCache: "back-forward-cache",
301
+ prerender: "prerender",
302
+ restore: "restore"
236
303
  };
237
- var FORM_EVENT_TYPES = {
238
- start: "start",
239
- // Form interaction started
240
- fieldFocus: "field_focus",
241
- // Field received focus
242
- fieldBlur: "field_blur",
243
- // Field lost focus
244
- fieldError: "field_error",
245
- // Field validation error
246
- submit: "submit",
247
- // Form submitted
248
- abandon: "abandon"
249
- // Form abandoned (left page)
304
+ /**
305
+ * Form event types (Phase 2)
306
+ */
307
+ const FORM_EVENT_TYPES = {
308
+ start: "start",
309
+ fieldFocus: "field_focus",
310
+ fieldBlur: "field_blur",
311
+ fieldError: "field_error",
312
+ submit: "submit",
313
+ abandon: "abandon"
250
314
  };
251
- var FORM_FIELD_TYPES = {
252
- text: "text",
253
- email: "email",
254
- password: "password",
255
- tel: "tel",
256
- number: "number",
257
- url: "url",
258
- textarea: "textarea",
259
- select: "select",
260
- checkbox: "checkbox",
261
- radio: "radio",
262
- date: "date",
263
- file: "file",
264
- hidden: "hidden",
265
- submit: "submit",
266
- other: "other"
315
+ /**
316
+ * Form field types
317
+ */
318
+ const FORM_FIELD_TYPES = {
319
+ text: "text",
320
+ email: "email",
321
+ password: "password",
322
+ tel: "tel",
323
+ number: "number",
324
+ url: "url",
325
+ textarea: "textarea",
326
+ select: "select",
327
+ checkbox: "checkbox",
328
+ radio: "radio",
329
+ date: "date",
330
+ file: "file",
331
+ hidden: "hidden",
332
+ submit: "submit",
333
+ other: "other"
267
334
  };
268
- var DEPLOYMENT_SOURCES = {
269
- vercel: "vercel",
270
- netlify: "netlify",
271
- cloudflare: "cloudflare",
272
- railway: "railway",
273
- render: "render",
274
- fly: "fly",
275
- heroku: "heroku",
276
- aws: "aws",
277
- gcp: "gcp",
278
- azure: "azure",
279
- custom: "custom"
335
+ /**
336
+ * Deployment platform sources (Phase 2)
337
+ */
338
+ const DEPLOYMENT_SOURCES = {
339
+ vercel: "vercel",
340
+ netlify: "netlify",
341
+ cloudflare: "cloudflare",
342
+ railway: "railway",
343
+ render: "render",
344
+ fly: "fly",
345
+ heroku: "heroku",
346
+ aws: "aws",
347
+ gcp: "gcp",
348
+ azure: "azure",
349
+ custom: "custom"
280
350
  };
281
- var DEPLOYMENT_ENV_VARS = {
282
- vercel: {
283
- deployId: "VERCEL_DEPLOYMENT_ID",
284
- gitSha: "VERCEL_GIT_COMMIT_SHA",
285
- gitBranch: "VERCEL_GIT_COMMIT_REF",
286
- url: "VERCEL_URL"
287
- },
288
- netlify: {
289
- deployId: "DEPLOY_ID",
290
- gitSha: "COMMIT_REF",
291
- gitBranch: "BRANCH",
292
- url: "DEPLOY_URL"
293
- },
294
- cloudflare: {
295
- deployId: "CF_PAGES_COMMIT_SHA",
296
- gitSha: "CF_PAGES_COMMIT_SHA",
297
- gitBranch: "CF_PAGES_BRANCH",
298
- url: "CF_PAGES_URL"
299
- }
351
+ /**
352
+ * Deployment environment variables by platform
353
+ */
354
+ const DEPLOYMENT_ENV_VARS = {
355
+ vercel: {
356
+ deployId: "VERCEL_DEPLOYMENT_ID",
357
+ gitSha: "VERCEL_GIT_COMMIT_SHA",
358
+ gitBranch: "VERCEL_GIT_COMMIT_REF",
359
+ url: "VERCEL_URL"
360
+ },
361
+ netlify: {
362
+ deployId: "DEPLOY_ID",
363
+ gitSha: "COMMIT_REF",
364
+ gitBranch: "BRANCH",
365
+ url: "DEPLOY_URL"
366
+ },
367
+ cloudflare: {
368
+ deployId: "CF_PAGES_COMMIT_SHA",
369
+ gitSha: "CF_PAGES_COMMIT_SHA",
370
+ gitBranch: "CF_PAGES_BRANCH",
371
+ url: "CF_PAGES_URL"
372
+ }
300
373
  };
301
- var HTTP_STATUS = {
302
- ok: 200,
303
- created: 201,
304
- accepted: 202,
305
- noContent: 204,
306
- badRequest: 400,
307
- unauthorized: 401,
308
- forbidden: 403,
309
- notFound: 404,
310
- conflict: 409,
311
- tooManyRequests: 429,
312
- internalServerError: 500,
313
- serviceUnavailable: 503
374
+ /**
375
+ * HTTP status codes
376
+ */
377
+ const HTTP_STATUS = {
378
+ ok: 200,
379
+ created: 201,
380
+ accepted: 202,
381
+ noContent: 204,
382
+ badRequest: 400,
383
+ unauthorized: 401,
384
+ forbidden: 403,
385
+ notFound: 404,
386
+ conflict: 409,
387
+ tooManyRequests: 429,
388
+ internalServerError: 500,
389
+ serviceUnavailable: 503
314
390
  };
315
- var API_ROUTES = {
316
- // CLI Auth routes
317
- cliAuthToken: "/api/auth/cli/token",
318
- cliAuthTokens: "/api/auth/cli/tokens",
319
- cliValidate: "/api/auth/cli/validate",
320
- cliToken: "/api/cli/token",
321
- // Legacy - deprecated
322
- // Share routes
323
- shareToken: (shareId) => `/api/share/${shareId}`,
324
- // Links routes
325
- links: "/api/links",
326
- linkRedirect: (slug) => `/q/${slug}`,
327
- // Website routes
328
- websites: "/api/websites",
329
- websiteById: (id) => `/api/websites/${id}`,
330
- websiteEvents: (id) => `/api/websites/${id}/events`,
331
- websiteRecentEvents: (id) => `/api/websites/${id}/recent-events`,
332
- // User routes
333
- userOnboarding: "/api/user/onboarding",
334
- userProfile: "/api/user/profile",
335
- userEmailPreferences: "/api/me/email-preferences",
336
- // Billing routes
337
- billingUsage: "/api/billing/usage",
338
- billingCheckout: "/api/billing/checkout",
339
- billingPortal: "/api/billing/portal",
340
- billingWebhook: "/api/billing/webhook",
341
- // Analytics routes (REST)
342
- analyticsOverview: (websiteId) => `/api/analytics/${websiteId}/overview`,
343
- analyticsTimeseries: (websiteId) => `/api/analytics/${websiteId}/timeseries`,
344
- analyticsTopPages: (websiteId) => `/api/analytics/${websiteId}/top-pages`,
345
- analyticsTopReferrers: (websiteId) => `/api/analytics/${websiteId}/top-referrers`,
346
- analyticsGeography: (websiteId) => `/api/analytics/${websiteId}/geography`,
347
- analyticsDevices: (websiteId) => `/api/analytics/${websiteId}/devices`,
348
- // Event collection
349
- collect: "/api/collect",
350
- collectBatch: "/api/collect/batch",
351
- send: "/api/send",
352
- // Phase 2: Web Vitals, Forms, Deployments
353
- collectVitals: "/api/collect/vitals",
354
- collectVitalsBatch: "/api/collect/vitals/batch",
355
- collectForms: "/api/collect/forms",
356
- websiteVitals: (id) => `/api/websites/${id}/vitals`,
357
- websiteForms: (id) => `/api/websites/${id}/forms`,
358
- websiteDeployments: (id) => `/api/websites/${id}/deployments`,
359
- // Health checks
360
- health: "/api/health",
361
- healthIntegrations: "/api/health/integrations"
391
+ /**
392
+ * API route paths
393
+ */
394
+ const API_ROUTES = {
395
+ cliAuthToken: "/api/auth/cli/token",
396
+ cliAuthTokens: "/api/auth/cli/tokens",
397
+ cliValidate: "/api/auth/cli/validate",
398
+ cliToken: "/api/cli/token",
399
+ shareToken: (shareId) => `/api/share/${shareId}`,
400
+ links: "/api/links",
401
+ linkRedirect: (slug) => `/q/${slug}`,
402
+ websites: "/api/websites",
403
+ websiteById: (id) => `/api/websites/${id}`,
404
+ websiteEvents: (id) => `/api/websites/${id}/events`,
405
+ websiteRecentEvents: (id) => `/api/websites/${id}/recent-events`,
406
+ userOnboarding: "/api/user/onboarding",
407
+ userProfile: "/api/user/profile",
408
+ userEmailPreferences: "/api/me/email-preferences",
409
+ billingUsage: "/api/billing/usage",
410
+ billingCheckout: "/api/billing/checkout",
411
+ billingPortal: "/api/billing/portal",
412
+ billingWebhook: "/api/billing/webhook",
413
+ analyticsOverview: (websiteId) => `/api/analytics/${websiteId}/overview`,
414
+ analyticsTimeseries: (websiteId) => `/api/analytics/${websiteId}/timeseries`,
415
+ analyticsTopPages: (websiteId) => `/api/analytics/${websiteId}/top-pages`,
416
+ analyticsTopReferrers: (websiteId) => `/api/analytics/${websiteId}/top-referrers`,
417
+ analyticsGeography: (websiteId) => `/api/analytics/${websiteId}/geography`,
418
+ analyticsDevices: (websiteId) => `/api/analytics/${websiteId}/devices`,
419
+ collect: "/collect",
420
+ collectBatch: "/collect/batch",
421
+ send: "/collect",
422
+ collectVitals: "/api/collect/vitals",
423
+ collectVitalsBatch: "/api/collect/vitals/batch",
424
+ collectForms: "/api/collect/forms",
425
+ websiteVitals: (id) => `/api/websites/${id}/vitals`,
426
+ websiteForms: (id) => `/api/websites/${id}/forms`,
427
+ websiteDeployments: (id) => `/api/websites/${id}/deployments`,
428
+ health: "/api/health",
429
+ healthIntegrations: "/api/health/integrations"
362
430
  };
363
- var ONBOARDING_STEPS = {
364
- welcome: "welcome",
365
- createWebsite: "create-website",
366
- installTracking: "install-tracking",
367
- verify: "verify",
368
- complete: "complete",
369
- skipped: "skipped"
431
+ /**
432
+ * Onboarding step identifiers
433
+ */
434
+ const ONBOARDING_STEPS = {
435
+ welcome: "welcome",
436
+ createWebsite: "create-website",
437
+ installTracking: "install-tracking",
438
+ verify: "verify",
439
+ complete: "complete",
440
+ skipped: "skipped"
370
441
  };
371
- var CLI_TOKEN_STATUS = {
372
- pending: "pending",
373
- used: "used",
374
- expired: "expired",
375
- revoked: "revoked"
442
+ /**
443
+ * CLI token statuses
444
+ */
445
+ const CLI_TOKEN_STATUS = {
446
+ pending: "pending",
447
+ used: "used",
448
+ expired: "expired",
449
+ revoked: "revoked"
376
450
  };
377
- var USER_ROLES = {
378
- admin: "admin",
379
- user: "user",
380
- viewer: "viewer"
451
+ /**
452
+ * User roles
453
+ */
454
+ const USER_ROLES = {
455
+ admin: "admin",
456
+ user: "user",
457
+ viewer: "viewer"
381
458
  };
382
- var FRAMEWORK_PACKAGES = {
383
- nextjs: "@entrolytics/nextjs-sdk",
384
- react: "@entrolytics/react-sdk",
385
- vue: "@entrolytics/vue-sdk",
386
- svelte: "@entrolytics/svelte-sdk",
387
- astro: "@entrolytics/astro-sdk",
388
- node: "@entrolytics/node-sdk"
459
+ /**
460
+ * Framework package names
461
+ */
462
+ const FRAMEWORK_PACKAGES = {
463
+ nextjs: "@entrolytics/nextjs-sdk",
464
+ react: "@entrolytics/react-sdk",
465
+ vue: "@entrolytics/vue-sdk",
466
+ svelte: "@entrolytics/svelte-sdk",
467
+ astro: "@entrolytics/astro-sdk",
468
+ node: "@entrolytics/node-sdk"
389
469
  };
390
- var FRAMEWORK_PATTERNS = {
391
- nextjs: {
392
- files: ["next.config.js", "next.config.mjs", "next.config.ts"],
393
- dependencies: ["next"]
394
- },
395
- react: {
396
- files: ["vite.config.js", "vite.config.ts"],
397
- dependencies: ["react", "vite"]
398
- },
399
- vue: {
400
- files: ["vite.config.js", "vite.config.ts"],
401
- dependencies: ["vue", "vite"]
402
- },
403
- svelte: {
404
- files: ["svelte.config.js", "svelte.config.ts"],
405
- dependencies: ["svelte"]
406
- },
407
- astro: {
408
- files: ["astro.config.mjs", "astro.config.ts"],
409
- dependencies: ["astro"]
410
- }
470
+ /**
471
+ * Framework detection patterns
472
+ */
473
+ const FRAMEWORK_PATTERNS = {
474
+ nextjs: {
475
+ files: [
476
+ "next.config.js",
477
+ "next.config.mjs",
478
+ "next.config.ts"
479
+ ],
480
+ dependencies: ["next"]
481
+ },
482
+ react: {
483
+ files: ["vite.config.js", "vite.config.ts"],
484
+ dependencies: ["react", "vite"]
485
+ },
486
+ vue: {
487
+ files: ["vite.config.js", "vite.config.ts"],
488
+ dependencies: ["vue", "vite"]
489
+ },
490
+ svelte: {
491
+ files: ["svelte.config.js", "svelte.config.ts"],
492
+ dependencies: ["svelte"]
493
+ },
494
+ astro: {
495
+ files: ["astro.config.mjs", "astro.config.ts"],
496
+ dependencies: ["astro"]
497
+ }
411
498
  };
412
- var RATE_LIMITS = {
413
- cliTokenExchange: {
414
- windowSeconds: 60,
415
- // 1 minute
416
- maxRequests: 5
417
- },
418
- shareTokenGeneration: {
419
- windowSeconds: 60,
420
- // 1 minute
421
- maxRequests: 10
422
- },
423
- linkCreation: {
424
- windowSeconds: 60,
425
- // 1 minute
426
- maxRequests: 20
427
- },
428
- linkRedirect: {
429
- windowSeconds: 60,
430
- // 1 minute
431
- maxRequests: 100
432
- },
433
- apiGeneral: {
434
- windowSeconds: 60,
435
- // 1 minute
436
- maxRequests: 100
437
- },
438
- // Legacy (deprecated but kept for backwards compatibility)
439
- cliTokenGeneration: {
440
- windowMs: 36e5,
441
- // 1 hour
442
- maxRequests: 10
443
- },
444
- cliValidation: {
445
- windowMs: 36e5,
446
- // 1 hour
447
- maxRequests: 100
448
- },
449
- eventCollection: {
450
- windowMs: 6e4,
451
- // 1 minute
452
- maxRequests: 1e3
453
- }
499
+ /**
500
+ * Rate limiting configuration
501
+ * Updated to match server-side implementation
502
+ */
503
+ const RATE_LIMITS = {
504
+ cliTokenExchange: {
505
+ windowSeconds: 60,
506
+ maxRequests: 5
507
+ },
508
+ shareTokenGeneration: {
509
+ windowSeconds: 60,
510
+ maxRequests: 10
511
+ },
512
+ linkCreation: {
513
+ windowSeconds: 60,
514
+ maxRequests: 20
515
+ },
516
+ linkRedirect: {
517
+ windowSeconds: 60,
518
+ maxRequests: 100
519
+ },
520
+ apiGeneral: {
521
+ windowSeconds: 60,
522
+ maxRequests: 100
523
+ },
524
+ cliTokenGeneration: {
525
+ windowMs: 36e5,
526
+ maxRequests: 10
527
+ },
528
+ cliValidation: {
529
+ windowMs: 36e5,
530
+ maxRequests: 100
531
+ },
532
+ eventCollection: {
533
+ windowMs: 6e4,
534
+ maxRequests: 1e3
535
+ }
454
536
  };
455
- var ERROR_MESSAGES = {
456
- // Authentication
457
- unauthorized: "Unauthorized access",
458
- forbidden: "Access forbidden",
459
- tokenExpired: "Token has expired",
460
- tokenInvalid: "Invalid token",
461
- tokenNotFound: "Token not found",
462
- tokenAlreadyUsed: "Token has already been used",
463
- tokenRevoked: "Token has been revoked",
464
- tokenMissingJti: "Token missing JTI - please re-authenticate",
465
- userBanned: "User account has been banned",
466
- userDeleted: "User account has been deleted",
467
- // Share tokens
468
- shareTokenExpired: "Share token has expired",
469
- shareTokenRevoked: "Share has been revoked",
470
- shareTokenInvalid: "Invalid share token",
471
- // URL Validation
472
- invalidUrl: "Invalid URL provided",
473
- invalidUrlProtocol: "URL must use http or https protocol",
474
- openRedirectBlocked: "Open redirect attempt blocked",
475
- // Validation
476
- invalidInput: "Invalid input provided",
477
- missingRequired: "Missing required fields",
478
- invalidFormat: "Invalid format",
479
- // Resources
480
- notFound: "Resource not found",
481
- websiteNotFound: "Website not found",
482
- userNotFound: "User not found",
483
- linkNotFound: "Link not found",
484
- // Rate limiting
485
- tooManyRequests: "Too many requests. Please try again later.",
486
- rateLimitExceeded: "Rate limit exceeded",
487
- // Server
488
- internalError: "Internal server error",
489
- serviceUnavailable: "Service temporarily unavailable"
537
+ /**
538
+ * Error messages
539
+ */
540
+ const ERROR_MESSAGES = {
541
+ unauthorized: "Unauthorized access",
542
+ forbidden: "Access forbidden",
543
+ tokenExpired: "Token has expired",
544
+ tokenInvalid: "Invalid token",
545
+ tokenNotFound: "Token not found",
546
+ tokenAlreadyUsed: "Token has already been used",
547
+ tokenRevoked: "Token has been revoked",
548
+ tokenMissingJti: "Token missing JTI - please re-authenticate",
549
+ userBanned: "User account has been banned",
550
+ userDeleted: "User account has been deleted",
551
+ shareTokenExpired: "Share token has expired",
552
+ shareTokenRevoked: "Share has been revoked",
553
+ shareTokenInvalid: "Invalid share token",
554
+ invalidUrl: "Invalid URL provided",
555
+ invalidUrlProtocol: "URL must use http or https protocol",
556
+ openRedirectBlocked: "Open redirect attempt blocked",
557
+ invalidInput: "Invalid input provided",
558
+ missingRequired: "Missing required fields",
559
+ invalidFormat: "Invalid format",
560
+ notFound: "Resource not found",
561
+ websiteNotFound: "Website not found",
562
+ userNotFound: "User not found",
563
+ linkNotFound: "Link not found",
564
+ tooManyRequests: "Too many requests. Please try again later.",
565
+ rateLimitExceeded: "Rate limit exceeded",
566
+ internalError: "Internal server error",
567
+ serviceUnavailable: "Service temporarily unavailable"
490
568
  };
491
- var SUCCESS_MESSAGES = {
492
- tokenGenerated: "Setup token generated successfully",
493
- tokenValidated: "Token validated successfully",
494
- tokenRevoked: "Token revoked successfully",
495
- allTokensRevoked: "All tokens revoked successfully",
496
- websiteCreated: "Website created successfully",
497
- linkCreated: "Link created successfully",
498
- shareCreated: "Share created successfully",
499
- onboardingComplete: "Onboarding completed successfully",
500
- setupComplete: "Setup completed successfully"
569
+ /**
570
+ * Success messages
571
+ */
572
+ const SUCCESS_MESSAGES = {
573
+ tokenGenerated: "Setup token generated successfully",
574
+ tokenValidated: "Token validated successfully",
575
+ tokenRevoked: "Token revoked successfully",
576
+ allTokensRevoked: "All tokens revoked successfully",
577
+ websiteCreated: "Website created successfully",
578
+ linkCreated: "Link created successfully",
579
+ shareCreated: "Share created successfully",
580
+ onboardingComplete: "Onboarding completed successfully",
581
+ setupComplete: "Setup completed successfully"
501
582
  };
583
+ /**
584
+ * Utility functions
585
+ */
502
586
  function getEnvVarNames(framework) {
503
- return ENV_VAR_NAMES[framework];
587
+ return ENV_VAR_NAMES[framework];
504
588
  }
505
589
  function getFrameworkPackage(framework) {
506
- return FRAMEWORK_PACKAGES[framework] || null;
590
+ return FRAMEWORK_PACKAGES[framework] || null;
507
591
  }
508
592
  function isValidFramework(framework) {
509
- return framework in ENV_VAR_NAMES;
593
+ return framework in ENV_VAR_NAMES;
510
594
  }
511
595
  function getApiRoute(route, ...args) {
512
- const routeFn = API_ROUTES[route];
513
- if (typeof routeFn === "function") {
514
- return routeFn(...args);
515
- }
516
- return routeFn;
596
+ const routeFn = API_ROUTES[route];
597
+ if (typeof routeFn === "function") return routeFn(...args);
598
+ return routeFn;
517
599
  }
600
+ /**
601
+ * Get plan by ID
602
+ */
518
603
  function getPlan(planId) {
519
- return PLANS[planId];
604
+ return PLANS[planId];
520
605
  }
606
+ /**
607
+ * Check if a feature is available for a plan
608
+ */
521
609
  function isPlanFeatureEnabled(planId, feature) {
522
- const plan = PLANS[planId];
523
- return plan?.features?.[feature] === true;
610
+ return PLANS[planId]?.features?.[feature] === true;
524
611
  }
612
+ /**
613
+ * Get plan limit value (-1 means unlimited)
614
+ */
525
615
  function getPlanLimit(planId, limit) {
526
- return PLANS[planId]?.limits?.[limit] ?? 0;
616
+ return PLANS[planId]?.limits?.[limit] ?? 0;
527
617
  }
618
+ /**
619
+ * Check if usage is at warning threshold
620
+ */
528
621
  function isUsageWarning(current, limit) {
529
- if (limit <= 0) return false;
530
- return current / limit * 100 >= USAGE_THRESHOLDS.warning;
622
+ if (limit <= 0) return false;
623
+ return current / limit * 100 >= USAGE_THRESHOLDS.warning;
531
624
  }
625
+ /**
626
+ * Check if usage is at critical threshold
627
+ */
532
628
  function isUsageCritical(current, limit) {
533
- if (limit <= 0) return false;
534
- return current / limit * 100 >= USAGE_THRESHOLDS.critical;
629
+ if (limit <= 0) return false;
630
+ return current / limit * 100 >= USAGE_THRESHOLDS.critical;
535
631
  }
632
+ /**
633
+ * Calculate Web Vital rating from value (Phase 2)
634
+ */
536
635
  function getVitalRating(metric, value) {
537
- const thresholds = VITAL_THRESHOLDS[metric];
538
- if (value <= thresholds.good) return "good";
539
- if (value <= thresholds.poor) return "needs-improvement";
540
- return "poor";
636
+ const thresholds = VITAL_THRESHOLDS[metric];
637
+ if (value <= thresholds.good) return "good";
638
+ if (value <= thresholds.poor) return "needs-improvement";
639
+ return "poor";
541
640
  }
641
+ /**
642
+ * Detect deployment context from environment variables (Phase 2)
643
+ * Works in Node.js environments only - returns null in browser
644
+ */
542
645
  function detectDeploymentContext() {
543
- const env = getEnv();
544
- if (!env) return null;
545
- if (env.VERCEL_DEPLOYMENT_ID) {
546
- return {
547
- deployId: env.VERCEL_DEPLOYMENT_ID,
548
- gitSha: env.VERCEL_GIT_COMMIT_SHA,
549
- gitBranch: env.VERCEL_GIT_COMMIT_REF,
550
- deployUrl: env.VERCEL_URL ? `https://${env.VERCEL_URL}` : void 0,
551
- source: "vercel"
552
- };
553
- }
554
- if (env.DEPLOY_ID) {
555
- return {
556
- deployId: env.DEPLOY_ID,
557
- gitSha: env.COMMIT_REF,
558
- gitBranch: env.BRANCH,
559
- deployUrl: env.DEPLOY_URL,
560
- source: "netlify"
561
- };
562
- }
563
- if (env.CF_PAGES_COMMIT_SHA) {
564
- return {
565
- deployId: env.CF_PAGES_COMMIT_SHA,
566
- gitSha: env.CF_PAGES_COMMIT_SHA,
567
- gitBranch: env.CF_PAGES_BRANCH,
568
- deployUrl: env.CF_PAGES_URL,
569
- source: "cloudflare"
570
- };
571
- }
572
- return null;
646
+ const env = getEnv();
647
+ if (!env) return null;
648
+ if (env.VERCEL_DEPLOYMENT_ID) return {
649
+ deployId: env.VERCEL_DEPLOYMENT_ID,
650
+ gitSha: env.VERCEL_GIT_COMMIT_SHA,
651
+ gitBranch: env.VERCEL_GIT_COMMIT_REF,
652
+ deployUrl: env.VERCEL_URL ? `https://${env.VERCEL_URL}` : void 0,
653
+ source: "vercel"
654
+ };
655
+ if (env.DEPLOY_ID) return {
656
+ deployId: env.DEPLOY_ID,
657
+ gitSha: env.COMMIT_REF,
658
+ gitBranch: env.BRANCH,
659
+ deployUrl: env.DEPLOY_URL,
660
+ source: "netlify"
661
+ };
662
+ if (env.CF_PAGES_COMMIT_SHA) return {
663
+ deployId: env.CF_PAGES_COMMIT_SHA,
664
+ gitSha: env.CF_PAGES_COMMIT_SHA,
665
+ gitBranch: env.CF_PAGES_BRANCH,
666
+ deployUrl: env.CF_PAGES_URL,
667
+ source: "cloudflare"
668
+ };
669
+ return null;
573
670
  }
671
+ /**
672
+ * Safe environment variable access (works in browser and Node.js)
673
+ */
574
674
  function getEnv() {
575
- try {
576
- if (typeof globalThis !== "undefined" && "process" in globalThis) {
577
- const proc = globalThis.process;
578
- return proc?.env ?? null;
579
- }
580
- return null;
581
- } catch {
582
- return null;
583
- }
675
+ try {
676
+ if (typeof globalThis !== "undefined" && "process" in globalThis) return globalThis.process?.env ?? null;
677
+ return null;
678
+ } catch {
679
+ return null;
680
+ }
584
681
  }
585
682
 
683
+ //#endregion
586
684
  export { API_ENDPOINTS, API_ROUTES, BILLING_ERRORS, CLI_CONFIG, CLI_TOKEN_STATUS, DEFAULT_API_HOST, DEPLOYMENT_ENV_VARS, DEPLOYMENT_SOURCES, ENV_VAR_NAMES, ERROR_MESSAGES, EVENT_TYPES, EventType, FORM_EVENT_TYPES, FORM_FIELD_TYPES, FRAMEWORK_PACKAGES, FRAMEWORK_PATTERNS, HTTP_STATUS, NAVIGATION_TYPES, ONBOARDING_STEPS, PLANS, PLAN_FEATURES, RATE_LIMITS, SDK_EVENT_TYPES, SUCCESS_MESSAGES, USAGE_THRESHOLDS, USER_ROLES, VITAL_RATINGS, VITAL_THRESHOLDS, VITAL_TYPES, detectDeploymentContext, getApiRoute, getEnvVarNames, getFrameworkPackage, getPlan, getPlanLimit, getVitalRating, isPlanFeatureEnabled, isUsageCritical, isUsageWarning, isValidFramework };
587
- //# sourceMappingURL=index.js.map
588
685
  //# sourceMappingURL=index.js.map