@entrolytics/shared 2.4.0 → 2.4.2

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