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